Login Page - Create Account

Support Board


Date/Time: Fri, 18 Apr 2025 06:33:00 +0000



[Programming Help] - DTC request and response

View Count: 349

[2025-03-04 07:34:35]
Fungraphic72 - Posts: 16
Hello, I searched in the documentation how to have the ProfitLoss of my closed trades but I did not find.
Does anyone know how to get this information?
I can get almost all the information except this one.
I tried to calculate it with the recovered data but it never reflects the reality of my trades and my trading history.

Here's a sample image of what I can recover with the DTC server.

If it is not possible to have this information, is it possible to have the method of calculation to have the good PNL.


Thank you in advance
Date Time Of Last Edit: 2025-03-04 07:42:39
imageDatas_DTC.png / V - Attached On 2025-03-04 07:41:21 UTC - Size: 66.52 KB - 57 views
[2025-03-05 13:13:25]
Fungraphic72 - Posts: 16
There's no one to help, not even the developers at sierra?
It's a pity, because I need to finish my trading journal programme.

Interface image.
Attachment Deleted.
imagejournal.png / V - Attached On 2025-03-05 13:12:35 UTC - Size: 127 KB - 38 views
[2025-03-07 07:57:43]
Sierra_Chart Engineering - Posts: 19259
Use this request to get what you need through the DTC protocol server:
Sierra Chart Custom: HISTORICAL_TRADES_REQUEST [s_HistoricalTradesRequest structure] Client >> Server
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2025-03-07 07:57:51
[2025-03-07 17:01:30]
Fungraphic72 - Posts: 16
I tested, everything seems to work but I have no data in response.
I tested with the Empty symbol; then with MESH5 and MESH5.CME
I also tested with the username and password of my broker account and still no data.

Here is the structure of my python classes:


from dtc.enums.message_types import MessageTypes
from lib.base_message_type import BaseMessageType


class HistoricalTradesRequest(BaseMessageType):
def __init__(self,
request_id=None,
symbol=None,
trade_account=None,
start_date_time=None):
self.Type = MessageTypes.HISTORICAL_TRADES_REQUEST
self.RequestID = request_id
self.Symbol = symbol
self.TradeAccount = trade_account
self.StartDateTime = start_date_time

@staticmethod
def from_message_short(message_obj):
packet = message_obj.get('F')
return HistoricalTradesRequest(
request_id=packet[0],
symbol=packet[1],
trade_account=packet[2],
start_date_time=packet[3]
)

@staticmethod
def from_message_long(message_obj):
return HistoricalTradesRequest(
request_id=message_obj.get('RequestID'),
symbol=message_obj.get('Symbol'),
trade_account=message_obj.get('TradeAccount'),
start_date_time=message_obj.get('StartDateTime')
)

@staticmethod
def from_message(message_obj):
if 'F' in message_obj:
return HistoricalTradesRequest.from_message_short(message_obj)
else:
return HistoricalTradesRequest.from_message_long(message_obj)

@staticmethod
def get_message_type_name():
return "HistoricalTradesRequest"


from dtc.enums.message_types import MessageTypes
from lib.base_message_type import BaseMessageType


class HistoricalTradesResponse(BaseMessageType):
def __init__(self,
request_id=None,
symbol=None,
trade_account=None,
entry_date_time=None,
exit_date_time=None,
entry_price=None,
exit_price=None,
trade_type=None,
entry_quantity=None,
exit_quantity=None,
max_open_quantity=None,
closed_profit_loss=None,
maximum_open_position_loss=None,
maximum_open_position_profit=None,
commission=None):
self.Type = MessageTypes.HISTORICAL_TRADES_RESPONSE
self.RequestID = request_id
self.Symbol = symbol
self.TradeAccount = trade_account
self.EntryDateTime = entry_date_time
self.ExitDateTime = exit_date_time
self.EntryPrice = entry_price
self.ExitPrice = exit_price
self.TradeType = trade_type
self.EntryQuantity = entry_quantity
self.ExitQuantity = exit_quantity
self.MaxOpenQuantity = max_open_quantity
self.ClosedProfitLoss = closed_profit_loss
self.MaximumOpenPositionLoss = maximum_open_position_loss
self.MaximumOpenPositionProfit = maximum_open_position_profit
self.Commission = commission

@staticmethod
def from_message_short(message_obj):
packet = message_obj.get('F')
return HistoricalTradesResponse(
request_id=packet[0],
symbol=packet[1],
trade_account=packet[2],
entry_date_time=packet[3],
exit_date_time=packet[4],
entry_price=packet[5],
exit_price=packet[6],
trade_type=packet[7],
entry_quantity=packet[8],
exit_quantity=packet[9],
max_open_quantity=packet[10],
closed_profit_loss=packet[11],
maximum_open_position_loss=packet[12],
maximum_open_position_profit=packet[13],
commission=packet[14]
)

