python-okcoin-fix icon indicating copy to clipboard operation
python-okcoin-fix copied to clipboard

python-okcoin-fix

Python example for OKCoin FIX api

This is a simple python example for OKCoin FIX API.

Since quickfix api for python does not support SSL as in java case, we should use manual tunneling using stunnel.

Because of that, the configuration file for quickfix api for using OKCoin should be slightly different from C# and Java case.

Note: I'm using python 2.7

Prerequisites

  1. quickfix
  2. ssl tunneling (openssl and stunnel)

Install prerequisites

  1. Install quickfix python api
pip install quickfix
  1. Install openssl and stunnel

See https://github.com/lim0606/python-okcoin-fix/tree/master/docs/stunnel

Install this example

  1. Download this repository
git clone https://github.com/lim0606/python-okcoin-fix.git
  1. Set OKCoin API keys
  2. Copy the example configuration file
cp my_api.py.example my_api.py
  1. Change the below lines with your api keys
api_key='your api key here'
secret_key='your secret key here'
  1. Set quickfix configuration file
  2. Copy the example configuration file
cp okcoin.cfg.example okcoin.cfg
  1. Open the configuration file
vim okcoin.cfg
  1. Change the line with the same used in tunneling (i.e. your ip address in this example)
SocketConnectHost=Your ip address here

Note: So this application communicates with OKCoin server via tunneling installed as prerequisites. That is why this setting is different from C# or Java example in OKCoin repo.

Note: We used <your ip address> in stunnel's configuration file

  1. Change the line with user defined client name (e.g. generated using UUID)
SenderCompID=SenderCompID user defined client name(e.g. generated using UUID)
  1. Run
python okcoin.py

Note: spec/FIX44.xml is copied from https://github.com/OKCoin/fix/blob/master/c%23/FixDemo/config/FIX44.xml

References

  1. https://github.com/tianyilai/QuickFix-python-client
  2. https://futures.io/matlab-r-project-python/35213-python-quickfix.html
  3. https://github.com/OKCoin/fix/blob/9e45e651cfada4a4c59cd51a40666cd33f22070b/java/src/com/okcoin/fix/OKClientApplication.java
  4. https://github.com/OKCoin/fix/blob/85679c5f6793963c2bdaf03b72d6cb00d3b04cf7/c%23/FixDemo/bin/Debug/config/quickfix-client.cfg