Login Page - Create Account

Support Board


Date/Time: Sun, 24 Nov 2024 21:46:16 +0000



Post From: [SC Relay Server] Documentation Needed

[2024-05-02 16:43:43]
d9e5c763 - Posts: 108
You can refer to my dtc.py module as a reference.

#!/usr/bin/env python3

import numpy
import sys
import struct

from enum import IntEnum

UINT_MAX = (1 << 32) - 1
FLT_MAX = numpy.finfo(numpy.float32).max
DBL_MAX = numpy.finfo(numpy.float64).max

CURRENT_VERSION = 8

class DTCMessageType(IntEnum):
LOGON_REQUEST = 1
LOGON_RESPONSE = 2
HEARTBEAT = 3
ENCODING_REQUEST = 6
ENCODING_RESPONSE = 7

MARKET_DATA_REQUEST = 101
MARKET_DATA_SNAPSHOT = 104
MARKET_DATA_UPDATE_SESSION_HIGH = 114
MARKET_DATA_UPDATE_SESSION_LOW = 115
MARKET_DATA_UPDATE_OPEN_INTEREST = 124
MARKET_DATA_UPDATE_BID_ASK_FLOAT_WITH_MICROSECONDS = 144
MARKET_DATA_UPDATE_TRADE_WITH_UNBUNDLED_INDICATOR_2 = 146

MARKET_DEPTH_REQUEST = 102
MARKET_DEPTH_SNAPSHOT_LEVEL = 122
MARKET_DEPTH_UPDATE_LEVEL = 106

MARKET_DATA_FEED_SYMBOL_STATUS = 116

CANCEL_ORDER = 203
SUBMIT_NEW_SINGLE_ORDER = 208

OPEN_ORDERS_REQUEST = 300
ORDER_UPDATE = 301
OPEN_ORDERS_REJECT = 302
HISTORICAL_ORDER_FILLS_REQUEST = 303
HISTORICAL_ORDER_FILL_RESPONSE = 304
CURRENT_POSITIONS_REQUEST = 305
POSITION_UPDATE = 306

TRADE_ACCOUNT_RESPONSE = 401
TRADE_ACCOUNTS_REQUEST = 400

SECURITY_DEFINITION_RESPONSE = 507

ACCOUNT_BALANCE_UPDATE = 600
ACCOUNT_BALANCE_REQUEST = 601
HISTORICAL_ACCOUNT_BALANCES_REQUEST = 603
HISTORICAL_ACCOUNT_BALANCE_RESPONSE = 606

HISTORICAL_PRICE_DATA_REQUEST= 800
HISTORICAL_PRICE_DATA_RESPONSE_HEADER = 801
HISTORICAL_PRICE_DATA_RECORD_RESPONSE = 803

class EncodingEnum(IntEnum):
BINARY_ENCODING = 0
BINARY_WITH_VARIABLE_LENGTH_STRINGS = 1
JSON_ENCODING = 2
JSON_COMPACT_ENCODING = 3
PROTOCOL_BUFFERS = 4

class LogonStatusEnum(IntEnum):
LOGON_STATUS_UNSET = 0
LOGON_SUCCESS = 1
LOGON_ERROR = 2
LOGON_ERROR_NO_RECONNECT = 3
LOGON_RECONNECT_NEW_ADDRESS = 4

class RequestActionEnum(IntEnum):
SUBSCRIBE = 1
UNSUBSCRIBE = 2
SNAPSHOT = 3
SNAPSHOT_WITH_INTERVAL_UPDATES = 4

class OrderStatusEnum(IntEnum):
ORDER_STATUS_UNSPECIFIED = 0
ORDER_STATUS_ORDER_SENT = 1
ORDER_STATUS_PENDING_OPEN = 2
ORDER_STATUS_PENDING_CHILD = 3
ORDER_STATUS_OPEN = 4
ORDER_STATUS_PENDING_CANCEL_REPLACE = 5
ORDER_STATUS_PENDING_CANCEL = 6
ORDER_STATUS_FILLED = 7
ORDER_STATUS_CANCELED = 8
ORDER_STATUS_REJECTED = 9
ORDER_STATUS_PARTIALLY_FILLED = 10

class OrderUpdateReasonEnum(IntEnum):
ORDER_UPDATE_REASON_UNSET = 0
OPEN_ORDERS_REQUEST_RESPONSE = 1
NEW_ORDER_ACCEPTED = 2
GENERAL_ORDER_UPDATE = 3
ORDER_FILLED = 4
ORDER_FILLED_PARTIALLY = 5
ORDER_CANCELED = 6
ORDER_CANCEL_REPLACE_COMPLETE = 7
NEW_ORDER_REJECTED = 8
ORDER_CANCEL_REJECTED = 9
ORDER_CANCEL_REPLACE_REJECTED = 10

