From 317f17d7dafc062e3df95f30961c5ec990fc6c8d Mon Sep 17 00:00:00 2001 From: Taha Afzal Date: Tue, 21 Mar 2023 12:39:58 -0400 Subject: [PATCH] added examples --- testing/api-sample-scripts/delete_order.py | 24 ++ .../api-sample-scripts/enter_cover_order.py | 24 ++ .../api-sample-scripts/enter_iceberg_order.py | 24 ++ .../api-sample-scripts/enter_limit_order.py | 24 ++ .../api-sample-scripts/sample_generator.ipynb | 303 ++++++++++++++++++ testing/api-sample-scripts/subscribe_books.py | 27 ++ testing/api-sample-scripts/subscribe_fills.py | 27 ++ .../api-sample-scripts/subscribe_orders.py | 27 ++ .../subscribe_price_stats.py | 27 ++ .../subscribe_price_tickets.py | 27 ++ .../subscribe_securities.py | 27 ++ .../api-sample-scripts/subscribe_trades.py | 27 ++ testing/api-sample-scripts/upd_cover_order.py | 24 ++ .../api-sample-scripts/upd_iceberg_order.py | 24 ++ testing/api-sample-scripts/upd_limit_order.py | 24 ++ 15 files changed, 660 insertions(+) create mode 100644 testing/api-sample-scripts/delete_order.py create mode 100644 testing/api-sample-scripts/enter_cover_order.py create mode 100644 testing/api-sample-scripts/enter_iceberg_order.py create mode 100644 testing/api-sample-scripts/enter_limit_order.py create mode 100644 testing/api-sample-scripts/sample_generator.ipynb create mode 100644 testing/api-sample-scripts/subscribe_books.py create mode 100644 testing/api-sample-scripts/subscribe_fills.py create mode 100644 testing/api-sample-scripts/subscribe_orders.py create mode 100644 testing/api-sample-scripts/subscribe_price_stats.py create mode 100644 testing/api-sample-scripts/subscribe_price_tickets.py create mode 100644 testing/api-sample-scripts/subscribe_securities.py create mode 100644 testing/api-sample-scripts/subscribe_trades.py create mode 100644 testing/api-sample-scripts/upd_cover_order.py create mode 100644 testing/api-sample-scripts/upd_iceberg_order.py create mode 100644 testing/api-sample-scripts/upd_limit_order.py diff --git a/testing/api-sample-scripts/delete_order.py b/testing/api-sample-scripts/delete_order.py new file mode 100644 index 000000000..3bea41b96 --- /dev/null +++ b/testing/api-sample-scripts/delete_order.py @@ -0,0 +1,24 @@ +import json +import websocket +json_payload = {'jsonrpc': 2, 'method': 'delete_order', 'params': {'order_id': 541002}, '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") \ No newline at end of file diff --git a/testing/api-sample-scripts/enter_cover_order.py b/testing/api-sample-scripts/enter_cover_order.py new file mode 100644 index 000000000..195a96854 --- /dev/null +++ b/testing/api-sample-scripts/enter_cover_order.py @@ -0,0 +1,24 @@ +import json +import websocket +json_payload = {'price': 1646.8, 'quantity': 1, 'order_type': 'cover', 'side': 'buy', 'account': 'main', 'user': 'bts', 'exchange_securty_name': 'ETH-31MAR23', 'venue': 'deribit', 'custom': {'hedge_ticks': 2, 'cancel_on_external_hedge_cancel': True, 'cancel_hedges_on_cancel': True, 'detach_hedges': False}} +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") \ No newline at end of file diff --git a/testing/api-sample-scripts/enter_iceberg_order.py b/testing/api-sample-scripts/enter_iceberg_order.py new file mode 100644 index 000000000..114b9a896 --- /dev/null +++ b/testing/api-sample-scripts/enter_iceberg_order.py @@ -0,0 +1,24 @@ +import json +import websocket +json_payload = {'price': 1646.8, 'quantity': 1, 'order_type': 'iceberg', 'side': 'buy', 'account': 'main', 'user': 'bts', 'exchange_securty_name': 'ETH-31MAR23', 'venue': 'deribit', 'custom': {'showquanity': 5}} +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") \ No newline at end of file diff --git a/testing/api-sample-scripts/enter_limit_order.py b/testing/api-sample-scripts/enter_limit_order.py new file mode 100644 index 000000000..52a658a4e --- /dev/null +++ b/testing/api-sample-scripts/enter_limit_order.py @@ -0,0 +1,24 @@ +import json +import websocket +json_payload = {'price': 1646.8, 'quantity': 1, 'order_type': 'limit', 'side': 'buy', 'account': 'main', 'user': 'bts', 'exchange_securty_name': 'ETH-31MAR23', 'venue': 'deribit', 'custom': {}} +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") \ No newline at end of file diff --git a/testing/api-sample-scripts/sample_generator.ipynb b/testing/api-sample-scripts/sample_generator.ipynb new file mode 100644 index 000000000..2cdd9badf --- /dev/null +++ b/testing/api-sample-scripts/sample_generator.ipynb @@ -0,0 +1,303 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### installs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%pip install websocket" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Imports" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import websocket" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### data" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##### packets" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "outer = lambda method,params:{\n", + " \"jsonrpc\": 2,\n", + " \"method\": method,\n", + " \"params\": params,\n", + " \"id\": 1\n", + "}\n", + "enter_order_params=lambda type,custom:{\n", + " \"price\":1646.8,\n", + " \"quantity\":1,\n", + " \"order_type\":type,\n", + " \"side\":\"buy\",\n", + " \"account\":\"main\",\n", + " \"user\":\"bts\",\n", + " \"exchange_securty_name\": \"ETH-31MAR23\",\n", + " \"venue\":\"deribit\",\n", + " \"custom\":custom\n", + "}\n", + "upd_order_params=lambda custom,type:{\n", + " \"order_id\":538001,\n", + " \"price\":1641.8,\n", + " \"quantity\":2,\n", + " \"order_type\":type,\n", + " \"custom\":custom\n", + "}\n", + "simple_filter={\n", + " \"symbol\":[\"ETH\"],\n", + " \"expiration\":[\"2023/04/28\"],\n", + " \"venue\":[\"deribit\"],\n", + "}\n", + "order_customs = {\n", + " \"limit\":{},\n", + " \"iceberg\":{\"showquanity\":5},\n", + " \"cover\":{\"hedge_ticks\":2,\"cancel_on_external_hedge_cancel\":True,\"cancel_hedges_on_cancel\":True,\"detach_hedges\":False}\n", + " }\n", + "order_customs_upd = {\n", + " \"limit\":{},\n", + " \"iceberg\":{\"showquanity\":7},\n", + " \"cover\":{\"hedge_ticks\":6,\"cancel_on_external_hedge_cancel\":False,\"cancel_hedges_on_cancel\":True,\"detach_hedges\":False}}\n" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##### code" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "REST_code=lambda payload :f'''import json\n", + "import websocket\n", + "json_string = {json.dumps(payload,indent=4)}\n", + "ws_url = \"ws://localhost:8080\"\n", + "# Define a callback function to handle received messages\n", + "def on_message(ws, message):\n", + " print(\"Received message: \", message)\n", + " ws.close()\n", + "\n", + "# Define a callback function to handle the WebSocket connection opening\n", + "def on_open(ws):\n", + " print(\"WebSocket connection opened\")\n", + " ws.send(json_string)\n", + "\n", + "# Define a callback function to handle the WebSocket connection closing\n", + "def on_close(ws):\n", + " print(\"WebSocket connection closed\")\n", + "# Create a WebSocket connection and send the JSON payload\n", + "ws = websocket.WebSocketApp(ws_url, on_message=on_message, on_open=on_open, on_close=on_close)\n", + "\n", + "# Start the WebSocket connection and listen for incoming messages\n", + "ws.run_forever()\n", + "input(\"press any key to continue\")'''" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "sub_code=lambda payload :f'''import json\n", + "import websocket\n", + "json_string = {json.dumps(payload,indent=4)}\n", + "ws_url = \"ws://localhost:8080\"\n", + "message_count = [0]\n", + "# Define a callback function to handle received messages\n", + "def on_message(ws, message):\n", + " print(\"Received message: \", message)\n", + " if(message_count[0]>0):\n", + " ws.close()\n", + " message_count[0]+=1\n", + "\n", + "# Define a callback function to handle the WebSocket connection opening\n", + "def on_open(ws):\n", + " print(\"WebSocket connection opened\")\n", + " ws.send(json_string)\n", + "\n", + "# Define a callback function to handle the WebSocket connection closing\n", + "def on_close(ws):\n", + " print(\"WebSocket connection closed\")\n", + "# Create a WebSocket connection and send the JSON payload\n", + "ws = websocket.WebSocketApp(ws_url, on_message=on_message, on_open=on_open, on_close=on_close)\n", + "\n", + "# Start the WebSocket connection and listen for incoming messages\n", + "ws.run_forever()\n", + "input(\"press any key to continue\")\n", + "'''" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### file writers" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "def file_writer(name,val):\n", + " with open(name,\"w\") as f:\n", + " f.write(val)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##### subscription" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "get_sub = lambda typ,filter: outer(\"subscribe\",{\"subscription_id\":1,\"type\":typ,\"filter\":filter})\n", + "subscriptions={key:get_sub(key,simple_filter) for key in [\"books\",\"orders\",\"fills\",\"trades\",\"securities\",\"price_stats\",\"price_tickets\"]}\n", + "for key, value in subscriptions.items():\n", + " file_writer(f\"subscribe_{key}.py\",sub_code(value))" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##### order entry" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "get_enter_order = lambda ord_type,params:outer(\"enter_order\",enter_order_params(ord_type,params))\n", + "for key, value in order_customs.items():\n", + " file_writer(f\"enter_{key}_order.py\",REST_code(get_enter_order(key,value)))" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##### update order" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "get_upd_order = lambda ord_type,params:outer(\"update_order\",upd_order_params(ord_type,params))\n", + "for key, value in order_customs.items():\n", + " file_writer(f\"upd_{key}_order.py\",REST_code(get_upd_order(key,value)))" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##### delete order" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "file_writer(\"delete_order.py\",REST_code(outer(\"delete_order\",{\"order_id\":541002})))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.7" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/testing/api-sample-scripts/subscribe_books.py b/testing/api-sample-scripts/subscribe_books.py new file mode 100644 index 000000000..f814403e3 --- /dev/null +++ b/testing/api-sample-scripts/subscribe_books.py @@ -0,0 +1,27 @@ +import json +import websocket +json_payload = {'jsonrpc': 2, 'method': 'subscribe', 'params': {'subscription_id': 1, 'type': 'books', 'filter': {'symbol': ['ETH'], 'expiration': ['2023/04/28'], 'venue': ['deribit']}}, 'id': 1} +json_string = json.dumps(json_payload) +ws_url = "ws://localhost:8080" +message_count = [0] +# Define a callback function to handle received messages +def on_message(ws, message): + print("Received message: ", message) + if(message_count[0]>0): + ws.close() + message_count[0]+=1 + +# 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") diff --git a/testing/api-sample-scripts/subscribe_fills.py b/testing/api-sample-scripts/subscribe_fills.py new file mode 100644 index 000000000..ffa22c5ee --- /dev/null +++ b/testing/api-sample-scripts/subscribe_fills.py @@ -0,0 +1,27 @@ +import json +import websocket +json_payload = {'jsonrpc': 2, 'method': 'subscribe', 'params': {'subscription_id': 1, 'type': 'fills', 'filter': {'symbol': ['ETH'], 'expiration': ['2023/04/28'], 'venue': ['deribit']}}, 'id': 1} +json_string = json.dumps(json_payload) +ws_url = "ws://localhost:8080" +message_count = [0] +# Define a callback function to handle received messages +def on_message(ws, message): + print("Received message: ", message) + if(message_count[0]>0): + ws.close() + message_count[0]+=1 + +# 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") diff --git a/testing/api-sample-scripts/subscribe_orders.py b/testing/api-sample-scripts/subscribe_orders.py new file mode 100644 index 000000000..d968a332e --- /dev/null +++ b/testing/api-sample-scripts/subscribe_orders.py @@ -0,0 +1,27 @@ +import json +import websocket +json_payload = {'jsonrpc': 2, 'method': 'subscribe', 'params': {'subscription_id': 1, 'type': 'orders', 'filter': {'symbol': ['ETH'], 'expiration': ['2023/04/28'], 'venue': ['deribit']}}, 'id': 1} +json_string = json.dumps(json_payload) +ws_url = "ws://localhost:8080" +message_count = [0] +# Define a callback function to handle received messages +def on_message(ws, message): + print("Received message: ", message) + if(message_count[0]>0): + ws.close() + message_count[0]+=1 + +# 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") diff --git a/testing/api-sample-scripts/subscribe_price_stats.py b/testing/api-sample-scripts/subscribe_price_stats.py new file mode 100644 index 000000000..230738e09 --- /dev/null +++ b/testing/api-sample-scripts/subscribe_price_stats.py @@ -0,0 +1,27 @@ +import json +import websocket +json_payload = {'jsonrpc': 2, 'method': 'subscribe', 'params': {'subscription_id': 1, 'type': 'price_stats', 'filter': {'symbol': ['ETH'], 'expiration': ['2023/04/28'], 'venue': ['deribit']}}, 'id': 1} +json_string = json.dumps(json_payload) +ws_url = "ws://localhost:8080" +message_count = [0] +# Define a callback function to handle received messages +def on_message(ws, message): + print("Received message: ", message) + if(message_count[0]>0): + ws.close() + message_count[0]+=1 + +# 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") diff --git a/testing/api-sample-scripts/subscribe_price_tickets.py b/testing/api-sample-scripts/subscribe_price_tickets.py new file mode 100644 index 000000000..225d88fe5 --- /dev/null +++ b/testing/api-sample-scripts/subscribe_price_tickets.py @@ -0,0 +1,27 @@ +import json +import websocket +json_payload = {'jsonrpc': 2, 'method': 'subscribe', 'params': {'subscription_id': 1, 'type': 'price_tickets', 'filter': {'symbol': ['ETH'], 'expiration': ['2023/04/28'], 'venue': ['deribit']}}, 'id': 1} +json_string = json.dumps(json_payload) +ws_url = "ws://localhost:8080" +message_count = [0] +# Define a callback function to handle received messages +def on_message(ws, message): + print("Received message: ", message) + if(message_count[0]>0): + ws.close() + message_count[0]+=1 + +# 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") diff --git a/testing/api-sample-scripts/subscribe_securities.py b/testing/api-sample-scripts/subscribe_securities.py new file mode 100644 index 000000000..dd0b64167 --- /dev/null +++ b/testing/api-sample-scripts/subscribe_securities.py @@ -0,0 +1,27 @@ +import json +import websocket +json_payload = {'jsonrpc': 2, 'method': 'subscribe', 'params': {'subscription_id': 1, 'type': 'securities', 'filter': {'symbol': ['ETH'], 'expiration': ['2023/04/28'], 'venue': ['deribit']}}, 'id': 1} +json_string = json.dumps(json_payload) +ws_url = "ws://localhost:8080" +message_count = [0] +# Define a callback function to handle received messages +def on_message(ws, message): + print("Received message: ", message) + if(message_count[0]>0): + ws.close() + message_count[0]+=1 + +# 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") diff --git a/testing/api-sample-scripts/subscribe_trades.py b/testing/api-sample-scripts/subscribe_trades.py new file mode 100644 index 000000000..5aa548aae --- /dev/null +++ b/testing/api-sample-scripts/subscribe_trades.py @@ -0,0 +1,27 @@ +import json +import websocket +json_payload = {'jsonrpc': 2, 'method': 'subscribe', 'params': {'subscription_id': 1, 'type': 'trades', 'filter': {'symbol': ['ETH'], 'expiration': ['2023/04/28'], 'venue': ['deribit']}}, 'id': 1} +json_string = json.dumps(json_payload) +ws_url = "ws://localhost:8080" +message_count = [0] +# Define a callback function to handle received messages +def on_message(ws, message): + print("Received message: ", message) + if(message_count[0]>0): + ws.close() + message_count[0]+=1 + +# 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") diff --git a/testing/api-sample-scripts/upd_cover_order.py b/testing/api-sample-scripts/upd_cover_order.py new file mode 100644 index 000000000..a0d5ca130 --- /dev/null +++ b/testing/api-sample-scripts/upd_cover_order.py @@ -0,0 +1,24 @@ +import json +import websocket +json_payload = {'jsonrpc': 2, 'method': 'update_order', 'params': {'order_id': 538001, 'price': 1641.8, 'quantity': 2, 'order_type': {'hedge_ticks': 2, 'cancel_on_external_hedge_cancel': True, 'cancel_hedges_on_cancel': True, 'detach_hedges': False}, 'custom': 'cover'}, '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") \ No newline at end of file diff --git a/testing/api-sample-scripts/upd_iceberg_order.py b/testing/api-sample-scripts/upd_iceberg_order.py new file mode 100644 index 000000000..9a0cab402 --- /dev/null +++ b/testing/api-sample-scripts/upd_iceberg_order.py @@ -0,0 +1,24 @@ +import json +import websocket +json_payload = {'jsonrpc': 2, 'method': 'update_order', 'params': {'order_id': 538001, 'price': 1641.8, 'quantity': 2, 'order_type': {'showquanity': 5}, 'custom': 'iceberg'}, '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") \ No newline at end of file diff --git a/testing/api-sample-scripts/upd_limit_order.py b/testing/api-sample-scripts/upd_limit_order.py new file mode 100644 index 000000000..5cb505ba0 --- /dev/null +++ b/testing/api-sample-scripts/upd_limit_order.py @@ -0,0 +1,24 @@ +import json +import websocket +json_payload = {'jsonrpc': 2, 'method': 'update_order', 'params': {'order_id': 538001, 'price': 1641.8, 'quantity': 2, 'order_type': {}, 'custom': 'limit'}, '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") \ No newline at end of file