siglab-py 0.3.10__tar.gz → 0.3.12__tar.gz
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-0.3.10 → siglab_py-0.3.12}/PKG-INFO +1 -1
- {siglab_py-0.3.10 → siglab_py-0.3.12}/pyproject.toml +1 -1
- {siglab_py-0.3.10 → siglab_py-0.3.12}/setup.cfg +1 -1
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/ordergateway/gateway.py +8 -2
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/util/market_data_util.py +9 -0
- siglab_py-0.3.12/siglab_py/util/retry_util.py +23 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py.egg-info/PKG-INFO +1 -1
- siglab_py-0.3.10/siglab_py/util/retry_util.py +0 -15
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/__init__.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/constants.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/exchanges/__init__.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/exchanges/any_exchange.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/exchanges/futubull.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/market_data_providers/__init__.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/market_data_providers/aggregated_orderbook_provider.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/market_data_providers/candles_provider.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/market_data_providers/candles_ta_provider.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/market_data_providers/ccxt_candles_ta_to_csv.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/market_data_providers/deribit_options_expiry_provider.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/market_data_providers/futu_candles_ta_to_csv.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/market_data_providers/orderbooks_provider.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/market_data_providers/test_provider.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/ordergateway/__init__.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/ordergateway/client.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/ordergateway/encrypt_keys_util.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/ordergateway/test_ordergateway.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/tests/__init__.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/tests/integration/__init__.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/tests/integration/market_data_util_tests.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/tests/unit/__init__.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/tests/unit/analytic_util_tests.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/tests/unit/market_data_util_tests.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/tests/unit/trading_util_tests.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/util/__init__.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/util/analytic_util.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/util/aws_util.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/util/notification_util.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/util/slack_notification_util.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/util/trading_util.py +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py.egg-info/SOURCES.txt +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py.egg-info/dependency_links.txt +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py.egg-info/requires.txt +0 -0
- {siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py.egg-info/top_level.txt +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "siglab_py"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.12"
|
|
8
8
|
description = "Market data fetches, TA calculations and generic order gateway."
|
|
9
9
|
authors = [{name = "r0bbarh00d", email = "r0bbarh00d@gmail.com"}]
|
|
10
10
|
license = {text = "MIT"}
|
|
@@ -34,17 +34,21 @@ current_filename = os.path.basename(__file__)
|
|
|
34
34
|
'''
|
|
35
35
|
Usage:
|
|
36
36
|
set PYTHONPATH=%PYTHONPATH%;D:\dev\siglab\siglab_py
|
|
37
|
-
python gateway.py --gateway_id hyperliquid_01 --default_type linear --rate_limit_ms 100
|
|
37
|
+
python gateway.py --gateway_id hyperliquid_01 --default_type linear --rate_limit_ms 100 --encrypt_decrypt_with_aws_kms Y --aws_kms_key_id xxx --apikey xxx --secret xxxx --slack_info_url=https://hooks.slack.com/services/xxx --slack_critial_url=https://hooks.slack.com/services/xxx --slack_alert_url=https://hooks.slack.com/services/xxx
|
|
38
38
|
|
|
39
39
|
--default_type defaults to linear
|
|
40
40
|
--rate_limit_ms defaults to 100
|
|
41
|
-
|
|
41
|
+
--encrypt_decrypt_with_aws_kms If you encrypt apikey and secret using AMS KMS, then set to Y. If apikey and secret in unencrypted plain text, set to N.
|
|
42
|
+
--passphrase is optional, this depends on the exchange.
|
|
43
|
+
--gateway_id contains two parts separated by underscore. Gateway.py will parse 'hyperliquid_01' into two parts: 'hyperliquid' (Exchange name) and '01' (Use this for your sub account ID). Exchange name need be spelt exactly. Please have a look at market_data_util async_instantiate_exchange.
|
|
42
44
|
--slack_info_url, --slack_critical_url and --slack_alert_url are if you want gateway to dispatch Slack notification on events.
|
|
43
45
|
How to get Slack webhook urls? https://medium.com/@natalia_assad/how-send-a-table-to-slack-using-python-d1a20b08abe0
|
|
44
46
|
|
|
45
47
|
Another example:
|
|
46
48
|
python gateway.py --gateway_id hyperliquid_01 --default_type linear --rate_limit_ms 100 --slack_info_url=https://hooks.slack.com/services/xxx --slack_critial_url=https://hooks.slack.com/services/yyy --slack_alert_url=https://hooks.slack.com/services/zzz
|
|
47
49
|
|
|
50
|
+
gateway.py takes outgoing orders from redis and publish executions back to redis when done. Redis configuration in param['mds']['redis']. Start redis before starting gateway.py.
|
|
51
|
+
|
|
48
52
|
This script is pypy compatible:
|
|
49
53
|
pypy gateway.py --gateway_id bybit_01 --default_type linear --rate_limit_ms 100
|
|
50
54
|
|
|
@@ -452,6 +456,8 @@ async def execute_one_position(
|
|
|
452
456
|
'reduceOnly': slice.reduce_only
|
|
453
457
|
}
|
|
454
458
|
if position.order_type=='limit':
|
|
459
|
+
order_params['postOnly'] = True
|
|
460
|
+
|
|
455
461
|
if not param['dry_run']:
|
|
456
462
|
executed_order = await exchange.create_order( # type: ignore
|
|
457
463
|
symbol = position.ticker,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import logging
|
|
1
2
|
import incremental
|
|
2
3
|
import tzlocal
|
|
3
4
|
from datetime import datetime, timezone
|
|
@@ -19,6 +20,7 @@ from yahoofinancials import YahooFinancials
|
|
|
19
20
|
# yfinance allows intervals '1m', '5m', '15m', '1h', '1d', '1wk', '1mo'. yahoofinancials not as flexible
|
|
20
21
|
import yfinance as yf
|
|
21
22
|
|
|
23
|
+
from siglab_py.util.retry_util import retry
|
|
22
24
|
from siglab_py.exchanges.futubull import Futubull
|
|
23
25
|
from siglab_py.exchanges.any_exchange import AnyExchange
|
|
24
26
|
|
|
@@ -115,6 +117,8 @@ async def async_instantiate_exchange(
|
|
|
115
117
|
# spot, swap, future
|
|
116
118
|
# https://github.com/ccxt/ccxt/blob/master/python/ccxt/deribit.py#L360
|
|
117
119
|
exchange = ccxtpro.deribit(exchange_params) # type: ignore
|
|
120
|
+
elif exchange_name=='kraken':
|
|
121
|
+
exchange = ccxtpro.kraken(exchange_params) # type: ignore
|
|
118
122
|
elif exchange_name=='hyperliquid':
|
|
119
123
|
'''
|
|
120
124
|
https://app.hyperliquid.xyz/API
|
|
@@ -516,9 +520,12 @@ def _fetch_candles_ccxt(
|
|
|
516
520
|
candle_size : str,
|
|
517
521
|
num_candles_limit : int = 100
|
|
518
522
|
) -> Dict[str, Union[pd.DataFrame, None]]:
|
|
523
|
+
logger = logging.getLogger()
|
|
524
|
+
|
|
519
525
|
rsp = {}
|
|
520
526
|
|
|
521
527
|
for ticker in normalized_symbols:
|
|
528
|
+
@retry(num_attempts=3, pause_between_retries_ms=1000)
|
|
522
529
|
def _fetch_ohlcv(exchange, symbol, timeframe, since, limit, params) -> Union[List, NoReturn]:
|
|
523
530
|
one_timeframe = f"1{timeframe[-1]}"
|
|
524
531
|
candles = exchange.fetch_ohlcv(symbol=symbol, timeframe=one_timeframe, since=since, limit=limit, params=params)
|
|
@@ -541,6 +548,8 @@ def _fetch_candles_ccxt(
|
|
|
541
548
|
raise ValueError(f"Invalid candle_size {candle_size}")
|
|
542
549
|
return num_intervals * increment
|
|
543
550
|
|
|
551
|
+
logger.info(f"Fetching {candle_size} candles for {ticker}.")
|
|
552
|
+
|
|
544
553
|
all_candles = []
|
|
545
554
|
params = {}
|
|
546
555
|
this_cutoff = start_ts
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
def retry(
|
|
4
|
+
num_attempts : int = 1,
|
|
5
|
+
pause_between_retries_ms : int = 1000
|
|
6
|
+
):
|
|
7
|
+
def decorator(method):
|
|
8
|
+
def wrapper(*args, **kw):
|
|
9
|
+
for i in range(num_attempts):
|
|
10
|
+
try:
|
|
11
|
+
result = method(*args, **kw)
|
|
12
|
+
if i>0:
|
|
13
|
+
print(f"retry_util.retry done {method.__name__} on #{i+1} call. {args} {kw}")
|
|
14
|
+
return result
|
|
15
|
+
except Exception as retry_error:
|
|
16
|
+
if i==(num_attempts-1):
|
|
17
|
+
err_msg = f"retry_util.retry gave up {method.__name__} after {num_attempts} calls. {args} {kw}. {retry_error}"
|
|
18
|
+
raise Exception(err_msg) from retry_error
|
|
19
|
+
finally:
|
|
20
|
+
time.sleep(int(pause_between_retries_ms/1000))
|
|
21
|
+
|
|
22
|
+
return wrapper
|
|
23
|
+
return decorator
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
def retry(num_attempts : int = 1):
|
|
2
|
-
def decorator(method):
|
|
3
|
-
def wrapper(*args, **kw):
|
|
4
|
-
for i in range(num_attempts):
|
|
5
|
-
try:
|
|
6
|
-
result = method(*args, **kw)
|
|
7
|
-
if i>0:
|
|
8
|
-
print(f"retry_gizmo.retry succeeded: {method.__name__} on #{i+1} invocation. {args} {kw}")
|
|
9
|
-
return result
|
|
10
|
-
except Exception as retry_error:
|
|
11
|
-
if i==(num_attempts-1):
|
|
12
|
-
err_msg = f"retry_gizmo.retry failed: {method.__name__} after {num_attempts} invocations. {args} {kw}. {retry_error}"
|
|
13
|
-
raise Exception(err_msg) from retry_error
|
|
14
|
-
return wrapper
|
|
15
|
-
return decorator
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/market_data_providers/candles_ta_provider.py
RENAMED
|
File without changes
|
{siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/market_data_providers/ccxt_candles_ta_to_csv.py
RENAMED
|
File without changes
|
|
File without changes
|
{siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/market_data_providers/futu_candles_ta_to_csv.py
RENAMED
|
File without changes
|
{siglab_py-0.3.10 → siglab_py-0.3.12}/siglab_py/market_data_providers/orderbooks_provider.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|