From bb321926bcef5ac7cde4a71b5c69d95d526bc254 Mon Sep 17 00:00:00 2001 From: arhamGIT <59977509+arhamGIT@users.noreply.github.com> Date: Fri, 24 Mar 2023 07:37:18 -0400 Subject: [PATCH] names wkng in subs, examples working --- .../spark_api/data/SecurityCriteriaClause.cs | 17 +++-- .../data/SecurityCriteriaExtensions.cs | 70 ++++++++++++++----- .../spark_api/data/SecurityCriterionTypes.cs | 3 +- .../spark_websocket/Core/WebsocketDataSync.cs | 3 +- .../Core/WebsocketJsonParsers.cs | 6 ++ .../Core/WebsocketSubscriptionHandler.cs | 10 ++- testing/api-sample-scripts/delete_order.py | 3 +- .../api-sample-scripts/enter_cover_order.py | 3 +- .../api-sample-scripts/enter_iceberg_order.py | 3 +- .../api-sample-scripts/enter_limit_order.py | 3 +- .../api-sample-scripts/sample_generator.ipynb | 65 +++++++++++------ testing/api-sample-scripts/subscribe_books.py | 3 +- testing/api-sample-scripts/subscribe_fills.py | 3 +- .../api-sample-scripts/subscribe_orders.py | 3 +- .../subscribe_price_stats.py | 3 +- ..._tickets.py => subscribe_price_tickers.py} | 5 +- .../subscribe_securities.py | 3 +- .../api-sample-scripts/subscribe_trades.py | 3 +- testing/api-sample-scripts/upd_cover_order.py | 9 +-- .../api-sample-scripts/upd_iceberg_order.py | 9 +-- testing/api-sample-scripts/upd_limit_order.py | 7 +- 21 files changed, 163 insertions(+), 71 deletions(-) rename testing/api-sample-scripts/{subscribe_price_tickets.py => subscribe_price_tickers.py} (92%) diff --git a/src/client/spark_api/data/SecurityCriteriaClause.cs b/src/client/spark_api/data/SecurityCriteriaClause.cs index 5fe1a7284..d0ded2021 100644 --- a/src/client/spark_api/data/SecurityCriteriaClause.cs +++ b/src/client/spark_api/data/SecurityCriteriaClause.cs @@ -21,7 +21,8 @@ namespace mbts.spark { uint[]? security_keys = null, string? pretty_name = null, double[]? strikes = null, - PutOrCall[]? callputs = null + PutOrCall[]? callputs = null, + string[]? names= null ) { this.exchanges = exchanges; this.security_types = security_types; @@ -31,6 +32,7 @@ namespace mbts.spark { this.pretty_name = pretty_name; this.strikes = strikes; this.callputs = callputs; + this.names=names; } public static SecurityCriteriaClause from_securities( @@ -80,6 +82,9 @@ namespace mbts.spark { [ProtoMember(7)] public PutOrCall[]? callputs { get; } + [ProtoMember(8)] + public string[]? names { get; } + public bool is_defined => !string.IsNullOrEmpty(pretty_name) || !exchanges.is_null_or_empty() || @@ -88,7 +93,8 @@ namespace mbts.spark { !expirations.is_null_or_empty() || !strikes.is_null_or_empty() || !callputs.is_null_or_empty() || - !security_keys.is_null_or_empty(); + !security_keys.is_null_or_empty() || + !names.is_null_or_empty(); public override string ToString() => pretty_name ?? string.Empty; @@ -100,7 +106,8 @@ namespace mbts.spark { expirations.safe_sequence_equals(other.expirations) && strikes.safe_sequence_equals(other.strikes) && callputs.safe_sequence_equals(other.callputs) && - security_keys.safe_sequence_equals(other.security_keys); + security_keys.safe_sequence_equals(other.security_keys) && + names.safe_sequence_equals(other.names); public override bool Equals(object? obj) => obj is SecurityCriteriaClause other && Equals(other); @@ -114,6 +121,7 @@ namespace mbts.spark { .with_values(strikes.empty_if_null()) .with_values(callputs.empty_if_null()) .with_values(security_keys.empty_if_null()) + .with_values(names.empty_if_null()) .ToHashCode(); public SecurityCriteriaClause Clone() => @@ -125,7 +133,8 @@ namespace mbts.spark { security_keys?.ToArray(), pretty_name?.ToString(), strikes?.ToArray(), - callputs?.ToArray()); + callputs?.ToArray(), + names?.ToArray()); object ICloneable.Clone() => Clone(); diff --git a/src/client/spark_api/data/SecurityCriteriaExtensions.cs b/src/client/spark_api/data/SecurityCriteriaExtensions.cs index 9ca9b8fe4..dc21d02ab 100644 --- a/src/client/spark_api/data/SecurityCriteriaExtensions.cs +++ b/src/client/spark_api/data/SecurityCriteriaExtensions.cs @@ -97,6 +97,7 @@ namespace mbts.spark { clause.exchanges.is_null_or_empty() && clause.symbols.is_null_or_empty() && clause.security_types.is_null_or_empty() && + clause.names.is_null_or_empty() && clause.security_keys is not null && !clause.security_keys.Distinct().CountExact(1); @@ -164,6 +165,15 @@ namespace mbts.spark { clause.callputs.Length > 0 && clause.callputs.All(other.callputs.Contains) ) + ) && + // names + ( + other.names is null || + other.names.Length == 0 || ( + clause.names is not null && + clause.names.Length > 0 && + clause.names.All(other.names.Contains) + ) ); public static SecurityCriteriaClause with(this SecurityCriteriaClause clause, @@ -174,7 +184,8 @@ namespace mbts.spark { uint[]? security_keys = null, string? pretty_name = null, double[]? strikes = null, - PutOrCall[]? callputs = null) { + PutOrCall[]? callputs = null, + string[]? names = null) { return new( exchanges ?? clause.exchanges, security_types ?? clause.security_types, @@ -183,7 +194,8 @@ namespace mbts.spark { security_keys ?? clause.security_keys, pretty_name ?? clause.pretty_name, strikes ?? clause.strikes, - callputs ?? clause.callputs); + callputs ?? clause.callputs, + names ?? clause.names); } public static IEnumerable fmt_diagnostic_msgs(this SecurityCriteriaClause clause) { @@ -205,6 +217,9 @@ namespace mbts.spark { if (clause.callputs is not null && clause.callputs.Length > 0) { yield return "Callputs: " + string.Join(", ", clause.callputs); } + if (clause.names is not null && clause.names.Length > 0) { + yield return "Names: " + string.Join(", ", clause.names); + } } public static string fmt_pretty( @@ -216,7 +231,8 @@ namespace mbts.spark { SecurityCriterionTypes.Symbol | SecurityCriterionTypes.SecurityType | SecurityCriterionTypes.Expiration | - SecurityCriterionTypes.Exchange, + SecurityCriterionTypes.Exchange | + SecurityCriterionTypes.Name, fmt_sec); public static string fmt_pretty( @@ -248,7 +264,7 @@ namespace mbts.spark { sb.Append(string.Join( delimiter, clause.security_types.empty_if_null())); } - + if (criterion_types.HasFlag(SecurityCriterionTypes.Expiration)) { if (sb.Length > 0) { sb.Append(' '); @@ -286,6 +302,9 @@ namespace mbts.spark { } sb.Append(string.Join(delimiter, clause.exchanges.empty_if_null())); } + if (criterion_types.HasFlag(SecurityCriterionTypes.Name)) { + sb.Append(string.Join(delimiter, clause.names.empty_if_null())); + } return sb.ToString().TrimEnd(); } @@ -313,6 +332,9 @@ namespace mbts.spark { if (!clause.security_keys.is_null_or_empty()) { result |= SecurityCriterionTypes.Security; } + if (!clause.names.is_null_or_empty()) { + result |= SecurityCriterionTypes.Name; + } return result; } @@ -361,15 +383,16 @@ namespace mbts.spark { public static bts.api.domain.SecurityCriteriaClause to_clause( this SecurityCriteriaClause clause) { - var api_clause = new bts.api.domain.SecurityCriteriaClause(); - api_clause.Exchanges.AddRange( - clause.exchanges.empty_if_null().Select(e => e.to_api_venue())); - api_clause.Symbols.AddRange(clause.symbols.empty_if_null()); - api_clause.Keys.AddRange(clause.security_keys.empty_if_null()); - api_clause.SecurityTypes.AddRange( - clause.security_types.empty_if_null().Select(t => t.to_api_security_type())); - return api_clause; - } + var api_clause = new bts.api.domain.SecurityCriteriaClause(); + api_clause.Exchanges.AddRange( + clause.exchanges.empty_if_null().Select(e => e.to_api_venue())); + api_clause.Symbols.AddRange(clause.symbols.empty_if_null()); + api_clause.Keys.AddRange(clause.security_keys.empty_if_null()); + api_clause.SecurityTypes.AddRange( + clause.security_types.empty_if_null().Select(t => t.to_api_security_type())); + api_clause.Names.AddRange(clause.names.empty_if_null()); + return api_clause; + } public static SecurityCriteriaClause to_clause( this bts.api.domain.SecurityCriteriaClause api_clause) => @@ -377,25 +400,31 @@ namespace mbts.spark { public static SecurityCriteriaClause to_clause( this bts.api.domain.SecurityCriteriaClause api_clause, Func? try_resolve) { - if (try_resolve is not null) { - api_clause.resolve_names(try_resolve); - } return new( api_clause.Exchanges.WrapSelectorRO(v => v.to_venue()).ToArray(), api_clause.SecurityTypes.WrapSelectorRO(t => t.to_security_type()).ToArray(), api_clause.Symbols.ToArray(), null, - api_clause.Keys.ToArray()); + api_clause.Keys.ToArray(), + null, + null, + null, + api_clause.Names.ToArray()); } public static SecurityCriteriaClause to_clause( this bts.api.domain.SecurityCriteriaClauseImmutable api_clause) => - new( + new SecurityCriteriaClause( api_clause.Exchanges.Select(v => v.to_venue()).ToArray(), api_clause.SecurityTypes.Select(t => t.to_security_type()).ToArray(), api_clause.Symbols.ToArray(), null, - api_clause.Keys.ToArray()); + api_clause.Keys.ToArray(), + null, + null, + null, + api_clause.Names.ToArray() + ); public static bts.api.domain.SecurityCriteria to_criteria(this SecurityCriteria criteria) { var api_criteria = new bts.api.domain.SecurityCriteria(); @@ -437,6 +466,9 @@ namespace mbts.spark { if (!clause.callputs.is_null_or_empty()) { yield return sec => sec.HasOption && clause.callputs.Contains(sec.Option.CallPut); } + if (!clause.names.is_null_or_empty()) { + yield return sec => clause.names.Contains(sec.ToString()); + } } } } diff --git a/src/client/spark_api/data/SecurityCriterionTypes.cs b/src/client/spark_api/data/SecurityCriterionTypes.cs index 899673683..fb614e2b2 100644 --- a/src/client/spark_api/data/SecurityCriterionTypes.cs +++ b/src/client/spark_api/data/SecurityCriterionTypes.cs @@ -10,6 +10,7 @@ namespace mbts.spark { Symbol = 1 << 3, SecurityType = 1 << 4, Exchange = 1 << 5, - Expiration = 1 << 6 + Expiration = 1 << 6, + Name = 1 << 7 } } diff --git a/src/client/spark_websocket/Core/WebsocketDataSync.cs b/src/client/spark_websocket/Core/WebsocketDataSync.cs index 3c5ac0942..6b4fc0aea 100644 --- a/src/client/spark_websocket/Core/WebsocketDataSync.cs +++ b/src/client/spark_websocket/Core/WebsocketDataSync.cs @@ -306,8 +306,9 @@ namespace bts.websocket_core { } if (Clients.ContainsKey(req.client_id) && Clients[req.client_id].ContainsKey(hdlr.ID)) { handle_incorrect_request(req, "subscription id already in use"); + return; } - handle_correct_request(req.id, status, hdlr.ID, req.client_id); + handle_correct_request(req.id, status, new { subscription_id = hdlr.ID.ID }, req.client_id); hdlr.subscribe(); Clients[req.client_id] = Clients[req.client_id].Add(hdlr.ID, hdlr); } diff --git a/src/client/spark_websocket/Core/WebsocketJsonParsers.cs b/src/client/spark_websocket/Core/WebsocketJsonParsers.cs index 6857bfd46..ed8842893 100644 --- a/src/client/spark_websocket/Core/WebsocketJsonParsers.cs +++ b/src/client/spark_websocket/Core/WebsocketJsonParsers.cs @@ -43,6 +43,12 @@ namespace bts.websocket_core { public string[] getarr() { return Lis.ToArray(); } + public string[] getuprarr() { + return Lis.Select(v => v.ToUpper()).ToArray(); + } + public string[] getlwrarr() { + return Lis.Select(v => v.ToLower()).ToArray(); + } public static bool TryParse(string input, [NotNullWhen(true)] out ListWrapper? l) { l = null; try { diff --git a/src/client/spark_websocket/Core/WebsocketSubscriptionHandler.cs b/src/client/spark_websocket/Core/WebsocketSubscriptionHandler.cs index e55773abb..ce001ccb6 100644 --- a/src/client/spark_websocket/Core/WebsocketSubscriptionHandler.cs +++ b/src/client/spark_websocket/Core/WebsocketSubscriptionHandler.cs @@ -162,6 +162,7 @@ namespace bts.websocket_core { statuses); return true; } + static bool TryGetFilter(WebsocketRequest req, [NotNullWhen(true)] out SecurityCriteria? cri, out string message) { cri = null; JObject? filter = req.parameters?["filter"] as JObject; @@ -190,6 +191,10 @@ namespace bts.websocket_core { if (!WebsocketJsonParsers.TryParse(filter, "symbol", out symbols, out message)) { return false; } + WebsocketJsonParsers.ListWrapper? names; + if (!WebsocketJsonParsers.TryParse(filter, "name", out names, out message)) { + return false; + } // filter.GetValueOrDefault("symbol")?.ToString()?.Split(","); double[]? strikes; if (!WebsocketJsonParsers.TryParse(filter, "strikes", out strikes, out message)) { @@ -198,12 +203,13 @@ namespace bts.websocket_core { var clause = new SecurityCriteriaClause( exchanges, types, - symbols?.getarr(), + symbols?.getuprarr(), expiration, null, null, strikes, - callputs + callputs, + names?.getuprarr() ); var cls = new List { clause }; cri = new SecurityCriteria(cls); diff --git a/testing/api-sample-scripts/delete_order.py b/testing/api-sample-scripts/delete_order.py index e28a04a9e..5c78f6271 100644 --- a/testing/api-sample-scripts/delete_order.py +++ b/testing/api-sample-scripts/delete_order.py @@ -1,6 +1,6 @@ import json import websocket -json_string = { +json_payload = { "jsonrpc": 2, "method": "delete_order", "params": { @@ -8,6 +8,7 @@ json_string = { }, "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): diff --git a/testing/api-sample-scripts/enter_cover_order.py b/testing/api-sample-scripts/enter_cover_order.py index 44bd93867..3a947fb6f 100644 --- a/testing/api-sample-scripts/enter_cover_order.py +++ b/testing/api-sample-scripts/enter_cover_order.py @@ -1,6 +1,6 @@ import json import websocket -json_string = { +json_payload = { "jsonrpc": 2, "method": "enter_order", "params": { @@ -21,6 +21,7 @@ json_string = { }, "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): diff --git a/testing/api-sample-scripts/enter_iceberg_order.py b/testing/api-sample-scripts/enter_iceberg_order.py index aac6d5c3b..17e554ba7 100644 --- a/testing/api-sample-scripts/enter_iceberg_order.py +++ b/testing/api-sample-scripts/enter_iceberg_order.py @@ -1,6 +1,6 @@ import json import websocket -json_string = { +json_payload = { "jsonrpc": 2, "method": "enter_order", "params": { @@ -18,6 +18,7 @@ json_string = { }, "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): diff --git a/testing/api-sample-scripts/enter_limit_order.py b/testing/api-sample-scripts/enter_limit_order.py index 4c2322dd4..10f9b9743 100644 --- a/testing/api-sample-scripts/enter_limit_order.py +++ b/testing/api-sample-scripts/enter_limit_order.py @@ -1,6 +1,6 @@ import json import websocket -json_string = { +json_payload = { "jsonrpc": 2, "method": "enter_order", "params": { @@ -16,6 +16,7 @@ json_string = { }, "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): diff --git a/testing/api-sample-scripts/sample_generator.ipynb b/testing/api-sample-scripts/sample_generator.ipynb index c73078fcd..a0caf14f2 100644 --- a/testing/api-sample-scripts/sample_generator.ipynb +++ b/testing/api-sample-scripts/sample_generator.ipynb @@ -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, diff --git a/testing/api-sample-scripts/subscribe_books.py b/testing/api-sample-scripts/subscribe_books.py index 40ddee075..94ace8a6c 100644 --- a/testing/api-sample-scripts/subscribe_books.py +++ b/testing/api-sample-scripts/subscribe_books.py @@ -1,6 +1,6 @@ import json import websocket -json_string = { +json_payload = { "jsonrpc": 2, "method": "subscribe", "params": { @@ -20,6 +20,7 @@ json_string = { }, "id": 1 } +json_string = json.dumps(json_payload) ws_url = "ws://localhost:8080" message_count = [0] # Define a callback function to handle received messages diff --git a/testing/api-sample-scripts/subscribe_fills.py b/testing/api-sample-scripts/subscribe_fills.py index eefa64766..b4883585b 100644 --- a/testing/api-sample-scripts/subscribe_fills.py +++ b/testing/api-sample-scripts/subscribe_fills.py @@ -1,6 +1,6 @@ import json import websocket -json_string = { +json_payload = { "jsonrpc": 2, "method": "subscribe", "params": { @@ -20,6 +20,7 @@ json_string = { }, "id": 1 } +json_string = json.dumps(json_payload) ws_url = "ws://localhost:8080" message_count = [0] # Define a callback function to handle received messages diff --git a/testing/api-sample-scripts/subscribe_orders.py b/testing/api-sample-scripts/subscribe_orders.py index 40004cddb..a84dc4717 100644 --- a/testing/api-sample-scripts/subscribe_orders.py +++ b/testing/api-sample-scripts/subscribe_orders.py @@ -1,6 +1,6 @@ import json import websocket -json_string = { +json_payload = { "jsonrpc": 2, "method": "subscribe", "params": { @@ -20,6 +20,7 @@ json_string = { }, "id": 1 } +json_string = json.dumps(json_payload) ws_url = "ws://localhost:8080" message_count = [0] # Define a callback function to handle received messages diff --git a/testing/api-sample-scripts/subscribe_price_stats.py b/testing/api-sample-scripts/subscribe_price_stats.py index 9830f6a5c..61d4702a0 100644 --- a/testing/api-sample-scripts/subscribe_price_stats.py +++ b/testing/api-sample-scripts/subscribe_price_stats.py @@ -1,6 +1,6 @@ import json import websocket -json_string = { +json_payload = { "jsonrpc": 2, "method": "subscribe", "params": { @@ -20,6 +20,7 @@ json_string = { }, "id": 1 } +json_string = json.dumps(json_payload) ws_url = "ws://localhost:8080" message_count = [0] # Define a callback function to handle received messages diff --git a/testing/api-sample-scripts/subscribe_price_tickets.py b/testing/api-sample-scripts/subscribe_price_tickers.py similarity index 92% rename from testing/api-sample-scripts/subscribe_price_tickets.py rename to testing/api-sample-scripts/subscribe_price_tickers.py index 580c7a382..c5fbc90a2 100644 --- a/testing/api-sample-scripts/subscribe_price_tickets.py +++ b/testing/api-sample-scripts/subscribe_price_tickers.py @@ -1,11 +1,11 @@ import json import websocket -json_string = { +json_payload = { "jsonrpc": 2, "method": "subscribe", "params": { "subscription_id": 1, - "type": "price_tickets", + "type": "price_tickers", "filter": { "symbol": [ "ETH" @@ -20,6 +20,7 @@ json_string = { }, "id": 1 } +json_string = json.dumps(json_payload) ws_url = "ws://localhost:8080" message_count = [0] # Define a callback function to handle received messages diff --git a/testing/api-sample-scripts/subscribe_securities.py b/testing/api-sample-scripts/subscribe_securities.py index fad358945..d182f8f2f 100644 --- a/testing/api-sample-scripts/subscribe_securities.py +++ b/testing/api-sample-scripts/subscribe_securities.py @@ -1,6 +1,6 @@ import json import websocket -json_string = { +json_payload = { "jsonrpc": 2, "method": "subscribe", "params": { @@ -20,6 +20,7 @@ json_string = { }, "id": 1 } +json_string = json.dumps(json_payload) ws_url = "ws://localhost:8080" message_count = [0] # Define a callback function to handle received messages diff --git a/testing/api-sample-scripts/subscribe_trades.py b/testing/api-sample-scripts/subscribe_trades.py index 7eae6af03..be4bd64af 100644 --- a/testing/api-sample-scripts/subscribe_trades.py +++ b/testing/api-sample-scripts/subscribe_trades.py @@ -1,6 +1,6 @@ import json import websocket -json_string = { +json_payload = { "jsonrpc": 2, "method": "subscribe", "params": { @@ -20,6 +20,7 @@ json_string = { }, "id": 1 } +json_string = json.dumps(json_payload) ws_url = "ws://localhost:8080" message_count = [0] # Define a callback function to handle received messages diff --git a/testing/api-sample-scripts/upd_cover_order.py b/testing/api-sample-scripts/upd_cover_order.py index e9e3ae29b..8f129cda0 100644 --- a/testing/api-sample-scripts/upd_cover_order.py +++ b/testing/api-sample-scripts/upd_cover_order.py @@ -1,22 +1,23 @@ import json import websocket -json_string = { +json_payload = { "jsonrpc": 2, "method": "update_order", "params": { "order_id": 538001, "price": 1641.8, "quantity": 2, - "order_type": { + "order_type": "cover", + "custom": { "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): diff --git a/testing/api-sample-scripts/upd_iceberg_order.py b/testing/api-sample-scripts/upd_iceberg_order.py index e75b2fa3a..82a620c68 100644 --- a/testing/api-sample-scripts/upd_iceberg_order.py +++ b/testing/api-sample-scripts/upd_iceberg_order.py @@ -1,19 +1,20 @@ import json import websocket -json_string = { +json_payload = { "jsonrpc": 2, "method": "update_order", "params": { "order_id": 538001, "price": 1641.8, "quantity": 2, - "order_type": { + "order_type": "iceberg", + "custom": { "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): diff --git a/testing/api-sample-scripts/upd_limit_order.py b/testing/api-sample-scripts/upd_limit_order.py index 5a11444e2..09b0e3e3f 100644 --- a/testing/api-sample-scripts/upd_limit_order.py +++ b/testing/api-sample-scripts/upd_limit_order.py @@ -1,17 +1,18 @@ import json import websocket -json_string = { +json_payload = { "jsonrpc": 2, "method": "update_order", "params": { "order_id": 538001, "price": 1641.8, "quantity": 2, - "order_type": {}, - "custom": "limit" + "order_type": "limit", + "custom": {} }, "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):