class AtBidOrAskEnum8(IntEnum):
BID_ASK_UNSET_8 = 0
AT_BID_8 = 1
AT_ASK_8 = 2

class AtBidOrAskEnum(IntEnum):
BID_ASK_UNSET = 0
AT_BID = 1
AT_ASK = 2

class MarketDepthUpdateTypeEnum(IntEnum):
MARKET_DEPTH_UNSET = 0
MARKET_DEPTH_INSERT_UPDATE_LEVEL = 1
MARKET_DEPTH_DELETE_LEVEL = 2

class OrderTypeEnum(IntEnum):
ORDER_TYPE_UNSET = 0
ORDER_TYPE_MARKET = 1
ORDER_TYPE_LIMIT = 2
ORDER_TYPE_STOP = 3
ORDER_TYPE_STOP_LIMIT = 4
ORDER_TYPE_MARKET_IF_TOUCHED = 5
ORDER_TYPE_LIMIT_IF_TOUCHED = 6
ORDER_TYPE_MARKET_LIMIT = 7

class TimeInForceEnum(IntEnum):
TIF_UNSET = 0
TIF_DAY = 1
TIF_GOOD_TILL_CANCELED = 2
TIF_GOOD_TILL_DATE_TIME = 3
TIF_IMMEDIATE_OR_CANCEL = 4
TIF_ALL_OR_NONE = 5
TIF_FILL_OR_KILL = 6

class BuySellEnum(IntEnum):
BUY_SELL_UNSET = 0
BUY = 1
SELL = 2

class OpenCloseTradeEnum(IntEnum):
TRADE_UNSET = 0
TRADE_OPEN = 1
TRADE_CLOSE = 2

class MarketDataFeedStatusEnum(IntEnum):
MARKET_DATA_FEED_STATUS_UNSET = 0
MARKET_DATA_FEED_UNAVAILABLE = 1
MARKET_DATA_FEED_AVAILABLE = 2

class PriceDisplayFormatEnum(IntEnum):
PRICE_DISPLAY_FORMAT_DECIMAL_0 = 0
PRICE_DISPLAY_FORMAT_DECIMAL_1 = 1
PRICE_DISPLAY_FORMAT_DECIMAL_2 = 2
PRICE_DISPLAY_FORMAT_DECIMAL_3 = 3
PRICE_DISPLAY_FORMAT_DECIMAL_4 = 4
PRICE_DISPLAY_FORMAT_DECIMAL_5 = 5
PRICE_DISPLAY_FORMAT_DECIMAL_6 = 6
PRICE_DISPLAY_FORMAT_DECIMAL_7 = 7
PRICE_DISPLAY_FORMAT_DECIMAL_8 = 8
PRICE_DISPLAY_FORMAT_DECIMAL_9 = 9
PRICE_DISPLAY_FORMAT_UNSET = -1

class SecurityTypeEnum(IntEnum):
SECURITY_TYPE_UNSET = 0
SECURITY_TYPE_FUTURE = 1
SECURITY_TYPE_STOCK = 2
SECURITY_TYPE_FOREX = 3
SECURITY_TYPE_INDEX = 4

class PutCallEnum(IntEnum):
PC_UNSET = 0
PC_CALL = 1
PC_PUT = 2

class HistoricalDataIntervalEnum(IntEnum):
INTERVAL_TICK = 0
INTERVAL_1_SECOND = 1
INTERVAL_2_SECONDS = 2
INTERVAL_4_SECONDS = 4
INTERVAL_5_SECONDS = 5
INTERVAL_10_SECONDS = 10
INTERVAL_30_SECONDS = 30
INTERVAL_1_MINUTE = 60
INTERVAL_1_DAY = 86400


async def SendDTCMessage(Writer, DTCMessage):
try:
Writer.write(DTCMessage)
await Writer.drain()

except ConnectionResetError:
return

except Exception as e:
print(f"SendDTCMessage: {e.__class__.__name__}")

