Login Page - Create Account

Support Board


Date/Time: Thu, 25 Apr 2024 19:19:16 +0000



Connecting to DTC with javascript websockets

View Count: 1205

[2021-11-29 05:27:27]
KylieV1618 - Posts: 58
Hi,

Is there a tutorial available for how to connect to DTC with javascript websockets??

I can't find any relevant info for how to do that?
Like how do I send the authentication/logon request??

Also....when I do a netstat, I dont see any TCP server running at port 11099 even though it says "Yes" for enabled in the DTC settings?
Is there something special I need to do to turn it on?

Thanks
Kylie
[2021-11-29 15:50:03]
Sierra Chart Engineering - Posts: 104368
Did you want to use JSON encoding? Are you at least able to establish the TCP/IP connection to that port? Are you connecting from a web browser?

Make sure that port is not used by another instance of Sierra Chart or another program. Or try changing the port in Global Settings >> Sierra Chart Server Settings >> DTC Protocol 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, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2021-11-29 16:53:58]
KylieV1618 - Posts: 58
Yeah I want to use JSON encoding.
I cant establish a connection to the port it doesnt seem :(
It shows open in netstat though. when I do netstat -a

But....

ws://127.0.0.0.1:11099 and ws://0.0.0.0:110999. both dont work?? Is there another way to connect that I should try?
Or maybe I have to send the connect/logon request??

How do I do that with websockets? Like what is the format? (JSON?)
Yes Ill be connecting from a webbrowser


EDIT: I did also download a Python version of a DTC implementation.
https://github.com/jseparovic/python-ws-dtc-client
ANd that seems to be able to connect to the port just fine. The websockets however, also dont work in that implementation either though :(
The REST api they programmed does though.

But yeah, the websockets dont. But thats probably a different issue, since their websockets go through the API server they setup.
I posted an Issue on their Github about it
https://github.com/jseparovic/python-ws-dtc-client/issues/2
Date Time Of Last Edit: 2021-11-29 17:56:22
[2021-11-29 20:50:17]
KylieV1618 - Posts: 58
Ok, I downloaded a binary encoding/decoding library for javascript. And it seems I can connect to the websockets.
ut Im not sure if Im encoding correctly.

The error I get on LOGON_REQUEST is


WSServer | DTC client #62. 127.0.0.1 (2) | Response HANDSHAKE with status code 101 | 2021-11-29 12:48:50.209
JSON data:
DTC_CLIENT | 2021-11-29 12:48:50.244
DTC JSON message: Missing 'Type' field. Ignoring message. | 2021-11-29 12:48:50.244 *
JSON data: | 2021-11-29 12:48:50.244
JSON data: | 2021-11-29 12:48:50.244
JSON data: x | 2021-11-29 12:48:50.244
DTC JSON message: Missing 'Type' field. Ignoring message. | 2021-11-29 12:48:50.244 *
JSON data: | 2021-11-29 12:48:50.244
JSON data: | 2021-11-29 12:48:50.244
JSON data:  | 2021-11-29 12:48:50.244
DTC JSON message: Missing 'Type' field. Ignoring message. | 2021-11-29 12:48:50.244 *
JSON data:  | 2021-11-29 12:48:50.244
DTC JSON message: Missing 'Type' field. Ignoring message. | 2021-11-29 12:48:50.244 *
JSON data:  | 2021-11-29 12:48:50.244





This is my current code.

Not really sure what to put in Size



var sp = require('../../schemapack/schemapack.js');


var logonSchema = sp.build({
Size: 'uint16',
Type: 'uint16',
ProtocolVersion: 'int32',
HeartbeatIntervalInSeconds: 'int32',
ClientName: 'string'
});

var logon = {
Size: 23,
Type: 1,
ProtocolVersion: 8,
HeartbeatIntervalInSeconds: 120,
ClientName: "DTC_CLIENT"
};

var buffer = logonSchema.encode(logon);

let socket = new WebSocket('ws://127.0.0.1:11099');
socket.onopen = function(e) {
console.log(buffer);
socket.send(buffer.buffer);
};


Do I need to be appending extra bytes somewhere, that will not be part of this encoding/decoding library?
Date Time Of Last Edit: 2021-11-30 01:11:36
[2021-11-30 01:38:15]
KylieV1618 - Posts: 58
Also.....when I finally do figure out how to connect.

How do I get Market updates, on replay data?

Im trying to create something similar to priceSquawk. But I want it to be able to work on a market replay as well.

Hopefully somebody can help me get the LOGON_REQUEST working soon :)

Thanks
Kylie
Date Time Of Last Edit: 2021-11-30 01:38:45
[2021-11-30 03:09:37]
KylieV1618 - Posts: 58
Still stumped on this...

I follwed this other thread to try do it via JSON?

New websocket

But I get ..


WSServer | DTC client #129. 127.0.0.1 (1) | Start Server | 2021-11-29 19:07:12.479
WSServer | DTC client #129. 127.0.0.1 (1) | Switch to HANDSHAKE | 2021-11-29 19:07:12.479
WSServer | DTC client #129. 127.0.0.1 (1) | Switch to READY_DATA | 2021-11-29 19:07:12.480
WSServer | DTC client #129. 127.0.0.1 (1) | Response HANDSHAKE with status code 101 | 2021-11-29 19:07:12.480
JSON data: [object Object] | 2021-11-29 19:07:12.502


Then if i JSON.stringify() it,....


WSServer | DTC client #130. 127.0.0.1 (1) | Start Server | 2021-11-29 19:08:37.972
WSServer | DTC client #130. 127.0.0.1 (1) | Switch to HANDSHAKE | 2021-11-29 19:08:37.972
WSServer | DTC client #130. 127.0.0.1 (1) | Switch to READY_DATA | 2021-11-29 19:08:37.972
WSServer | DTC client #130. 127.0.0.1 (1) | Response HANDSHAKE with status code 101 | 2021-11-29 19:08:37.972
JSON data: {"ClientName":"DTC Client","HeartbeatIntervalInSeconds":120,"Password":"xxxx","ProtocolVersion":6,"TradeMode":3,"Type":1,"Username":"xxxx"} | 2021-11-29 19:08:38.004
DTC client #130. 127.0.0.1 | No activity on network socket. Closing network socket. Bytes in receive buffer: 0 | 2021-11-29 19:08:57.954
DTC client #130. 127.0.0.1 (1) | CloseSocket call. | 2021-11-29 19:08:57.954
DTC client #130. 127.0.0.1 (1) | Shutdown started. Waiting for graceful close. | 2021-11-29 19:08:57.954




How the hell do I connect to DTC!!??? This is super frustrating. It should be easy

In my settings Ive set the encoding to be JSON. Not automatic.
Thought that might help but it didn't.

Ive tried binary, Ive tried JSON. How do I do this!?

Am I talking to myself here?
Date Time Of Last Edit: 2021-11-30 03:11:29
[2021-11-30 09:29:56]
Sierra Chart Engineering - Posts: 104368
Start with JSON encoding and use this to logon:
{"Type":1, "ProtocolVersion":8,"HeartbeatIntervalInSeconds":20,"ClientName":"Client"}

And send a null terminator character after this. Every message must end with that.

In Global Settings >> Sierra Chart Server Settings >> DTC Protocol Server, set the option for Require Authentication to No.
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, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2021-11-30 09:31:44
[2021-11-30 19:40:31]
KylieV1618 - Posts: 58
Can you show me an example of a null terminator and how to send it??

Do I just attach it to end of the string? or as a seperate message?

Seems like its supposed to not even be allowed??

https://stackoverflow.com/questions/43969649/null-character-within-json
Date Time Of Last Edit: 2021-11-30 20:03:03
[2021-11-30 21:13:43]
KylieV1618 - Posts: 58
Ok I figured it out.

My logon works


let logon = {
Type: 1,
ProtocolVersion: 8,
HeartbeatIntervalInSeconds: 120,
ClientName: "DTC_CLIENT"
};

socket.send(JSON.stringify(logon)+"\0")

BUT...

Doesn't seem my logoff does anything though??
Doesn't close the connection or anything.


let logoff = {
Type: 5,
Reason: "Logoff button hit",
DoNotReconnect:1
};
socket.send(JSON.stringify(logoff)+"\0")

Doesnt seem to do anything.
This is the exact same setup I have for the logon. So I know the null terminator works.
Date Time Of Last Edit: 2021-11-30 21:47:38
[2021-11-30 21:49:48]
KylieV1618 - Posts: 58
Ok, I got the major parts of what I wanted to do working :) (Except for logging off / closing the connection, which isn't too important since the lack of heartbeat will do it anyways)

But now...

I just want the same functionality, but with REPLAY data.
Like I want to be able to run a replay, and have the plugin Im programming function the exact same.

Please let me know how I can subscribe to replay data.

Is it

HISTORICAL_PRICE_DATA_REQUEST ??

and if so....


Logging in to the Historical server at 11098 doesnt seem to work


WSServer | HD Server | Thread:2700 (2) | Switch to HANDSHAKE | 2021-11-30 13:59:17.329
WSServer | HD Server | Thread:2700 (2) | Switch to READY_DATA | 2021-11-30 13:59:17.329
WSServer | HD Server | Thread:2700 (2) | Response HANDSHAKE with status code 101 | 2021-11-30 13:59:17.329
HD Server | Timed out waiting for logon request. | Thread:2700 | 2021-11-30 13:59:28.335
HD Server | Thread:2700 (2) | CloseSocket call. | 2021-11-30 13:59:28.335


It doesn't seem to process my logon request.
Do I have to send it differently than the 11099 request??

But also...reading the documentation....it doesn't appear that what I want is available.

Id have to download the tick data and replay it within my Client. But I want it to be synced to whatever replay I am doing in Sierra Chart. It doesn't look like this is possible correct???
Date Time Of Last Edit: 2021-11-30 22:15:04
[2021-11-30 22:29:47]
Sierra Chart Engineering - Posts: 104368
There is replay functionality:
Sierra Chart Custom: REPLAY_CHART_DATA [s_ReplayChartData structure] Client >> Server

This can be used on the standard port and not the historical data port. There is no synchronization to a Sierra Chart chart replay.
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, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2021-11-30 22:30:20
[2021-12-02 02:28:34]
KylieV1618 - Posts: 58
Yeah hmmm...

so Im not going to be able to run this tool in replay mode then I guess.

Im programming something similar to Price Squawk.
And was hoping I could use it in Replay mode as well, since Price Squawk only functions live.

But this is probably the same reason their software only works live as well, correct??

Would you ever think of adding functionality to output a market depth replay as a stream over websockets?? (similar to how live functions?)
[2021-12-06 08:10:26]
Sierra Chart Engineering - Posts: 104368
You cannot access the chart replay data through the DTC protocol server.

Would you ever think of adding functionality to output a market depth replay as a stream over websockets?? (similar to how live functions?)
No this is not going to come.
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, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2022-11-02 16:30:59]
User735389 - Posts: 188
@kyle did u get it all working? Do you have a repository to share?

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

Login

Login Page - Create Account