Qubx 0.1.7__cp311-cp311-manylinux_2_35_x86_64.whl → 0.1.8__cp311-cp311-manylinux_2_35_x86_64.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 Qubx might be problematic. Click here for more details.

qubx/data/readers.py CHANGED
@@ -507,23 +507,25 @@ class QuestDBConnector(DataReader):
507
507
  """
508
508
  Very first version of QuestDB connector
509
509
 
510
- # Connect to an existing QuestDB instance
511
- >>> db = QuestDBConnector('user=admin password=quest host=localhost port=8812', OhlcvPandasDataProcessor())
512
- >>> db.read('BINANCEF.ETHUSDT', '2024-01-01')
510
+ ### Connect to an existing QuestDB instance
511
+ >>> db = QuestDBConnector()
512
+ >>> db.read('BINANCE.UM:ETHUSDT', '2024-01-01', transform=AsPandasFrame())
513
513
  """
514
514
  _reconnect_tries = 5
515
515
  _reconnect_idle = 0.1 # wait seconds before retying
516
516
 
517
- def __init__(self, connection_url: str) -> None:
517
+ def __init__(self, host='localhost', user='admin', password='quest', port=8812) -> None:
518
518
  self._connection = None
519
519
  self._cursor = None
520
- self.connection_url = connection_url
520
+ self._host = host
521
+ self._port = port
522
+ self.connection_url = f'user={user} password={password} host={host} port={port}'
521
523
  self._connect()
522
524
 
523
525
  def _connect(self):
524
- logger.info("Connecting to QuestDB ...")
525
526
  self._connection = pg.connect(self.connection_url, autocommit=True)
526
527
  self._cursor = self._connection.cursor()
528
+ logger.debug(f"Connected to QuestDB at {self._host}:{self._port}")
527
529
 
528
530
  @_retry
