Qubx 0.2.69__tar.gz → 0.2.71__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 Qubx might be problematic. Click here for more details.

Files changed (57) hide show
  1. {qubx-0.2.69 → qubx-0.2.71}/PKG-INFO +1 -1
  2. {qubx-0.2.69 → qubx-0.2.71}/pyproject.toml +1 -1
  3. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/backtester/simulator.py +10 -4
  4. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/core/basics.py +6 -0
  5. qubx-0.2.71/src/qubx/gathering/simplest.py +88 -0
  6. qubx-0.2.69/src/qubx/gathering/simplest.py +0 -44
  7. {qubx-0.2.69 → qubx-0.2.71}/README.md +0 -0
  8. {qubx-0.2.69 → qubx-0.2.71}/build.py +0 -0
  9. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/__init__.py +0 -0
  10. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/_nb_magic.py +0 -0
  11. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/backtester/__init__.py +0 -0
  12. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/backtester/ome.py +0 -0
  13. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/backtester/optimization.py +0 -0
  14. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/backtester/queue.py +0 -0
  15. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/core/__init__.py +0 -0
  16. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/core/account.py +0 -0
  17. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/core/context.py +0 -0
  18. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/core/exceptions.py +0 -0
  19. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/core/helpers.py +0 -0
  20. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/core/loggers.py +0 -0
  21. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/core/lookups.py +0 -0
  22. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/core/metrics.py +0 -0
  23. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/core/series.pxd +0 -0
  24. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/core/series.pyi +0 -0
  25. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/core/series.pyx +0 -0
  26. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/core/strategy.py +0 -0
  27. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/core/utils.pyi +0 -0
  28. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/core/utils.pyx +0 -0
  29. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/data/helpers.py +0 -0
  30. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/data/readers.py +0 -0
  31. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/impl/ccxt_connector.py +0 -0
  32. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/impl/ccxt_customizations.py +0 -0
  33. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/impl/ccxt_trading.py +0 -0
  34. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/impl/ccxt_utils.py +0 -0
  35. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/math/__init__.py +0 -0
  36. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/math/stats.py +0 -0
  37. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/pandaz/__init__.py +0 -0
  38. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/pandaz/ta.py +0 -0
  39. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/pandaz/utils.py +0 -0
  40. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/ta/__init__.py +0 -0
  41. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/ta/indicators.pxd +0 -0
  42. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/ta/indicators.pyi +0 -0
  43. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/ta/indicators.pyx +0 -0
  44. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/trackers/__init__.py +0 -0
  45. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/trackers/composite.py +0 -0
  46. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/trackers/rebalancers.py +0 -0
  47. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/trackers/riskctrl.py +0 -0
  48. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/trackers/sizers.py +0 -0
  49. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/utils/__init__.py +0 -0
  50. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/utils/_pyxreloader.py +0 -0
  51. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/utils/charting/lookinglass.py +0 -0
  52. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/utils/charting/mpl_helpers.py +0 -0
  53. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/utils/marketdata/binance.py +0 -0
  54. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/utils/misc.py +0 -0
  55. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/utils/ntp.py +0 -0
  56. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/utils/runner.py +0 -0
  57. {qubx-0.2.69 → qubx-0.2.71}/src/qubx/utils/time.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: Qubx
3
- Version: 0.2.69
3
+ Version: 0.2.71
4
4
  Summary: Qubx - quantitative trading framework
5
5
  Home-page: https://github.com/dmarienko/Qubx
6
6
  Author: Dmitry Marienko
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "Qubx"
3
- version = "0.2.69"
3
+ version = "0.2.71"
4
4
  description = "Qubx - quantitative trading framework"
5
5
  authors = ["Dmitry Marienko <dmitry@gmail.com>", "Yuriy Arabskyy <yuriy.arabskyy@gmail.com>"]
6
6
  readme = "README.md"
@@ -468,11 +468,13 @@ class SimulatedExchange(IBrokerServiceProvider):
468
468
 
469
469
  if silent:
470
470
  for symbol, data_type, event in qiter:
471
- _run(symbol, data_type, event)
471
+ if not _run(symbol, data_type, event):
472
+ break
472
473
  else:
