names wkng in subs, examples working

This commit is contained in:
arhamGIT authored and Taha Afzal committed 2023-03-27 11:40:51 -05:00
1 parent ce9880a9b1
commit bb321926bc
21 files changed
+163 -71

No files matched your search

@@ -18,18 +18,13 @@
"output_type": "stream",
"text": [
"Defaulting to user installation because normal site-packages is not writeable\n",
"Requirement already satisfied: websocket in /home/arham/.local/lib/python3.10/site-packages (0.2.1)\n",
"Requirement already satisfied: greenlet in /home/arham/.local/lib/python3.10/site-packages (from websocket) (2.0.2)\n",
"Requirement already satisfied: gevent in /home/arham/.local/lib/python3.10/site-packages (from websocket) (22.10.2)\n",
"Requirement already satisfied: zope.event in /home/arham/.local/lib/python3.10/site-packages (from gevent->websocket) (4.6)\n",
"Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from gevent->websocket) (59.6.0)\n",
"Requirement already satisfied: zope.interface in /home/arham/.local/lib/python3.10/site-packages (from gevent->websocket) (6.0)\n",
"Requirement already satisfied: websocket-client in /home/arham/.local/lib/python3.10/site-packages (1.5.1)\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install websocket"
"%pip install websocket-client"
]
},
{
@@ -42,7 +37,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
@@ -68,7 +63,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 40,
"metadata": {},
"outputs": [],
"source": [
@@ -89,7 +84,7 @@
" \"venue\":\"deribit\",\n",
" \"custom\":custom\n",
"}\n",
"upd_order_params=lambda custom,type:{\n",
"upd_order_params=lambda type,custom:{\n",
" \"order_id\":538001,\n",
" \"price\":1641.8,\n",
" \"quantity\":2,\n",
@@ -99,7 +94,7 @@
"simple_filter={\n",
" \"symbol\":[\"ETH\"],\n",
" \"expiration\":[\"2023/04/28\"],\n",
" \"venue\":[\"deribit\"],\n",
" \"venue\":[\"deribit\"]\n",
"}\n",
"order_customs = {\n",
" \"limit\":{},\n",
@@ -122,13 +117,14 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
"REST_code=lambda payload :f'''import json\n",
"import websocket\n",
"json_string = {json.dumps(payload,indent=4)}\n",
"json_payload = {json.dumps(payload,indent=4)}\n",
"json_string = json.dumps(json_payload)\n",
"ws_url = \"ws://localhost:8080\"\n",
"# Define a callback function to handle received messages\n",
"def on_message(ws, message):\n",
@@ -153,13 +149,14 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
"sub_code=lambda payload :f'''import json\n",
"import websocket\n",
"json_string = {json.dumps(payload,indent=4)}\n",
"json_payload = {json.dumps(payload,indent=4)}\n",
"json_string = json.dumps(json_payload)\n",
"ws_url = \"ws://localhost:8080\"\n",
"message_count = [0]\n",
"# Define a callback function to handle received messages\n",
@@ -196,7 +193,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
@@ -215,12 +212,12 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 44,
"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",
"subscriptions={key:get_sub(key,simple_filter) for key in [\"books\",\"orders\",\"fills\",\"trades\",\"securities\",\"price_stats\",\"price_tickers\"]}\n",
"for key, value in subscriptions.items():\n",
" file_writer(f\"subscribe_{key}.py\",sub_code(value))"
]
@@ -235,7 +232,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
@@ -254,7 +251,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 46,
"metadata": {},
"outputs": [],
"source": [
@@ -273,7 +270,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 47,
"metadata": {},
"outputs": [],
"source": [
@@ -285,6 +282,32 @@
"metadata": {},
"source": []
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Run Examples"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"WebSocket connection opened\n",
"Received message: {\"jsonrpc\":2.0,\"id\":\"1\",\"status\":\"1\",\"result\":{\"subscription_id\":\"1\"}}\n"
]
}
],
"source": [
"%run subscribe_price_stats.py"
]
},
{
"cell_type": "code",
"execution_count": null,