Login Page - Create Account

Support Board


Date/Time: Sun, 24 Nov 2024 21:45:07 +0000



Post From: [SC Relay Server] Documentation Needed

[2024-05-02 17:52:55]
MichaelPPTF - Posts: 69
and the code related to handling LOGON_REQUEST:

Thank you for the code.

So, I guess my next question will be:

In order to facilitate data streaming, what needs to happen first and in what order?

Update: I've gotten this far so SC will Acknowledge my client.

import socket
import json
import threading
import time

def create_logon_request():
logon_request = {
"Type": 1, # Assuming Type 1 is for LOGON_REQUEST
"ProtocolVersion": 8,
"HeartbeatIntervalInSeconds": 10,
}
return json.dumps(logon_request).encode('utf-8') + b'\x00'

def create_heartbeat():
heartbeat = {
"Type": 3, # Assuming Type 3 is for HEARTBEAT
}
return json.dumps(heartbeat).encode('utf-8') + b'\x00'

def send_heartbeat(sock):
while True:
try:
sock.send(create_heartbeat())
print("Heartbeat sent.")
except socket.error as e:
print("Socket error:", e)
break
time.sleep(10) # Send heartbeat every 10 seconds

def receive_response(sock):
response = b""
try:
while True:
part = sock.recv(1024)
if part:
response += part
if response.endswith(b'\x00'):
print("Received response:", response.decode('utf-8').strip('\x00'))
response = b"" # Reset the buffer after processing
else:
break
except socket.error as e:
print("Socket error:", e)

def main():
host = '127.0.0.1'
port = 11099
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((host, port))
print("Connected to Sierra Chart Relay Server")

# Send logon request
s.send(create_logon_request())
print("Logon request sent.")

# Start the heartbeat thread
heartbeat_thread = threading.Thread(target=send_heartbeat, args=(s,))
heartbeat_thread.start()

# Handle responses
receive_response(s)

# Wait for the heartbeat thread to finish (if ever)
heartbeat_thread.join()

if __name__ == "__main__":
main()

This is what SC gave me back:


Received response: {
"Type":3,
"NumDroppedMessages":0,
"CurrentDateTime":1714676026,
"SecondsSinceLastReceivedHeartbeat":9,
"NumberOfOutstandingSentBuffers":0,
"PendingTransmissionDelayInMilliseconds":0,
"CurrentSendBufferSizeInBytes":0,
"SendingDateTimeMicroseconds":1714676026493516,
"DataCompressionRatio":0,
"TotalUncompressedBytes":3016,
"TotalCompressionTime":0,
"NumberOfCompressions":0,
"SourceIPAddress":2130706433,
"MaximumSendBufferSizeInBytes":0,
"MaximumSendBufferSizeInBytesDateTime":0
}

How do I start to get data from it? The doc said I can't send a MARKET_DATA_REQUEST to SC, so how would I get what is being relayed? For example, I have a real time quote board with AAPL and MSFT on it. How can I stream the data from SC Relay Server?
Date Time Of Last Edit: 2024-05-02 18:59:21