First of all, I want to thank anyone who contributes to this question. I know everyone’s time is valuable and it means a lot!!
I created python code to do things like generate trades, list position, etc., but I also want to pull ticker data (OHLCV) from Tradovate. I am using the following code, but I get the following error…
“websockets.exceptions.ConnectionClosedOK: received 1000 (OK) Bye; then sent 1000 (OK) Bye”
Here is the code…
import asyncio
import websockets
import json
from config import *
from GetAccessToken import getAccessToken
— Get Access Token
token = getAccessToken(False)[0]
— Define the WebSocket URL for Tradovate’s API
websocket_url = f"wss://md.tradovateapi.com/v1/websocket/{token}"
— Create a message to authenticate with Tradovate
auth_message = {
“action”: “login”,
“data”: {
“appId”: APP_ID,
“appVersion”: “1.0.0”,
“cid”: CID,
“deviceId”: DEVICE_ID,
“sec”: API_SECRET,
“name”: USER_NAME,
“password”: PASSWORD,
},
}
— Create a message to subscribe to quotes for a specific symbol
subscribe_message = {
“action”: “quote”,
“data”: [
{“symbol”: “CLV3”}
],
}
async def connect_and_request_quotes():
async with websockets.connect(websocket_url) as websocket:
# Send the authentication message
await websocket.send(json.dumps(auth_message))
# Wait for the authentication response
auth_response = await websocket.recv()
if "error" in auth_response:
print(f"Authentication Error: {auth_response}")
return # Exit the function or handle the error as needed
print(f"Authentication Response: {auth_response}")
# Send the subscription message
await websocket.send(json.dumps(subscribe_message))
print(f"Subscribe Message Response: {subscribe_message}")
# Continuously receive and print quotes
while True:
quote_response = await websocket.recv()
print(f"Quote: {quote_response}")
if name == “main”: #(name and main are surrounded by “__”)
asyncio.get_event_loop().run_until_complete(connect_and_request_quotes())