async def LogonResponse(Writer, **Data):
DefaultValues = {
"ProtocolVersion": CURRENT_VERSION, # ProtocolVersion, (int32_t), 4 bytes, i
"Result": LogonStatusEnum.LOGON_STATUS_UNSET, # Result, (LogonStatusEnum int32_t), 4 bytes, i
"ResultText": b"", # ResultText, (char), 96 bytes
"ReconnectAddress": b"", # ReconnectAddress, (char), 64 bytes
"Integer1": 0, # Integer1, (int32_t), 4 bytes, i
"ServerName": b"", # ServerName, (char), 60 bytes
"MarketDepthUpdatesBestBidAndAsk": 0, # MarketDepthUpdatesBestBidAndAsk, (uint8_t), 1 byte, B
"TradingIsSupported": 0, # TradingIsSupported, (uint8_t), 1 byte, B
"OCOOrdersSupported": 0, # OCOOrdersSupported, (uint8_t), 1 byte, B
"OrderCancelReplaceSupported": 0, # OrderCancelReplaceSupported, (uint8_t), 1 byte, B
"SymbolExchangeDelimiter": b"", # SymbolExchangeDelimiter, (char), 4 byte
"SecurityDefinitionsSupported": 0, # SecurityDefinitionsSupported, (uint8_t), 1 byte, B
"HistoricalPriceDataSupported": 0, # HistoricalPriceDataSupported, (uint8_t), 1 byte, B
"ResubscribeWhenMarketDataFeedAvailable": 0, # ResubscribeWhenMarketDataFeedAvailable, (uint8_t), 1 byte, B
"MarketDepthIsSupported": 0, # MarketDepthIsSupported, (uint8_t), 1 byte, B
"OneHistoricalPriceDataRequestPerConnection": 0, # OneHistoricalPriceDataRequestPerConnection, (uint8_t), 1 byte, B
"BracketOrdersSupported": 0, # BracketOrdersSupported, (uint8_t), 1 byte, B
"UseIntegerPriceOrderMessages": 0, # UseIntegerPriceOrderMessages, (uint8_t), 1 byte, B
"UsesMultiplePositionsPerSymbolAndTradeAccount": 0, # UsesMultiplePositionsPerSymbolAndTradeAccount, (uint8_t), 1 byte, B
"MarketDataSupported": 0 # MarketDataSupported (uint8_t), 1 byte, B
}

DefaultValues.update(Data)

FormatString = "<HHii96s64si60sBBBB4sBBBBBBBBB"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.LOGON_RESPONSE,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def Heartbeat(Writer, **Data):
DefaultValues = {
"NumDroppedMessages": 0, # NumDroppedMessages, (uint32_t), 4 bytes, I
"CurrentDateTimeWithSeconds": 0 # CurrentDateTimeWithSeconds, (t_DateTime int64_t), 8 bytes, q
}

DefaultValues.update(Data)

FormatString = "<HHIq"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.HEARTBEAT,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def MarketDataSnapshot(Writer, **Data):
DefaultValues = {
"SymbolID": 0, # SymbolID, (uint32_t), 4 bytes, I
"SessionSettlementPrice": DBL_MAX, # SessionSettlementPrice, (double), 8 bytes, d
"SessionOpenPrice": DBL_MAX, # SessionOpenPrice, (double), 8 bytes, d
"SessionHighPrice": DBL_MAX, # SessionHighPrice, (double), 8 bytes, d
"SessionLowPrice": DBL_MAX, # SessionLowPrice, (double), 8 bytes, d
"SessionVolume": DBL_MAX, # SessionVolume, (double), 8 bytes, d
"SessionNumTrades": UINT_MAX, # SessionNumTrades, (uint32_t), 4 bytes, I
"OpenInterest": UINT_MAX, # OpenInterest, (uint32_t), 4 bytes, I
"BidPrice": DBL_MAX, # BidPrice, (double), 8 bytes, d
"AskPrice": DBL_MAX, # AskPrice, (double), 8 bytes, d
"AskQuantity": DBL_MAX, # AskQuantity, (double), 8 bytes, d
"BidQuantity": DBL_MAX, # BidQuantity, (double), 8 bytes, d
"LastTradePrice": DBL_MAX, # LastTradePrice, (double), 8 bytes, d
"LastTradeVolume": DBL_MAX, # LastTradeVolume, (double), 8 bytes, d
"LastTradeDateTimeWithMilliseconds": 0.0, # LastTradeDateTimeWithMilliseconds, (t_DateTimeWithMilliseconds double), 8 bytes, d
"BidAskDateTimeWithMilliseconds": 0.0, # BidAskDateTimeWithMilliseconds, (t_DateTimeWithMilliseconds double), 8 bytes, d
"SessionSettlementDateTimeWithSeconds": 0, # SessionSettlementDateTimeWithSeconds, (t_DateTime4Byte uint32_t), 4 bytes, I
"TradingSessionDateTimeWithSeconds": 0 # TradingSessionDateTimeWithSeconds, (t_DateTime4Byte uint32_t), 4 bytes, I
}

