Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting started on FIX protocol with PHP sockets

I have pretty basic knowledge of PHP sockets and the FIX protocol altogether. I have an account that allows me to connect to a server and retrieve currency prices.

I adapted this code to connect and figure out what I receive back from the remote server:

$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);
    }

and I get nothing back. The host is good because I'm getting an error when I use a random one. Is the message I'm sending not generating a reply ?

I might not be very good at finding things in Google but I could not find any simple tutorial on how to do this with php (at least nothing that puts together fix and php).

Any help is greatly appreciated.

like image 511
NickOpris Avatar asked Apr 17 '26 08:04

NickOpris


1 Answers

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

Some links for you:

  • FIX protocol - formal specs
  • Onixs FIX dictionary - very useful site for tag lookup

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 ...)
like image 164
Nikolai Fetissov Avatar answered Apr 18 '26 23:04

Nikolai Fetissov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!