473
474
  with tqdm(total=total_duration.total_seconds(), desc="Simulating", unit="s", leave=False) as pbar:
474
475
  for symbol, data_type, event in qiter:
475
- _run(symbol, data_type, event)
476
+ if not _run(symbol, data_type, event):
477
+ break
476
478
  dt = pd.Timestamp(event.time)
477
479
  # update only if date has changed
478
480
  if dt - prev_dt > update_delta:
@@ -484,7 +486,7 @@ class SimulatedExchange(IBrokerServiceProvider):
484
486
 
485
487
  logger.info(f"SimulatedExchangeService :: run :: Simulation finished at {end}")
486
488
 
487
- def _run_generated_signals(self, symbol: str, data_type: str, data: Any) -> None:
489
+ def _run_generated_signals(self, symbol: str, data_type: str, data: Any) -> bool:
488
490
  is_hist = data_type.startswith("hist")
489
491
  if is_hist:
490
492
  raise ValueError("Historical data is not supported for pre-generated signals !")
@@ -503,7 +505,9 @@ class SimulatedExchange(IBrokerServiceProvider):
503
505
  cc.send((symbol, "event", {"order": sigs[0][1]}))
504
506
  sigs.pop(0)
505
507
 
506
- def _run_as_strategy(self, symbol: str, data_type: str, data: Any) -> None:
508
+ return cc.control.is_set()
509
+
510
+ def _run_as_strategy(self, symbol: str, data_type: str, data: Any) -> bool:
507
511
  cc = self.get_communication_channel()
508
512
  t = data.time # type: ignore
509
513
  self._current_time = max(np.datetime64(t, "ns"), self._current_time)
@@ -525,6 +529,8 @@ class SimulatedExchange(IBrokerServiceProvider):
525
529
  if q is not None and data_type != "quote":
526
530
  cc.send((symbol, "quote", q))
527
531
 
532
+ return cc.control.is_set()
533
+
528
534
  def get_quote(self, symbol: str) -> Optional[Quote]:
529
535
  return self._last_quotes[symbol]
530
536
 
@@ -570,6 +570,12 @@ class SimulatedCtrlChannel(CtrlChannel):
570
570
  def receive(self) -> Any:
571
571
  raise ValueError("This method should not be called in a simulated environment.")
572
572
 
573
+ def stop(self):
574
+ self.control.clear()
575
+
576
+ def start(self):
577
+ self.control.set()
578
+
573
579
 
574
580
  class IComminucationManager:
575
581
  databus: CtrlChannel