DefaultValues.update(Data)

FormatString = "<HHIdddddIIddddddddII"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.MARKET_DATA_SNAPSHOT,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def MarketDataFeedSymbolStatus(Writer, **Data):
DefaultValues = {
"Status": MarketDataFeedStatusEnum.MARKET_DATA_FEED_STATUS_UNSET, # Status, (MarketDataFeedStatusEnum int32_t), 4 bytes, i
"SymbolID": 0 # SymbolID, (uint32_t), 4 bytes, I
}

DefaultValues.update(Data)

FormatString = "<HHiI"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.MARKET_DATA_FEED_SYMBOL_STATUS,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def MarketDataUpdateSessionHigh(Writer, **Data):
DefaultValues = {
"SymbolID": 0, # SymbolID, (uint32_t), 4 bytes, I
"Price": 0.0 # Price, (double), 8 bytes, d
}

DefaultValues.update(Data)

FormatString = "<HHIf"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.MARKET_DATA_UPDATE_SESSION_HIGH,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def MarketDataUpdateSessionLow(Writer, **Data):
DefaultValues = {
"SymbolID": 0, # SymbolID, (uint32_t), 4 bytes, I
"Price": 0.0 # Price, (double), 8 bytes, d
}

DefaultValues.update(Data)

FormatString = "<HHIf"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.MARKET_DATA_UPDATE_SESSION_LOW,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def MarketDataUpdateOpenInterest(Writer, **Data):
DefaultValues = {
"SymbolID": 0, # SymbolID, (uint32_t), 4 bytes, I
"OpenInterest": 0 # OpenInterest, (uint32_t), 4 bytes, I
}

DefaultValues.update(Data)

FormatString = "<HHII"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.MARKET_DATA_UPDATE_OPEN_INTEREST,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def MarketDataUpdateBidAskFloatWithMicroseconds(Writer, **Data):
DefaultValues = {
"SymbolID": 0, # SymbolID, (uint32_t), 4 bytes, I
"BidPrice": FLT_MAX, # BidPrice, (float), 4 bytes, f
"BidQuantity": 0.0, # BidQuantity, (float), 4 bytes, f
"AskPrice": FLT_MAX, # AskPrice, (float), 4 bytes, f
"AskQuantity": 0.0, # AskQuantity, (float), 4 bytes, f
"DateTime": 0 # DateTime, (t_DateTimeWithMicrosecondsInt int64_t), 8 bytes, q
}

DefaultValues.update(Data)

FormatString = "<HHIffffq"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.MARKET_DATA_UPDATE_BID_ASK_FLOAT_WITH_MICROSECONDS,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def MarketDataUpdateTradeWithUnbundledIndicator2(Writer, **Data):
DefaultValues = {
"SymbolID": 0, # SymbolID, (uint32_t), 4 bytes, I
"Price": 0.0, # Price, (float), 4 bytes, f
"Volume": 0, # Volume, (uint32_t), 4 bytes, I
"DateTime": 0, # DateTime, (t_DateTimeWithMicrosecondsInt int64_t), 8 bytes, q
"Side": AtBidOrAskEnum8.BID_ASK_UNSET_8 # AtBidOrAsk, (AtBidOrAskEnum8 uint8_t), 2 byte, B
}

DefaultValues.update(Data)

FormatString = "<HHIfIqB"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.MARKET_DATA_UPDATE_TRADE_WITH_UNBUNDLED_INDICATOR_2,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def MarketDepthSnapshotLevel(Writer, **Data):
DefaultValues = {
"SymbolID": 0, # SymbolID, (uint32_t), 4 bytes, i
"Side": AtBidOrAskEnum.BID_ASK_UNSET, # AtBidOrAsk, (AtBidOrAskEnum int16_t), 8 bytes, q
"Price": 0.0, # Price, (double), 8 bytes, d
"Quantity": 0.0, # Quantity, (double), 8 bytes, d
"Level": 0, # Level (uint16_t), 4 bytes, H
"IsFirstMessageInBatch": 0, # IsFirstMessageInBatch, (FinalUpdateInBatchEnum uint8_t), 2 byte, B
"IsLastMessageInBatch": 0, # IsLastMessageInBatch, (uint8_t), 1 byte, B
"DateTimeWithMilliseconds": 0.0, # DateTimeWithMilliseconds, (t_DateTimeWithMilliseconds double), 8 bytes, d
"NumOrders": 0 # NumOrders, (uint32_t), 4 bytes, I
}