@staticmethod
def from_message_long(message_obj):
return HistoricalTradesResponse(
request_id=message_obj.get('RequestID'),
symbol=message_obj.get('Symbol'),
trade_account=message_obj.get('TradeAccount'),
entry_date_time=message_obj.get('EntryDateTime'),
exit_date_time=message_obj.get('ExitDateTime'),
entry_price=message_obj.get('EntryPrice'),
exit_price=message_obj.get('ExitPrice'),
trade_type=message_obj.get('TradeType'),
entry_quantity=message_obj.get('EntryQuantity'),
exit_quantity=message_obj.get('ExitQuantity'),
max_open_quantity=message_obj.get('MaxOpenQuantity'),
closed_profit_loss=message_obj.get('ClosedProfitLoss'),
maximum_open_position_loss=message_obj.get('MaximumOpenPositionLoss'),
maximum_open_position_profit=message_obj.get('MaximumOpenPositionProfit'),
commission=message_obj.get('Commission')
)

@staticmethod
def from_message(message_obj):
if 'F' in message_obj:
return HistoricalTradesResponse.from_message_short(message_obj)
else:
return HistoricalTradesResponse.from_message_long(message_obj)

@staticmethod
def get_message_type_name():
return "HistoricalTradesResponse"

Here is a screen of the sierra messagelog.
Date Time Of Last Edit: 2025-03-07 17:05:34
imageDTC_request.png / V - Attached On 2025-03-07 17:01:22 UTC - Size: 29.73 KB - 25 views
[2025-03-07 22:08:29]
Fungraphic72 - Posts: 16
I forgot to give you the format of the request sent to the server.

Here it is:

2025-03-07 23:04:55,477 - DTC_Client - INFO - Sending HistoricalTradesRequest for symbol MESH5.CME (RequestID: 1001): HistoricalTradesRequest(RequestID=1001, Symbol='MESH5.CME',
TradeAccount='PP-CASH...........', StartDateTime=1738368060)

Date Time Of Last Edit: 2025-03-08 10:02:04
[2025-03-08 11:19:35]
Fungraphic72 - Posts: 16
I started again from zero and simplified my client to test and Yes! It works, I have a return message. Now I just have to wait until the market is open to see if it returns the data.

PS C:\Client_DTC> python CustomDTC_Client.py -n 127.0.0.1 -l -p 11099 -q 11098
INFO:root:Connecting to ws://127.0.0.1:11099
INFO:websocket:Websocket connected
INFO:root:On open
INFO:root:[CustomDTCClient] post_login_thread => envoi HISTORICAL_TRADES_REQUEST (JSON).
INFO:root:[CustomDTCClient] HISTORICAL_TRADES_REQUEST envoyé : {'Type': 10100, 'RequestID': 2222, 'Symbol': 'MESH5', 'TradeAccount': 'PP-CASH.......', 'StartDateTime': 45695.0}
INFO:root:[CustomDTCClient] Reçu HISTORICAL_TRADES_RESPONSE :
INFO:root:{'ClosedProfitLoss': 0, 'Commission': 0, 'EntryDateTime': 0, 'EntryPrice': 0, 'EntryQuantity': 0, 'ExitDateTime': 0, 'ExitPrice': 0, 'ExitQuantity': 0, 'MaxOpenQuantity': 0, 'MaximumOpenPositionLoss': 0,
'MaximumOpenPositionProfit': 0, 'RequestID': 2222, 'Symbol': 'MESH5', 'TradeAccount': 'PP-CASH.......', 'TradeType': 0, 'Type': 10102}

Date Time Of Last Edit: 2025-03-08 11:20:19
[2025-03-09 13:54:54]
Fungraphic72 - Posts: 16
Use this request to get what you need through the DTC protocol server:
Sierra Chart Custom: HISTORICAL_TRADES_REQUEST [s_HistoricalTradesRequest structure] Client >> Server
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, use the Teton service:
Sierra Chart Teton Futures Order Routing

Hello, thank you very much because it works.
But there's still one thing I can't understand.
With this data I still can't calculate the exact PNL that is displayed in my Rithmic dashboard.
There is this kind of data in EntryQuantity/ExitQuantity "4294967294".
Does this represent the partial close of a trade?
Does this make it possible to aggregate partially closed trades?

I have entered the fees in sierra charts for the MESH5.CME (1.54)
I have tried several calculations but I cannot find the exact amount of the PNL.
Can you tell me which method to use?

Thanks in advance
Date Time Of Last Edit: 2025-03-09 13:56:57
imageDatas_DTC_trades.png / V - Attached On 2025-03-09 13:54:45 UTC - Size: 98.2 KB - 23 views
[2025-03-09 14:24:21]
User431178 - Posts: 647

There is this kind of data in EntryQuantity/ExitQuantity "4294967294".

Maybe somewhere there is a type conversion error?

4294967294 unsigned int => -2 signed int
[2025-03-09 14:54:54]
Fungraphic72 - Posts: 16
ok, but that doesn't solve my PNL calculation problem :)


Thanks anyway.
Date Time Of Last Edit: 2025-03-09 14:55:17
[2025-03-25 18:03:48]
Fungraphic72 - Posts: 16
My trading journal is finally complete.
Everything works, thanks again for the help.

https://youtu.be/3qp5rsCkDws
[2025-03-25 18:24:17]
seandunaway - Posts: 348
so cool @Fungraphic72!
[2025-03-25 19:48:13]
User431178 - Posts: 647
Yes, very nice.
Interesting project.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account