@@ -0,0 +1,88 @@
1
+ from qubx import logger
2
+ from qubx.core.basics import Deal, Instrument, TargetPosition
3
+ from qubx.core.strategy import IPositionGathering, StrategyContext
4
+
5
+
6
+ class SimplePositionGatherer(IPositionGathering):
7
+ """
8
+ Default implementation of positions gathering by single orders through strategy context
9
+ """
10
+
11
+ entry_order_id: str | None = None
12
+
13
+ def _cncl_order(self, ctx: StrategyContext, instrument: Instrument) -> None:
14
+ if self.entry_order_id:
15
+ logger.debug(
16
+ f"<green>{instrument.symbol}</green>: Cancelling previous entry order <red>{self.entry_order_id}</red>"
17
+ )
18
+ try:
19
+ ctx.cancel_order(self.entry_order_id)
20
+ except Exception as e:
21
+ logger.error(f"Cancelling entry order failed: {str(e)}")
22
+ self.entry_order_id = None
23
+
24
+ def alter_position_size(self, ctx: StrategyContext, target: TargetPosition) -> float:
25
+ # Here is default inplementation:
26
+ # just trade it through the strategy context by using market (or limit) orders.
27
+ # but in general it may have complex logic for position adjustment
28
+ instrument, new_size, at_price = target.instrument, target.target_position_size, target.price
29
+ current_position = ctx.positions[instrument.symbol].quantity
30
+ to_trade = new_size - current_position
31
+
32
+ # - first cancel previous entry order if exists
33
+ self._cncl_order(ctx, instrument)
34
+
35
+ if abs(to_trade) < instrument.min_size:
36
+ if current_position != 0:
37
+ logger.warning(
38
+ f"{instrument.exchange}:{instrument.symbol}: Unable change position from {current_position} to {new_size} : too small difference"
39
+ )
40
+ else:
41
+
42
+ # - check how it should be traded: market or limit or stop order
43
+ opts = {}
44
+ _is_stop_or_limit = False
45
+ if at_price:
46
+ # - we already havbe position but it's requested to change at a specific price
47
+ if abs(current_position) > instrument.min_size:
48
+ logger.warning(
49
+ f"<green>{instrument.symbol}</green>: Attempt to change current position {current_position} to {new_size} at {at_price} !"
50
+ )
51
+
52
+ quote = ctx.quote(instrument.symbol)
53
+ if (to_trade > 0 and at_price > quote.ask) or (to_trade < 0 and at_price < quote.bid):
54
+ opts["stop_type"] = "market"
55
+ _is_stop_or_limit = True
56
+
57
+ if (to_trade > 0 and at_price <= quote.bid) or (to_trade < 0 and at_price >= quote.ask):
58
+ _is_stop_or_limit = True
59
+
60
+ r = ctx.trade(instrument, to_trade, at_price, **opts)
61
+ if _is_stop_or_limit:
62
+ self.entry_order_id = r.id
63
+ logger.debug(
64
+ f"<green>{instrument.symbol}</green>: Position may be adjusted from {current_position} to {new_size} at {at_price} : {r}"
65
+ )
66
+ else:
67
+ self.entry_order_id = None
68
+ logger.debug(
69
+ f"<green>{instrument.symbol}</green>: Adjusting position from {current_position} to {new_size} : {r}"
70
+ )
71
+
72
+ current_position = new_size
73
+ # - TODO: need to check how fast position is being updated on live
74
+ # current_position = ctx.positions[instrument.symbol].quantity
75
+
76
+ return current_position
77
+
78
+ def on_execution_report(self, ctx: StrategyContext, instrument: Instrument, deal: Deal):
79
+ if deal.order_id == self.entry_order_id:
80
+ self.entry_order_id = None
81
+
82
+
83
+ class SplittedOrdersPositionGatherer(IPositionGathering):
84
+ """
85
+ Gather position by splitting order into smaller parts randomly
86
+ """
87
+
88
+ pass
@@ -1,44 +0,0 @@
1
- from qubx import logger
2
- from qubx.core.basics import Deal, Instrument, TargetPosition
3
- from qubx.core.strategy import IPositionGathering, StrategyContext
4
-
5
-
6
- class SimplePositionGatherer(IPositionGathering):
7
- """
8
- Default implementation of positions gathering by single orders through strategy context
9
- """
10
-
11
- def alter_position_size(self, ctx: StrategyContext, target: TargetPosition) -> float:
12
- instrument, new_size, at_price = target.instrument, target.target_position_size, target.price
13
- current_position = ctx.positions[instrument.symbol].quantity
14
- to_trade = new_size - current_position
15
- if abs(to_trade) < instrument.min_size:
16
- logger.warning(
17
- f"{instrument.exchange}:{instrument.symbol}: Unable change position from {current_position} to {new_size} : too small difference"
18
- )
19
- else:
20
- # - here is default inplementation:
21
- # just trade it through the strategy context by using market (or limit) orders.
22
- # - but in general it may have complex logic for position adjustment
23
- r = ctx.trade(instrument, to_trade, at_price)
24
- # , fill_at_price=target.signal.options.get("fill_at_signal_price", False)
25
- logger.debug(
26
- f"<green>{instrument.symbol}</green>: Adjusting position from {current_position} to {new_size} : {r}"
27
- )
28
-
29
- current_position = new_size
30
- # - TODO: need to check how fast position is being updated on live
31
- # current_position = ctx.positions[instrument.symbol].quantity
32
-
33
- return current_position
34
-
35
- def on_execution_report(self, ctx: StrategyContext, instrument: Instrument, deal: Deal):
36
- pass
37
-
38
-
39
- class SplittedOrdersPositionGatherer(IPositionGathering):
40
- """
41
- Gather position by splitting order into smaller parts randomly
42
- """
43
-
44
- pass
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
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