3

I've been trying to set up a connection to the FIX API for the GDAX crpyto exchange, but I can't seem to logon properly. I'm using the code below to generate the message:

import time
import simplefix
import socket
import base64
import hmac
import hashlib
from datetime import datetime

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("127.0.0.1", 4197))

API_KEY = "KEY_GOES_HERE"
PASSPHRASE = "PASSPHRASE_GOES_HERE"
API_SECRET = "SECRET_GOES_HERE"

seq_num = "1"
sendingTime = str(datetime.utcnow()).replace("-","").replace(" ", "-")[:-3]
rawSig = "\x01".join([sendingTime, "A", seq_num, API_KEY, "Coinbase", PASSPHRASE]).encode("utf-8")

hmac_key  = base64.b64decode(API_SECRET)
signature = hmac.new(hmac_key, rawSig, hashlib.sha256)
sign_b64  = base64.b64encode(signature.digest()).decode()

msg = simplefix.FixMessage()

msg.append_pair(8, "FIX.4.2")
msg.append_pair(35, "A")
msg.append_pair(49, API_KEY)
msg.append_pair(52, sendingTime)
msg.append_pair(56, "Coinbase")
msg.append_pair(98, "0")
msg.append_pair(108, "30")
msg.append_pair(554, PASSPHRASE)
msg.append_pair(96, sign_b64)
msg.append_pair(8013, "Y")

print(msg.encode())
s.sendall(msg.encode("ascii"))
print(s.recv(4096))

And I'm getting 0 bytes of response from the server. As far as I can tell, the stunnel is working properly (connects and validates certificates successfully, but disconnects after sending my logon message).

Have just tried with a newly generated API key, passphrase and secret but to no avail.

For reference, I was working from the question asked here: How to send FIX logon message with Python to GDAX but I'm not allowed to comment there.

If anyone has any ideas, would be appreciated. Below is an example of the fix message generated, passwords removed in post:

8=FIX.4.2\x019=161\x0135=A\x0149=[KEY_REMOVED]\x0152=20180113-18:24:07.889\x0156=Coinbase\x0198=0\x01108=30\x01554=[PASSPHRASE_REMOVED]\x0196=jueSJHoSNQM2BOCN3KM0mgB2/9tXpICbg4amqDKc2wY=\x018013=Y\x0110=053\x01
TheOdeexs
  • 39
  • 3
  • I'm having the same issue. From what I can gather, to connect to the FIX API, you have to connect not to the local host but to GDAX with `s.connect(("fix.gdax.com", 4198))`. Please let me know if that does anything for you. – Arda Arslan Feb 08 '18 at 05:59
  • Did you manage to find a solution? – SiberianGuy Feb 27 '18 at 16:29
  • @ArdaArslan yeah that kind of looks like the obvious issue. He’s trying to connect to himself. I thought maybe he was running a local engine like quickfix at first. But this is the very first night that I am learning about the FIX API protocol, so I’m going to try this out myself with simplefix in the next few days. I will probably definitely be reporting back to this thread since it’s one of the only ones I can find for support so far. – greenhouse Sep 15 '18 at 08:11

0 Answers0