Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 19:45:43 +0000



Post From: SerraChart as a DTC Protocol Client

[2023-09-08 13:40:42]
d9e5c763 - Posts: 108
I continue to troubleshoot. First, I decided to switch to binary encoding. Since Python has the struct module, this looks very straightforward. For example, I can send the SECURITY_DEFINITION_RESPONSE based on the documentation and the definitions in DTCProtocol.h. Here's the specific code:

async def send_security_definitions(writer):
with open(QUOTE_BOARD_FILE_LOCATION, 'w') as file:
for product in PRICES_DICT:
file.write(f"{product}_OKX\n")

total_products = len(PRICES_DICT)

for index, product in enumerate(PRICES_DICT):
instrument_data = INSTRUMENTS_DICT.get(product, {})
multiplier = PRODUCT_MULTIPLIERS.get(product, 1)
tick_size = str((Decimal(instrument_data.get('tick_size', 0)) * multiplier).normalize())
tick_value = str((Decimal(instrument_data.get('tick_size', 0)) * (Decimal(instrument_data.get('ct_value', 0)))).normalize())
decimal_places = len(tick_size.split('.')[1]) if '.' in tick_size else 0
price_display_format = decimal_places if decimal_places <= 9 else -1

product_prefix = product.split('-')[0]
description = await get_product_descriptions(product_prefix)

format_string = '2Hi64s16si64sfifB2f32sBfBIi3fIfBf64si2f8sfIB'
security_definition_data = struct.pack(
format_string,
struct.calcsize(format_string), # Size (uint16)
dtc["SECURITY_DEFINITION_RESPONSE"], # Type (uint16)
0, # RequestID (int32)
product.encode('ascii'), # Symbol (char, 64 bytes)
b"OKX", # Exchange (char, 16 bytes)
0, # SecurityType (int32)
description.encode('ascii'), # Description (char, 64 bytes)
float(tick_size), # MinPriceIncrement (float)
price_display_format, # PriceDisplayFormat (int32)
float(tick_value), # CurrencyValuePerIncrement (float)
1 if index == total_products - 1 else 0, # IsFinalMessage (uint8)
1.0, # FloatToIntPriceMultiplier (float)
1.0, # IntegerToFloatPriceDivisor (float)
b"", # UnderlyingSymbol (char, 32 bytes)
0, # UpdatesBidAskOnly (uint8)
0.0, # StrikePrice (float)
0, # PutOrCall (uint8)
0, # ShortInterest (uint32)
0, # SecurityExpirationDate (int32)
0.0, # BuyRolloverInterest (float)
0.0, # SellRolloverInterest (float)
0.0, # EarningsPerShare (float)
0, # SharesOutstanding (uint32)
0.0, # IntToFloatQuantityDivisor (float)
0, # HasMarketDepthData (uint8)
1.0, # DisplayPriceMultiplier (float)
b"", # ExchangeSymbol (char, 64 bytes)
0, # RolloverDate (int32)
0.0, # InitialMarginRequirement (float)
0.0, # MaintenanceMarginRequirement (float)
b"USDT", # Currency (char, 8 bytes)
0.0, # ContractSize (float)
0, # OpenInterest (uint32)
0 # IsDelayed (uint8)
)

writer.write(security_definition_data)
await writer.drain()

However, I also noticed that MARKET_DATA_UPDATE_BID_ASK and MARKET_DATA_UPDATE_TRADE have issues similar to those mentioned above with JSON encoding:
For MARKET_DATA_UPDATE_BID_ASK, I can see on the Quote Board that the ask price and ask size are displayed as very large numbers, while the bid price and bid size are not. I have double-checked the documentation and DTCProtocol.h file, and everything seems to be in accordance with the specifications. However, MARKET_DATA_UPDATE_BID_ASK_COMPACT doesn't have these issues.
Similarly, for MARKET_DATA_UPDATE_TRADE, in the Time and Sales Window, I see that the Volume is always 1 and the Price is always 0, but the Time is displayed correctly in milliseconds. MARKET_DATA_UPDATE_TRADE_COMPACT doesn't have these issues, and it appears that MARKET_DATA_UPDATE_TRADE_COMPACT is consistent with MARKET_DATA_UPDATE_TRADE in JSON encoding. (MARKET_DATA_UPDATE_TRADE_COMPACT is not listed in the documentation but is clearly defined in the DTCProtocol.h file).
I haven't tested historical data yet as it's currently not operational. I might have gotten the order of the data wrong; I'm not sure yet.