DefaultValues.update(Data)

FormatString = "<HHiqddHBB4xdI"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.MARKET_DEPTH_SNAPSHOT_LEVEL,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def MarketDepthUpdateLevel(Writer, **Data):
DefaultValues = {
"SymbolID": 0, # SymbolID, (uint32_t), 4 bytes, i
"Side": AtBidOrAskEnum.BID_ASK_UNSET, # AtBidOrAsk, (AtBidOrAskEnum int16_t), 8 bytes, q
"Price": 0.0, # Price, (double), 8 bytes, d
"Quantity": 0.0, # Quantity, (double), 8 bytes, d
"UpdateType": MarketDepthUpdateTypeEnum.MARKET_DEPTH_UNSET, # UpdateType, (MarketDepthUpdateTypeEnum uint8_t), 2 byte, B
"DateTimeWithMilliseconds": 0.0, # DateTimeWithMilliseconds, (t_DateTimeWithMilliseconds double), 8 bytes, d
"NumOrders": 0 # NumOrders, (uint32_t), 4 bytes, I
}

DefaultValues.update(Data)

FormatString = "<HHiqddB7xdI"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.MARKET_DEPTH_UPDATE_LEVEL,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def OrderUpdate(Writer, **Data):
DefaultValues = {
"RequestID": 0, # RequestID, (int32_t), 4 bytes, i
"TotalNumberMessages": 1, # TotalNumberMessages, (int32_t), 4 bytes, i
"MessageNumber": 1, # MessageNumber, (int32_t), 4 bytes, i
"Symbol": b"", # Symbol, (char), 64 bytes
"Exchange": b"", # Exchange, (char), 16 bytes
"PreviousServerOrderID": b"", # PreviousServerOrderID, (char), 32 bytes
"ServerOrderID": b"", # ServerOrderID, (char), 32 bytes
"ClientOrderID": b"", # ClientOrderID, (char), 32 bytes
"ExchangeOrderID": b"", # ExchangeOrderID, (char), 32 bytes
"OrderStatus": OrderStatusEnum.ORDER_STATUS_UNSPECIFIED, # OrderStatus, (OrderStatusEnum int32_t), 4 bytes, i
"OrderUpdateReason": OrderUpdateReasonEnum.ORDER_UPDATE_REASON_UNSET, # OrderUpdateReason, (OrderUpdateReasonEnum int32_t), 4 bytes, i
"OrderType": OrderTypeEnum.ORDER_TYPE_UNSET, # OrderType, (OrderTypeEnum int32_t), 4 bytes, i
"BuySell": BuySellEnum.BUY_SELL_UNSET, # BuySell, (BuySellEnum int32_t), 4 bytes, i
"Price1": DBL_MAX, # Price1, (double), 8 bytes, d
"Price2": DBL_MAX, # Price2, (double), 8 bytes, d
"TimeInForce": TimeInForceEnum.TIF_UNSET, # TimeInForce, (TimeInForceEnum int32_t), 4 bytes, i
"GoodTillDateTimeWithSeconds": 0, # GoodTillDateTimeWithSeconds, (t_DateTime int64_t), 8 bytes, q
"OrderQuantity": DBL_MAX, # OrderQuantity, (double), 8 bytes, d
"FilledQuantity": DBL_MAX, # FilledQuantity, (double), 8 bytes, d
"RemainingQuantity": DBL_MAX, # RemainingQuantity, (double), 8 bytes, d
"AverageFillPrice": DBL_MAX, # AverageFillPrice, (double), 8 bytes, d
"LastFillPrice": DBL_MAX, # LastFillPrice, (double), 8 bytes, d
"LastFillDateTimeWithSeconds": 0, # LastFillDateTimeWithSeconds, (t_DateTime int64_t), 8 bytes, q
"LastFillQuantity": DBL_MAX, # LastFillQuantity, (double), 8 bytes, d
"LastFillExecutionID": b"", # LastFillExecutionID, (char), 64 bytes
"TradeAccount": b"", # TradeAccount, (char), 32 bytes
"InfoText": b"", # InfoText, (char), 96 bytes
"NoOrders": 0, # NoOrders, (uint8_t), 1 byte, B
"ParentServerOrderID": b"", # ParentServerOrderID, (char), 32 bytes
"OCOLinkedOrderServerOrderID": b"", # OCOLinkedOrderServerOrderID, (char), 32 bytes
"OpenOrClose": OpenCloseTradeEnum.TRADE_UNSET, # OpenOrClose, (OpenCloseTradeEnum int32_t), 4 bytes, i
"PreviousClientOrderID": b"", # PreviousClientOrderID, (char), 32 bytes
"FreeFormText": b"", # FreeFormText, (char), 48 bytes
"OrderReceivedDateTimeWithSeconds": 0, # OrderReceivedDateTimeWithSeconds, (t_DateTime int64_t), 8 bytes, q
"LatestTransactionDateTimeWithMilliseconds": 0.0 # LatestTransactionDateTimeWithMilliseconds, (t_DateTimeWithMilliseconds double), 8 bytes, d
}