529
531
  def read(self, data_id: str, start: str|None=None, stop: str|None=None,
@@ -542,14 +544,49 @@ class QuestDBConnector(DataReader):
542
544
  transform.process_data(records)
543
545
  return transform.collect()
544
546
 
545
- def _prepare_data_sql(self, data_id: str, start: str|None, end: str|None, resample: str) -> str:
546
- # just a temp hack - actually we need to discuss symbology etc
547
- symbol = data_id#.split('.')[-1]
547
+ @staticmethod
548
+ def _convert_time_delta_to_qdb_resample_format(c_tf: str):
549
+ if c_tf:
550
+ _t = re.match(r'(\d+)(\w+)', c_tf)
551
+ if _t and len(_t.groups()) > 1:
552
+ c_tf = f"{_t[1]}{_t[2][0].lower()}"
553
+ return c_tf
554
+
555
+ def _get_table_name(self, data_id: str, sfx: str='') -> str:
556
+ """
557
+ Get table name for data_id
558
+ data_id can have format <exchange>.<type>:<symbol>
559
+ for example:
560
+ BINANCE.UM:BTCUSDT or BINANCE:BTCUSDT for spot
561
+ """
562
+ _aliases = {'um': 'umfutures', 'cm': 'cmfutures', 'f': 'futures'}
563
+ table_name = data_id
564
+ _ss = data_id.split(':')
565
+ if len(_ss) > 1:
566
+ _exch, symb = _ss
567
+ _mktype = 'spot'
568
+ _ss = _exch.split('.')
569
+ if len(_ss) > 1:
570
+ _exch = _ss[0]
571
+ _mktype = _ss[1]
572
+ _mktype = _mktype.lower()
573
+ table_name = '.'.join(filter(lambda x: x, [_exch.lower(), _aliases.get(_mktype, _mktype), symb.lower(), sfx]))
574
+ return table_name
548
575
 
576
+ def _prepare_data_sql(self, data_id: str, start: str|None, end: str|None, resample: str) -> str:
577
+ where = ''
549
578
  w0 = f"timestamp >= '{start}'" if start else ''
550
579
  w1 = f"timestamp <= '{end}'" if end else ''
551
- where = f'where {w0} and {w1}' if (w0 and w1) else f"where {(w0 or w1)}"
552
580
 
581
+ # - fix: when no data ranges are provided we must skip empy where keyword
582
+ if w0 or w1:
583
+ where = f'where {w0} and {w1}' if (w0 and w1) else f"where {(w0 or w1)}"
584
+
585
+ # - check resample format
586
+ resample = QuestDBConnector._convert_time_delta_to_qdb_resample_format(resample) if resample else resample
587
+ _rsmpl = f"SAMPLE by {resample}" if resample else ''
588
+
589
+ table_name = self._get_table_name(data_id, 'candles_1m')
553
590
  return f"""
554
591
  select timestamp,
555
592
  first(open) as open,
@@ -561,8 +598,7 @@ class QuestDBConnector(DataReader):
561
598
  sum(count) as count,
562
599
  sum(taker_buy_volume) as taker_buy_volume,
563
600
  sum(taker_buy_quote_volume) as taker_buy_quote_volume
564
- from "{symbol.upper()}" {where}
565
- SAMPLE by {resample};
601
+ from "{table_name}" {where} {_rsmpl};
566
602
  """
567
603
 
568
604
  def _prepare_names_sql(self) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: Qubx
3
- Version: 0.1.7
3
+ Version: 0.1.8
4
4
  Summary: Qubx - quantitative trading framework
5
5
  Home-page: https://github.com/dmarienko/Qubx
6
6
  Author: Dmitry Marienko
@@ -6,13 +6,13 @@ qubx/core/basics.py,sha256=2u7WV5KX-RbTmzoKfi1yT4HNLDPfQcFMCUZ1pVsM_VE,14777
6
6
  qubx/core/helpers.py,sha256=gPE78dO718NBY0-JbfqNGCzIvr4BVatFntNIy2RUrEY,11559
7
7
  qubx/core/loggers.py,sha256=HpgavBZegoDv9ssihtqX0pitXKULVAPHUpoE_volJw0,11910
8
8
  qubx/core/lookups.py,sha256=4aEC7b2AyEXFqHHGDenex3Z1FZGrpDSb8IwzBZrSqIA,13688
9
- qubx/core/series.cpython-311-x86_64-linux-gnu.so,sha256=Wpec9yDlhedIs11mCYl8pVf30bghhwL4UHBxgMesiak,698952
9
+ qubx/core/series.cpython-311-x86_64-linux-gnu.so,sha256=ltVxtoC4f0B4skXk6yRtoryDzon6gwLX_3NuX7gb5io,698952
10
10
  qubx/core/series.pxd,sha256=IS89NQ5FYp3T0YIHe1lELKZIAKrNvX8K6WlLyac44I4,2847
11
11
  qubx/core/series.pyx,sha256=WEAjn4j3zn540Cxx68X5gRXilvwa7NGdbki6myzZbIM,28108
12
12
  qubx/core/strategy.py,sha256=Fs4fFyHaEGYuz7mBeQHBWFu3Ipg0yFzcxXhskgsPxJE,30330
13
- qubx/core/utils.cpython-311-x86_64-linux-gnu.so,sha256=nLncQM5F9XMpCda8IWifgSYWtoL0MCrQg27fPxK9Z2I,74216
13
+ qubx/core/utils.cpython-311-x86_64-linux-gnu.so,sha256=5ddzSg68VpiWMCEtase_w0XhyEb4DUjP7xWxL55XQ4k,74216
14
14
  qubx/core/utils.pyx,sha256=6dQ8R02bl8V3f-W3Wk9-e86D9OvDz-5-4NA_dlF_xwc,1368
15
- qubx/data/readers.py,sha256=wQc3tsLoNcvO9c2YFDxrN8jyXtPMbR3XrA_NBA38zp8,23350
15
+ qubx/data/readers.py,sha256=EuYLt7mmf4TPtVzlbbxGvgw-luR7oDPwdLJQe37iU6c,24786
16
16
  qubx/impl/ccxt_connector.py,sha256=NqF-tgxfTATnmVqKUonNXCAzECrDU8YrgqM3Nq06fw8,9150
17
17
  qubx/impl/ccxt_customizations.py,sha256=kK_4KmOyKvDVgd4MTkVg4CyqdjE-6r41siZIvLj-A-Q,3488
18
18
  qubx/impl/ccxt_trading.py,sha256=cmg4P-zd78w-V8j3-IGS2LFxikGhxFPgmCvz3sr065Q,9097
@@ -23,7 +23,7 @@ qubx/pandaz/__init__.py,sha256=Iw5uzicYGSC3FEKZ-W1O5-7cXq_P0kH11-EcXV0zZhs,175
23
23
  qubx/pandaz/ta.py,sha256=TUvjrvmk4EQvDcXoRp6Os08-HUap-ZvpSDGawhViOgg,85271
24
24
  qubx/pandaz/utils.py,sha256=FyLKQy8spkqxhBij_nPFC_ZzI_L3-IgB9O53MqWKmq0,19109
25
25
  qubx/ta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
- qubx/ta/indicators.cpython-311-x86_64-linux-gnu.so,sha256=HFcrtnfX2BiiqymRwZ5lftBsqrF-TEmZKchPVzhbUbM,284552
26
+ qubx/ta/indicators.cpython-311-x86_64-linux-gnu.so,sha256=JDkaQwaNS6-J9ICrxJsATcSxaZKvURf0jtQ-09vhUGg,284552
27
27
  qubx/ta/indicators.pyx,sha256=P-GEYUks2lSHo6hbtUFAB7TWE1AunjLR4jIjwqPHrwU,7708
28
28
  qubx/trackers/__init__.py,sha256=1y_yvIy0OQwBqfhAW_EY33NxFzFSWvI0qNAPU6zchYc,60
29
29
  qubx/trackers/rebalancers.py,sha256=QCzANCooZBi2VMCBjjCPMq_Dt1h1zrBelATnfmVve74,5522
@@ -34,6 +34,6 @@ qubx/utils/marketdata/binance.py,sha256=36dl4rxOAGTeY3uoONmiPanj8BkP0oBdDiH-URJJ
34
34
  qubx/utils/misc.py,sha256=z5rdz5hbRu9-F2QgF47OCkMvhfIkRKs-PHR8L5DWkBM,9831
35
35
  qubx/utils/runner.py,sha256=OY7SoRfxHwzn0rKTGB_lbg5zNASEL_49hQXWqs-LiMk,9306
36
36
  qubx/utils/time.py,sha256=_DjCdQditzZwMy_8rvPdWyw5tjw__2p24LMPgXdZ8i0,4911
37
- qubx-0.1.7.dist-info/METADATA,sha256=gjq_-njDfPiu_li6ID5hClbIvZL3NsVARvM6NRNZd9U,2490
38
- qubx-0.1.7.dist-info/WHEEL,sha256=MLOa6LysROdjgj4FVxsHitAnIh8Be2D_c9ZSBHKrz2M,110
39
- qubx-0.1.7.dist-info/RECORD,,
37
+ qubx-0.1.8.dist-info/METADATA,sha256=W62rM-gCLkzeF0GQ087NFox6vZ6wQBouO_aSfRaDoV8,2490
38
+ qubx-0.1.8.dist-info/WHEEL,sha256=MLOa6LysROdjgj4FVxsHitAnIh8Be2D_c9ZSBHKrz2M,110
39
+ qubx-0.1.8.dist-info/RECORD,,
File without changes