Login Page - Create Account

DTC Protocol Discussion Forum


Date/Time: Fri, 29 Nov 2024 14:48:40 +0000



Post From: Python interface for DTC protocol library

[2017-04-08 13:16:42]
Queeq - Posts: 42
Hi,

I would like to use DTC protocol from Python, but haven't found any available solutions. Thus, I decided to try SWIG to generate it. As my knowledge about C/C++ is very basic, I encountered some problems during the process. I ended up with the following (doing it on Linux Mint,
GCC 5.4.0, SWIG 3.0.8):

1. Put DTCProtocol.h and DTCProtocol.cpp in a target folder.

2. Create DTCProtocol.i with the following contents:

%module DTCProtocol

%{
#define SWIG_FILE_WITH_INIT
#include "DTCProtocol.h"
%}

%include "DTCProtocol.h"


3. Run the following (according to SWIG manual):
swig -c++ -python DTCProtocol.i
gcc -O2 -fPIC -std=c++11 -c DTCProtocol.cpp
gcc -O2 -fPIC -std=c++11 -c DTCProtocol_wrap.cxx -I/usr/include/python3.5m
gcc -shared DTCProtocol.o DTCProtocol_wrap.o -o _DTCProtocol.so

During the swig run there were many warnings like these:

DTCProtocol.h:15: Warning 315: Nothing known about 'std::int32_t'.
DTCProtocol.h:16: Warning 315: Nothing known about 'std::int64_t'.
DTCProtocol.h:17: Warning 315: Nothing known about 'std::uint16_t'.
DTCProtocol.h:18: Warning 315: Nothing known about 'std::uint32_t'.

Somewhere on Stackoverflow it was mentioned that it is not critical.

Further on the way, I had to add
#include <cfloat>
to DTCProtocol.h, otherwise there were errors like the following:


In file included from DTCProtocol_wrap.cxx:3204:0:
DTCProtocol.h: In member function ‘void DTC::s_MarketDataSnapshot::Clear()’:
DTCProtocol.h:834:29: error: ‘DBL_MAX’ was not declared in this scope
    SessionSettlementPrice = DBL_MAX;
                             ^
DTCProtocol.h: In member function ‘void DTC::s_MarketDataUpdateBidAsk::Clear()’:
DTCProtocol.h:1495:15: error: ‘DBL_MAX’ was not declared in this scope
    BidPrice = DBL_MAX; //This also signifies the BidQuantity is unset
               ^
DTCProtocol.h: In member function ‘void DTC::s_MarketDataUpdateBidAskCompact::Clear()’:
DTCProtocol.h:1574:15: error: ‘FLT_MAX’ was not declared in this scope
    BidPrice = FLT_MAX;
               ^
DTCProtocol.h: In member function ‘void DTC::s_OrderUpdate::Clear()’:
DTCProtocol.h:2493:13: error: ‘DBL_MAX’ was not declared in this scope
    Price1 = DBL_MAX;
             ^

When trying to import the resulting object, it gives the following errors:


➜ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import DTCProtocol
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/queeq/Work/wat/wat/DTC/DTCProtocol.py", line 28, in <module>
_DTCProtocol = swig_import_helper()
File "/home/queeq/Work/wat/wat/DTC/DTCProtocol.py", line 24, in swig_import_helper
_mod = imp.load_module('_DTCProtocol', fp, pathname, description)
File "/usr/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: /home/queeq/Work/wat/wat/DTC/_DTCProtocol.so: undefined symbol: _ZN3DTC25s_MarketDepthFullUpdate2016NUM_DEPTH_LEVELSE

I tried readelf on the .so file, and it seems that the above function (or whatever it is) is there:

➜ readelf -sW _DTCProtocol.so | grep _ZN3DTC25s_MarketDepthFullUpdate2016NUM_DEPTH_LEVELSE
29: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _ZN3DTC25s_MarketDepthFullUpdate2016NUM_DEPTH_LEVELSE
3407: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _ZN3DTC25s_MarketDepthFullUpdate2016NUM_DEPTH_LEVELSE

I don't really know how should it look like. Could someone help me with this? Would be really great to have DTC protocol available for use in Python, and with SWIG it seems to be pretty straightforward.

Thanks!

P.S. SWIG manual used is here: http://www.swig.org/Doc3.0/Python.html#Python
Date Time Of Last Edit: 2017-04-08 19:24:57