siglab-py 0.1.4__py3-none-any.whl → 0.1.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of siglab-py might be problematic. Click here for more details.
- siglab_py/ordergateway/client.py +45 -6
- siglab_py/ordergateway/test_ordergateway.py +14 -39
- {siglab_py-0.1.4.dist-info → siglab_py-0.1.6.dist-info}/METADATA +1 -1
- {siglab_py-0.1.4.dist-info → siglab_py-0.1.6.dist-info}/RECORD +6 -6
- {siglab_py-0.1.4.dist-info → siglab_py-0.1.6.dist-info}/WHEEL +0 -0
- {siglab_py-0.1.4.dist-info → siglab_py-0.1.6.dist-info}/top_level.txt +0 -0
siglab_py/ordergateway/client.py
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
|
|
2
|
-
from typing import List, Dict, Any
|
|
2
|
+
from typing import List, Dict, Any, Union
|
|
3
|
+
import json
|
|
4
|
+
import time
|
|
5
|
+
from redis import StrictRedis
|
|
3
6
|
|
|
4
|
-
from
|
|
5
|
-
|
|
6
|
-
from ..exchanges.any_exchange import AnyExchange
|
|
7
|
+
from exchanges.any_exchange import AnyExchange
|
|
8
|
+
from constants import JSON_SERIALIZABLE_TYPES
|
|
7
9
|
|
|
8
10
|
'''
|
|
9
11
|
Example,
|
|
@@ -37,7 +39,7 @@ class Order:
|
|
|
37
39
|
self.order_type = order_type.strip().lower()
|
|
38
40
|
self.leg_room_bps = leg_room_bps
|
|
39
41
|
|
|
40
|
-
def to_dict(self) -> Dict[
|
|
42
|
+
def to_dict(self) -> Dict[JSON_SERIALIZABLE_TYPES, JSON_SERIALIZABLE_TYPES]:
|
|
41
43
|
return {
|
|
42
44
|
"ticker" : self.ticker,
|
|
43
45
|
"side" : self.side,
|
|
@@ -126,7 +128,7 @@ class DivisiblePosition(Order):
|
|
|
126
128
|
self.average_cost = average_cost
|
|
127
129
|
return average_cost
|
|
128
130
|
|
|
129
|
-
def to_dict(self) -> Dict[
|
|
131
|
+
def to_dict(self) -> Dict[JSON_SERIALIZABLE_TYPES, JSON_SERIALIZABLE_TYPES]:
|
|
130
132
|
rv = super().to_dict()
|
|
131
133
|
rv['slices'] = self.slices
|
|
132
134
|
rv['wait_fill_threshold_ms'] = self.wait_fill_threshold_ms
|
|
@@ -134,3 +136,40 @@ class DivisiblePosition(Order):
|
|
|
134
136
|
rv['filled_amount'] = self.filled_amount
|
|
135
137
|
rv['average_cost'] = self.average_cost
|
|
136
138
|
return rv
|
|
139
|
+
|
|
140
|
+
def execute_positions(
|
|
141
|
+
redis_client : StrictRedis,
|
|
142
|
+
positions : List[DivisiblePosition],
|
|
143
|
+
ordergateway_pending_orders_topic : str,
|
|
144
|
+
ordergateway_executions_topic : str
|
|
145
|
+
) -> Union[Dict[JSON_SERIALIZABLE_TYPES, JSON_SERIALIZABLE_TYPES], None]:
|
|
146
|
+
|
|
147
|
+
executed_positions : Union[Dict[JSON_SERIALIZABLE_TYPES, JSON_SERIALIZABLE_TYPES], None] = None
|
|
148
|
+
|
|
149
|
+
# https://redis.io/commands/publish/
|
|
150
|
+
_positions = [ position.to_dict() for position in positions ]
|
|
151
|
+
redis_client.set(name=ordergateway_pending_orders_topic, value=json.dumps(_positions).encode('utf-8'), ex=60*15)
|
|
152
|
+
|
|
153
|
+
print(f"{ordergateway_pending_orders_topic}: Orders sent {_positions}.")
|
|
154
|
+
|
|
155
|
+
# Wait for fills
|
|
156
|
+
fills_received : bool = False
|
|
157
|
+
while not fills_received:
|
|
158
|
+
try:
|
|
159
|
+
keys = redis_client.keys()
|
|
160
|
+
for key in keys:
|
|
161
|
+
s_key : str = key.decode("utf-8")
|
|
162
|
+
if s_key==ordergateway_executions_topic:
|
|
163
|
+
message = redis_client.get(key)
|
|
164
|
+
if message:
|
|
165
|
+
message = message.decode('utf-8')
|
|
166
|
+
executed_positions = json.loads(message)
|
|
167
|
+
fills_received = True
|
|
168
|
+
break
|
|
169
|
+
|
|
170
|
+
except Exception as loop_err:
|
|
171
|
+
raise loop_err
|
|
172
|
+
finally:
|
|
173
|
+
time.sleep(1)
|
|
174
|
+
|
|
175
|
+
return executed_positions
|
|
@@ -5,15 +5,14 @@ from datetime import datetime
|
|
|
5
5
|
from typing import Any, Dict, List, Union
|
|
6
6
|
import logging
|
|
7
7
|
import json
|
|
8
|
-
import pandas as pd
|
|
9
|
-
import numpy as np
|
|
10
8
|
from redis import StrictRedis
|
|
11
9
|
|
|
12
|
-
from ordergateway.client import DivisiblePosition
|
|
10
|
+
from ordergateway.client import DivisiblePosition, execute_positions
|
|
11
|
+
from constants import JSON_SERIALIZABLE_TYPES
|
|
13
12
|
|
|
14
13
|
'''
|
|
15
14
|
set PYTHONPATH=%PYTHONPATH%;D:\dev\siglab\siglab_py
|
|
16
|
-
python test_ordergateway.py --gateway_id
|
|
15
|
+
python test_ordergateway.py --gateway_id bybit_03
|
|
17
16
|
'''
|
|
18
17
|
|
|
19
18
|
param : Dict[str, str] = {
|
|
@@ -42,16 +41,6 @@ def init_redis_client() -> StrictRedis:
|
|
|
42
41
|
|
|
43
42
|
return redis_client
|
|
44
43
|
|
|
45
|
-
def execute_positions(
|
|
46
|
-
redis_client : StrictRedis,
|
|
47
|
-
positions : List[DivisiblePosition],
|
|
48
|
-
ordergateway_pending_orders_topic : str):
|
|
49
|
-
# https://redis.io/commands/publish/
|
|
50
|
-
_positions = [ position.to_dict() for position in positions ]
|
|
51
|
-
redis_client.set(name=ordergateway_pending_orders_topic, value=json.dumps(_positions).encode('utf-8'), ex=60*15)
|
|
52
|
-
|
|
53
|
-
print(f"{ordergateway_pending_orders_topic}: Orders sent {_positions}.")
|
|
54
|
-
|
|
55
44
|
if __name__ == '__main__':
|
|
56
45
|
parse_args()
|
|
57
46
|
|
|
@@ -109,32 +98,18 @@ if __name__ == '__main__':
|
|
|
109
98
|
wait_fill_threshold_ms=60000
|
|
110
99
|
)
|
|
111
100
|
]
|
|
112
|
-
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
executed_positions : Union[Dict[JSON_SERIALIZABLE_TYPES, JSON_SERIALIZABLE_TYPES], None] = execute_positions(
|
|
113
104
|
redis_client=redis_client,
|
|
114
105
|
positions=positions_2,
|
|
115
|
-
ordergateway_pending_orders_topic=ordergateway_pending_orders_topic
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
s_key : str = key.decode("utf-8")
|
|
124
|
-
if s_key==ordergateway_executions_topic:
|
|
125
|
-
message = redis_client.get(key)
|
|
126
|
-
if message:
|
|
127
|
-
message = message.decode('utf-8')
|
|
128
|
-
positions = json.loads(message)
|
|
129
|
-
|
|
130
|
-
for position in positions:
|
|
131
|
-
print(f"{position['ticker']} {position['side']} amount: {position['amount']} leg_room_bps: {position['leg_room_bps']} slices: {position['slices']}, filled_amount: {position['filled_amount']}, average_cost: {position['average_cost']}, # executions: {len(position['executions'])}")
|
|
132
|
-
fills_received = True
|
|
133
|
-
break
|
|
134
|
-
|
|
135
|
-
except Exception as loop_err:
|
|
136
|
-
print(f"Oops {loop_err}")
|
|
137
|
-
finally:
|
|
138
|
-
time.sleep(1)
|
|
106
|
+
ordergateway_pending_orders_topic=ordergateway_pending_orders_topic,
|
|
107
|
+
ordergateway_executions_topic=ordergateway_executions_topic
|
|
108
|
+
)
|
|
109
|
+
if executed_positions:
|
|
110
|
+
for position in executed_positions:
|
|
111
|
+
print(f"{position['ticker']} {position['side']} amount: {position['amount']} leg_room_bps: {position['leg_room_bps']} slices: {position['slices']}, filled_amount: {position['filled_amount']}, average_cost: {position['average_cost']}, # executions: {len(position['executions'])}") # type: ignore
|
|
112
|
+
|
|
113
|
+
|
|
139
114
|
|
|
140
115
|
|
|
@@ -10,10 +10,10 @@ siglab_py/market_data_providers/deribit_options_expiry_provider.py,sha256=mP-508
|
|
|
10
10
|
siglab_py/market_data_providers/orderbooks_provider.py,sha256=cBp-HYCups2Uiwzw0SaUwxrg4unJvnm2TDqIK8f4hUg,15674
|
|
11
11
|
siglab_py/market_data_providers/test_provider.py,sha256=wBLCgcWjs7FGZJXWsNyn30lkOLa_cgpuvqRakMC0wbA,2221
|
|
12
12
|
siglab_py/ordergateway/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
-
siglab_py/ordergateway/client.py,sha256=
|
|
13
|
+
siglab_py/ordergateway/client.py,sha256=RWngzDnqsE_7LUqvRcDopTHxUNYKrA-FF_0A-IfJv90,6419
|
|
14
14
|
siglab_py/ordergateway/encrypt_keys_util.py,sha256=-qi87db8To8Yf1WS1Q_Cp2Ya7ZqgWlRqSHfNXCM7wE4,1339
|
|
15
15
|
siglab_py/ordergateway/gateway.py,sha256=xlTThsNRRHYWilpc3zpAcYC2nxG4crfpDY8Refbnl64,30038
|
|
16
|
-
siglab_py/ordergateway/test_ordergateway.py,sha256
|
|
16
|
+
siglab_py/ordergateway/test_ordergateway.py,sha256=DH4djEZeWZr69lTx_xG9_N8S_E2wAG4S3430VisU5w4,3805
|
|
17
17
|
siglab_py/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
18
|
siglab_py/tests/integration/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
19
|
siglab_py/tests/integration/market_data_util_tests.py,sha256=_UyOMTTBW1VJ7rroyESoxmdhBCQzWSV2A14tAjV9J5U,5634
|
|
@@ -23,7 +23,7 @@ siglab_py/util/analytic_util.py,sha256=QLabbEMqM4rKKH2PE_LqxIyo-BUdCRhkLybLATBIm
|
|
|
23
23
|
siglab_py/util/aws_util.py,sha256=x_duGDXJ6sO0wVpoRVDTMxECag7feA7zOwZweVLGl_w,2251
|
|
24
24
|
siglab_py/util/market_data_util.py,sha256=3qTq71xGvQXj0ORKJV50IN5FP_mCBF_gvdmlPyhdyco,16439
|
|
25
25
|
siglab_py/util/retry_util.py,sha256=mxYuRFZRZoaQQjENcwPmxhxixtd1TFvbxIdPx4RwfRc,743
|
|
26
|
-
siglab_py-0.1.
|
|
27
|
-
siglab_py-0.1.
|
|
28
|
-
siglab_py-0.1.
|
|
29
|
-
siglab_py-0.1.
|
|
26
|
+
siglab_py-0.1.6.dist-info/METADATA,sha256=-5cCWoewOwKri1IrLJG7rIeff4vbZpqDUQtQnxiTlDU,1096
|
|
27
|
+
siglab_py-0.1.6.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
28
|
+
siglab_py-0.1.6.dist-info/top_level.txt,sha256=AbD4VR9OqmMOGlMJLkAVPGQMtUPIQv0t1BF5xmcLJSk,10
|
|
29
|
+
siglab_py-0.1.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|