DefaultValues.update(Data)

FormatString = "<HHiii64s16s32s32s32s32siiiiddi4xqdddddqd64s32s96sB32s32s3xi32s48sqd"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.ORDER_UPDATE,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def OpenOrdersReject(Writer, **Data):
DefaultValues = {
"RequestID": 0, # RequestID, (int32_t), 4 bytes, i
"RejectText": b"", # RejectText, (char), 96 bytes
}

DefaultValues.update(Data)

FormatString = "<HHi96s"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.OPEN_ORDERS_REJECT,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def HistoricalOrderFillResponse(Writer, **Data):
DefaultValues = {
"RequestID": 0, # RequestID, (int32_t), 4 bytes, i
"TotalNumberMessages": 1, # TotalNumberMessages, (int32_t), 4 bytes, i
"MessageNumber": 1, # MessageNumber, (int32_t), 4 bytes, i
"Symbol": b"", # Symbol, (char), 64 bytes
"Exchange": b"", # Exchange, (char), 16 bytes
"ServerOrderID": b"", # ServerOrderID, (char), 32 bytes
"BuySell": BuySellEnum.BUY_SELL_UNSET, # BuySell, (BuySellEnum int32_t), 4 bytes, i
"Price": 0.0, # Price, (double), 8 bytes, d
"DateTimeWithSeconds": 0, # DateTimeWithSeconds, (t_DateTime int64_t), 8 bytes, q
"Quantity": 0.0, # Quantity, (double), 8 bytes, d
"UniqueExecutionID": b"", # UniqueExecutionID, (char), 64 bytes
"TradeAccount": b"", # TradeAccount, (char), 32 bytes
"OpenClose": OpenCloseTradeEnum.TRADE_UNSET, # OpenClose, (BuySellEnum int32_t), 4 bytes, i
"NoOrderFills": 0 # NoOrderFills, (uint8_t), 1 byte, B
}

DefaultValues.update(Data)

FormatString = "<HHiii64s16s32si4xdqd64s32siB"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.HISTORICAL_ORDER_FILL_RESPONSE,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def PositionUpdate(Writer, **Data):
DefaultValues = {
"RequestID": 0, # RequestID, (int32_t), 4 bytes, i
"TotalNumberMessages": 1, # TotalNumberMessages, (int32_t), 4 bytes, i
"MessageNumber": 1, # MessageNumber, (int32_t), 4 bytes, i
"Symbol": b"", # Symbol, (char), 64 bytes
"Exchange": b"", # Exchange, (char), 16 bytes
"Quantity": 0.0, # Quantity, (double), 8 bytes, d
"AveragePrice": 0.0, # AveragePrice, (double), 8 bytes, d
"PositionIdentifier": b"", # PositionIdentifier, (char), 32 bytes
"TradeAccount": b"", # TradeAccount, (char), 32 bytes
"NoPositions": 0, # NoPositions, (uint8_t), 1 byte, B
"Unsolicited": 0, # Unsolicited, (uint8_t), 1 byte, B
"MarginRequirement": 0.0, # MarginRequirement, (double), 8 bytes, d
"EntryDateTimeWithSeconds": 0, # EntryDateTimeWithSeconds, (t_DateTime4Byte uint32_t), 4 bytes, I
"OpenProfitLoss": 0.0, # OpenProfitLoss, (double), 8 bytes, d
"HighPriceDuringPosition": 0.0, # HighPriceDuringPosition, (double), 8 bytes, d
"LowPriceDuringPosition": 0.0 # LowPriceDuringPosition, (double), 8 bytes, d
}

DefaultValues.update(Data)

