37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
import json
|
|
import websocket
|
|
json_payload = {
|
|
"jsonrpc": 2,
|
|
"method": "update_order",
|
|
"params": {
|
|
"order_id": 538001,
|
|
"price": 1641.8,
|
|
"quantity": 2,
|
|
"order_type": "iceberg",
|
|
"custom": {
|
|
"showquanity": 5
|
|
}
|
|
},
|
|
"id": 1
|
|
}
|
|
json_string = json.dumps(json_payload)
|
|
ws_url = "ws://localhost:8080"
|
|
# Define a callback function to handle received messages
|
|
def on_message(ws, message):
|
|
print("Received message: ", message)
|
|
ws.close()
|
|
|
|
# Define a callback function to handle the WebSocket connection opening
|
|
def on_open(ws):
|
|
print("WebSocket connection opened")
|
|
ws.send(json_string)
|
|
|
|
# Define a callback function to handle the WebSocket connection closing
|
|
def on_close(ws):
|
|
print("WebSocket connection closed")
|
|
# Create a WebSocket connection and send the JSON payload
|
|
ws = websocket.WebSocketApp(ws_url, on_message=on_message, on_open=on_open, on_close=on_close)
|
|
|
|
# Start the WebSocket connection and listen for incoming messages
|
|
ws.run_forever()
|
|
input("press any key to continue") |