3

我完全掌握了 PHP 套接字和 FIX 协议的基本知识。我有一个帐户,允许我连接到服务器并检索货币价格。

我修改了这段代码来连接并找出我从远程服务器收到的内容:

$host = "the-server.com";
    $port = "2xxxx";

    $fixv = "8=FIX.4.2";
    $clid = "client-name";
    $tid = "target-name";

    $fp = fsockopen($host, $port, $errno, $errstr, 30);
    if (!$fp) {
        echo "$errstr ($errno)<br />\n";
    } else {
        $out = "$fixv|9=70|35=A|49=$clid|56=$tid|34=1|52=20000426-12:05:06|98=0|108=30|10=185|";
        echo "\n".$out."\n";
        fwrite($fp, $out);
        while (!feof($fp)) {
            echo ".";
            echo fgets($fp, 1024);
        }
        fclose($fp);
    }

我一无所获。主机很好,因为当我使用随机主机时出现错误。我发送的消息是否没有产生回复?

我可能不太擅长在 Google 中查找内容,但我找不到任何关于如何使用 php 执行此操作的简单教程(至少没有任何东西可以将 fix 和 php 放在一起)。

任何帮助是极大的赞赏。

4

1 回答 1

4

FIX separator character is actually '\001' not '|', so you have to replace that when sending.

Some links for you:

Edit 0:

From that same wikipedia article you mention:

The message fields are delimited using the ASCII 01 character.
...
Example of a FIX message : Execution Report (Pipe character is used to represent SOH character) ...

Edit 1:

Couple more points:

  • Tag 9 holds message length without tags 8 (type), 9 (length), and 10 (checksum).
  • Tag 10, checksum, has to be a modulo 256 sum of ASCII values of all message characters including all SOH separators, but not including the tag 10 itself (I know, it's stupid to have checksums on top of TCP, but ...)
于 2011-08-09T21:04:28.833 回答