FormatString = "<HHiii64s16sdd32s32sBB6xdI4xddd"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.POSITION_UPDATE,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def TradeAccountResponse(Writer, **Data):
DefaultValues = {
"TotalNumberMessages": 1, # TotalNumberMessages, (int32_t), 4 bytes, i
"MessageNumber": 1, # MessageNumber, (int32_t), 4 bytes, i
"TradeAccount": b"", # TradeAccount, (char), 32 bytes
"RequestID": 0 # RequestID, (int32_t), 4 bytes, i
}

DefaultValues.update(Data)

FormatString = "<HHii32si"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.TRADE_ACCOUNT_RESPONSE,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def SecurityDefinitionResponse(Writer, **Data):
DefaultValues = {
"RequestID": 0, # RequestID, (int32_t), 4 bytes, i
"Symbol": b"", # Symbol, (char), 64 bytes
"Exchange": b"", # Exchange, (char), 16 bytes
"SecurityType": SecurityTypeEnum.SECURITY_TYPE_UNSET, # SecurityType, (SecurityTypeEnum int32_t), 4 bytes, i
"Description": b"", # Description, (char), 64 bytes
"MinPriceIncrement": 0.0, # MinPriceIncrement, (float), 4 bytes, f
"PriceDisplayFormat": PriceDisplayFormatEnum.PRICE_DISPLAY_FORMAT_UNSET, # PriceDisplayFormat, (PriceDisplayFormatEnum int32_t), 4 bytes, i
"CurrencyValuePerIncrement": 0.0, # CurrencyValuePerIncrement, (float), 4 bytes, f
"IsFinalMessage": 0, # IsFinalMessage, (uint8_t), 1 byte, B
"FloatToIntPriceMultiplier": 1.0, # FloatToIntPriceMultiplier, (float), 4 bytes, f
"IntToFloatPriceDivisor": 1.0, # IntegerToFloatPriceDivisor, (float), 4 bytes, f
"UnderlyingSymbol": b"", # UnderlyingSymbol, (char), 32 bytes
"UpdatesBidAskOnly": 0, # UpdatesBidAskOnly, (uint8_t), 1 byte, B
"StrikePrice": 0.0, # StrikePrice, (float), 4 bytes, f
"PutOrCall": PutCallEnum.PC_UNSET, # PutOrCall, (PutCallEnum int32_t), 4 bytes, i
"ShortInterest": 0, # ShortInterest, (uint32_t), 4 bytes, I
"SecurityExpirationDate": 0, # SecurityExpirationDate, (t_DateTime4Byte uint32_t), 4 bytes, I
"BuyRolloverInterest": 0.0, # BuyRolloverInterest, (float), 4 bytes, f
"SellRolloverInterest": 0.0, # SellRolloverInterest, (float), 4 bytes, f
"EarningsPerShare": 0.0, # EarningsPerShare, (float), 4 bytes, f
"SharesOutstanding": 0, # SharesOutstanding, (uint32_t), 4 bytes, I
"IntToFloatQuantityDivisor": 0.0, # IntToFloatQuantityDivisor, (float), 4 bytes, f
"HasMarketDepthData": 1, # HasMarketDepthData, (uint8_t), 1 byte, B
"DisplayPriceMultiplier": 1.0, # DisplayPriceMultiplier, (float), 4 bytes, f
"ExchangeSymbol": b"", # ExchangeSymbol, (char), 64 bytes
"RolloverDate": 0, # RolloverDate, (t_DateTime4Byte uint32_t), 4 bytes, I
"InitialMarginRequirement": 0.0, # InitialMarginRequirement, (float), 4 bytes, f
"MaintenanceMarginRequirement": 0.0, # MaintenanceMarginRequirement, (float), 4 bytes, f
"Currency": b"", # Currency, (char), 8 bytes
"ContractSize": 0.0, # ContractSize, (float), 4 bytes, f
"OpenInterest": 0, # OpenInterest, (uint32_t), 4 bytes, I
"IsDelayed": 0 # IsDelayed, (uint8_t), 1 byte, B
}

DefaultValues.update(Data)

