Login Page - Create Account

Support Board


Date/Time: Tue, 24 Apr 2018 16:29:27 +0000



Post From: DTC Protocol

[2016-03-31 21:32:01]
User783015 - Posts: 7
Ok, I understand. I would be very grateful if you could implement the JSON support sometime in the future though. Working with the binary format in a language like Python is incredibly frustrating. It takes long time to construct the necessary struct format strings and I still seem to get different results than expected.

Now I'm struggling with the logon response message from the SC historical data service.

The structure definition looks like this (I put the particular field sizes on the left):
  struct s_LogonResponse
  {
2    uint16_t Size;
2    uint16_t Type;
4    int32_t ProtocolVersion;
4    LogonStatusEnum Result;
96    char ResultText[TEXT_DESCRIPTION_LENGTH];
64    char ReconnectAddress[64];
4    int32_t Integer_1;
60    char ServerName[60];
1    uint8_t MarketDepthUpdatesBestBidAndAsk;
1    uint8_t TradingIsSupported;
1    uint8_t OCOOrdersSupported;
1    uint8_t OrderCancelReplaceSupported;
4    char SymbolExchangeDelimiter[SYMBOL_EXCHANGE_DELIMITER_LENGTH];
1    uint8_t SecurityDefinitionsSupported;
1    uint8_t HistoricalPriceDataSupported;
1    uint8_t ResubscribeWhenMarketDataFeedAvailable;
1    uint8_t MarketDepthIsSupported;
1    uint8_t OneHistoricalPriceDataRequestPerConnection;
1    uint8_t BracketOrdersSupported;
1    uint8_t UseIntegerPriceOrderMessages;
1    uint8_t UsesMultiplePositionsPerSymbolAndTradeAccount;
1    uint8_t MarketDataSupported;

When I add all the sizes together, I get a message size of 253. But SC HD service is sending me a message with the size of 256 so when I try to parse it

response = struct.unpack( "<2H2i96s64si60s4B4s9B" , message )

it fails because the message doesn't have the expected size.

$ python -u DTCCliPy.py
DBG: DTCCliPy: Connected to localhost:11098
DBG: DTCCliPy: Sending encoding request (requested encoding: Binary)
10 00 07 00 07 00 00 00 00 00 00 00 44 54 43 00
DBG: DTCCliPy: Binary encoding response received:
'(16, 7, 7, 0, 'D', 'T', 'C', '\x00')'
DBG: DTCCliPy: Sending binary logon request
00 01 02 00 07 00 00 00 01 00 00 00 4c 6f 67 6f 6e 20 73 75 63 63 65 73 73 66 75 6c 2e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 53 43 20 48 69 73 74 6f 72 69 63 61 6c 44 61 74 61 53 65 72 76 65 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 01 00 01 01 00 00 00 00 00 00 00
Traceback (most recent call last):
File "DTCCliPy.py", line 392, in <module>
if not dtc_client.connect( ):
File "DTCCliPy.py", line 153, in connect
if self.logon_request( ) and self.logon_response( ):
File "DTCCliPy.py", line 293, in logon_response
response = struct.unpack( "<2H2i96s64si60s4B4s9B" , message )
struct.error: unpack requires a string argument of length 253

What are those 3 extra bytes I'm getting? I feel like I'm getting crazy from this. Haven't done so many dec <-> hex conversions since my fun time with assembler :)

Of course I can just parse those extra 3 bytes and ignore them. But I would like to understand why my expectations don't match with what I'm getting.

The help page http://dtcprotocol.org/index.php?page=doc/doc_DTCMessages_AuthenticationConnectionMonitoringMessages.php#Messages-LOGON_RESPONSE lists the parameters in a different order than the s_LogonResponse structure definition in the DTC header file. I'm using the structure definition since that one seems to match (except for those 3 bytes) the data I'm getting.

Btw. please let me know if this is not the right place to put all these questions. I will surely have more during my DTC client development project and I don't want to spam this thread if you planned to use it for a different purpose. If there's another place I should be posting these questions, let me know.

Thanks,
Petr
Date Time Of Last Edit: 2016-03-31 22:48:14