FormatString = "<HHi64s16si64sfifB3xff32sB3xfiIIfffIfB3xf64sIff8sfIB"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.SECURITY_DEFINITION_RESPONSE,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def AccountBalanceUpdate(Writer, **Data):
DefaultValues = {
"RequestID": 0, # RequestID, (int32_t), 4 bytes, i
"CashBalance": 0.0, # CashBalance, (double), 8 bytes, d
"BalanceAvailableForNewPositions": 0.0, # BalanceAvailableForNewPositions, (double), 8 bytes, d
"AccountCurrency": b"", # AccountCurrency, (char), 8 bytes
"TradeAccount": b"", # TradeAccount, (char), 32 bytes
"SecuritiesValue": 0.0, # SecuritiesValue, (double), 8 bytes, d
"MarginRequirement": 0.0, # MarginRequirement, (double), 8 bytes, d
"TotalNumberMessages": 1, # TotalNumberMessages, (int32_t), 4 bytes, i
"MessageNumber": 1, # MessageNumber, (int32_t), 4 bytes, i
"NoAccountBalances": 0, # NoAccountBalances, (uint8_t), 1 byte, B
"Unsolicited": 0, # Unsolicited, (uint8_t), 1 byte, B
"OpenPositionsProfitLoss": 0.0, # OpenPositionsProfitLoss, (double), 8 bytes, d
"DailyProfitLoss": 0.0, # DailyProfitLoss, (double), 8 bytes, d
"InfoText": b"" # InfoText, (char), 96 bytes
}

DefaultValues.update(Data)

FormatString = "<HHidd8s32sddiiBBdd96s"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.ACCOUNT_BALANCE_UPDATE,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def HistoricalAccountBalanceResponse(Writer, **Data):
DefaultValues = {
"RequestID": 0, # RequestID, (int32_t), 4 bytes, i
"DateTimeWithMilliseconds": 0.0, # DateTimeWithMilliseconds, (t_DateTimeWithMilliseconds double), 8 bytes, d
"CashBalance": 0.0, # CashBalance, (double), 8 bytes, d
"AccountCurrency": b"", # AccountCurrency, (char), 8 bytes
"TradeAccount": b"", # TradeAccount, (char), 32 bytes
"IsFinalResponse": 0, # IsFinalResponse, (uint8_t), 1 byte, B
"NoAccountBalances": 0, # NoAccountBalances, (uint8_t), 1 byte, B
"InfoText": b"", # InfoText, (char), 96 bytes
"TransactionId": b"" # TransactionId, (char), 96 bytes
}

DefaultValues.update(Data)

FormatString = "<HHidd8s32sBB96s96s"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.HISTORICAL_ACCOUNT_BALANCE_RESPONSE,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def HistoricalPriceDataResponseHeader(Writer, **Data):
DefaultValues = {
"RequestID": 0, # RequestID, (int32_t), 4 bytes, i
"RecordInterval": HistoricalDataIntervalEnum.INTERVAL_TICK, # RecordInterval, (HistoricalDataIntervalEnum int32_t), 4 bytes, i
"UseZLibCompression": 0, # UseZLibCompression, (uint8_t), 1 byte, B
"NoRecordsToReturn": 0 # NoRecordsToReturn, (uint8_t), 1 byte, B
}

DefaultValues.update(Data)

FormatString = "<HHiiBB"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.HISTORICAL_PRICE_DATA_RESPONSE_HEADER,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)

async def HistoricalPriceDataRecordResponse(Writer, **Data):
DefaultValues = {
"RequestID": 0, # RequestID, (int32_t), 4 bytes, i
"StartDateTime": 0, # StartDateTime, (t_DateTimeWithMicrosecondsInt int64_t), 8 bytes, q
"OpenPrice": 0.0, # OpenPrice, (double), 8 bytes, d
"HighPrice": 0.0, # HighPrice, (double), 8 bytes, d
"LowPrice": 0.0, # LowPrice, (double), 8 bytes, d
"LastPrice": 0.0, # LastPrice, (double), 8 bytes, d
"Volume": 0.0, # Volume, (double), 8 bytes, d
"Union": 0, # Union, (OpenInterest or NumTrades), (uint32_t), 4 bytes, I
"BidVolume": 0.0, # BidVolume, (double), 8 bytes, d
"AskVolume": 0.0, # AskVolume, (double), 8 bytes, d
"IsFinalRecord": 0 # IsFinalRecord, (uint8_t), 1 byte, B
}

if "OpenInterest" in Data:
Data["Union"] = Data["OpenInterest"]
del Data["OpenInterest"]
elif "NumTrades" in Data:
Data["Union"] = Data["NumTrades"]
del Data["NumTrades"]

DefaultValues.update(Data)

FormatString = "<HHiq5dI4xddB"
DTCMessage = struct.pack(
FormatString,
struct.calcsize(FormatString),
DTCMessageType.HISTORICAL_PRICE_DATA_RECORD_RESPONSE,
*DefaultValues.values()
)

await SendDTCMessage(Writer, DTCMessage)