Qubx 0.6.41__cp312-cp312-manylinux_2_39_x86_64.whl → 0.6.42__cp312-cp312-manylinux_2_39_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.

@@ -13,7 +13,12 @@ class IncrementalFormatter(DefaultFormatter):
13
13
  based on leverage changes.
14
14
  """
15
15
 
16
- def __init__(self, alert_name: str, exchange_mapping: Optional[Dict[str, str]] = None):
16
+ def __init__(
17
+ self,
18
+ alert_name: str,
19
+ exchange_mapping: Optional[Dict[str, str]] = None,
20
+ account: Optional[IAccountViewer] = None
21
+ ):
17
22
  """
18
23
  Initialize the IncrementalFormatter.
19
24
 
@@ -21,12 +26,16 @@ class IncrementalFormatter(DefaultFormatter):
21
26
  alert_name: The name of the alert to include in the messages
22
27
  exchange_mapping: Optional mapping of exchange names to use in messages.
23
28
  If an exchange is not in the mapping, the instrument's exchange is used.
29
+ account: The account viewer to get account information like total capital, leverage, etc.
24
30
  """
25
31
  super().__init__()
26
32
  self.alert_name = alert_name
27
33
  self.exchange_mapping = exchange_mapping or {}
28
34
  self.instrument_leverages: Dict[Instrument, float] = {}
29
35
 
36
+ if account:
37
+ self.instrument_leverages = dict(account.get_leverages())
38
+
30
39
  def format_position_change(
31
40
  self, time: dt_64, instrument: Instrument, price: float, account: IAccountViewer
32
41
  ) -> dict[str, Any]:
@@ -36,6 +36,7 @@ class RedisStreamsExporter(ITradeDataExport):
36
36
  max_stream_length: int = 1000,
37
37
  formatter: Optional[IExportFormatter] = None,
38
38
  max_workers: int = 2,
39
+ account: Optional[IAccountViewer] = None,
39
40
  ):
40
41
  """
41
42
  Initialize the Redis Streams Exporter.
@@ -52,6 +53,7 @@ class RedisStreamsExporter(ITradeDataExport):
52
53
  max_stream_length: Maximum length of each stream
53
54
  formatter: Formatter to use for formatting data (default: DefaultFormatter)
54
55
  max_workers: Maximum number of worker threads for Redis operations
56
+ account: Optional account viewer to get account information like total capital, leverage, etc.
55
57
  """
56
58
  self._redis = redis.from_url(redis_url)
57
59
  self._strategy_name = strategy_name
@@ -71,6 +73,9 @@ class RedisStreamsExporter(ITradeDataExport):
71
73
 
72
74
  self._executor = ThreadPoolExecutor(max_workers=max_workers, thread_name_prefix="redis_exporter")
73
75
 
76
+ if account:
77
+ self._instrument_to_previous_leverage = dict(account.get_leverages())
78
+
74
79
  logger.info(
75
80
  f"[RedisStreamsExporter] Initialized for strategy '{strategy_name}' with "
76
81
  f"signals: {export_signals}, targets: {export_targets}, position_changes: {export_position_changes}"
@@ -201,6 +206,7 @@ class RedisStreamsExporter(ITradeDataExport):
201
206
 
202
207
  previous_leverage = self._instrument_to_previous_leverage.get(instrument, 0.0)
203
208
  new_leverage = account.get_leverage(instrument)
209
+ self._instrument_to_previous_leverage[instrument] = new_leverage
204
210
 
205
211
  try:
206
212
  # Format the leverage change using the formatter
@@ -4,10 +4,10 @@ Factory functions for creating various components used in strategy running and s
4
4
 
5
5
  import inspect
6
6
  import os
7
- from typing import Any
7
+ from typing import Any, Optional
8
8
 
9
9
  from qubx import logger
10
- from qubx.core.interfaces import IMetricEmitter, IStrategyLifecycleNotifier, ITradeDataExport
10
+ from qubx.core.interfaces import IAccountViewer, IMetricEmitter, IStrategyLifecycleNotifier, ITradeDataExport
11
11
  from qubx.data.composite import CompositeReader
12
12
  from qubx.data.readers import DataReader
13
13
  from qubx.emitters.composite import CompositeMetricEmitter
@@ -180,7 +180,11 @@ def create_data_type_readers(readers_configs: list[TypedReaderConfig] | None) ->
180
180
  return data_type_to_reader
181
181
 
182
182
 
183
- def create_exporters(exporters: list[ExporterConfig] | None, strategy_name: str) -> ITradeDataExport | None:
183
+ def create_exporters(
184
+ exporters: list[ExporterConfig] | None,
185
+ strategy_name: str,
186
+ account: Optional[IAccountViewer] = None,
187
+ ) -> ITradeDataExport | None:
184
188
  """
185
189
  Create exporters from the configuration.
186
190
 
@@ -218,6 +222,9 @@ def create_exporters(exporters: list[ExporterConfig] | None, strategy_name: str)
218
222
  for fmt_key, fmt_value in formatter_args.items():
219
223
  formatter_args[fmt_key] = resolve_env_vars(fmt_value)
220
224
 
225
+ if account and "account" not in formatter_args:
226
+ formatter_args["account"] = account
227
+
221
228
  if formatter_class_name:
222
229
  if "." not in formatter_class_name:
223
230
  formatter_class_name = f"qubx.exporters.formatters.{formatter_class_name}"
@@ -229,6 +236,8 @@ def create_exporters(exporters: list[ExporterConfig] | None, strategy_name: str)
229
236
  # Add strategy_name if the exporter requires it and it's not already provided
230
237
  if "strategy_name" in inspect.signature(exporter_class).parameters and "strategy_name" not in params:
231
238
  params["strategy_name"] = strategy_name
239
+ if account and "account" not in params:
240
+ params["account"] = account
232
241
 
233
242
  # Create the exporter instance
234
243
  exporter = exporter_class(**params)
@@ -261,9 +261,6 @@ def create_strategy_context(
261
261
 
262
262
  _aux_reader = construct_reader(config.aux) if config.aux else None
263
263
 
264
- # Create exporters if configured
265
- _exporter = create_exporters(config.exporters, stg_name)
266
-
267
264
  # Create metric emitters
268
265
  _metric_emitter = create_metric_emitters(config.emission, stg_name) if config.emission else None
269
266
 
@@ -335,6 +332,9 @@ def create_strategy_context(
335
332
  )
336
333
  _initializer = BasicStrategyInitializer(simulation=_exchange_to_data_provider[exchanges[0]].is_simulation)
337
334
 
335
+ # Create exporters if configured
336
+ _exporter = create_exporters(config.exporters, stg_name, _account)
337
+
338
338
  logger.info(f"- Strategy: <blue>{stg_name}</blue>\n- Mode: {_run_mode}\n- Parameters: {config.parameters}")
339
339
  ctx = StrategyContext(
340
340
  strategy=_strategy_class, # type: ignore
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: Qubx
3
- Version: 0.6.41
3
+ Version: 0.6.42
4
4
  Summary: Qubx - Quantitative Trading Framework
5
5
  Author: Dmitry Marienko
6
6
  Author-email: dmitry.marienko@xlydian.com
@@ -52,11 +52,11 @@ qubx/core/mixins/processing.py,sha256=cmjD0PcQv3gFP6oILfNgdNgw7Tez0fUZu_nFn6680V
52
52
  qubx/core/mixins/subscription.py,sha256=V_g9wCPQ8S5SHkU-qOZ84cV5nReAUrV7DoSNAGG0LPY,10372
53
53
  qubx/core/mixins/trading.py,sha256=idfRPaqrvkfMxzu9mXr9i_xfqLee-ZAOrERxkxv6Ruo,7256
54
54
  qubx/core/mixins/universe.py,sha256=L3s2Jw46_J1iDh4622Gk_LvCjol4W7mflBwEHrLfZEw,9899
55
- qubx/core/series.cpython-312-x86_64-linux-gnu.so,sha256=kaqGuSydE041VcwqUyHpIybK27yE1g-INOtDP1zfI8Q,978280
55
+ qubx/core/series.cpython-312-x86_64-linux-gnu.so,sha256=8DijkxPrz0lEvZCp81RfOj5oaxVt_0YTq0ihU5UtIVs,978280
56
56
  qubx/core/series.pxd,sha256=jBdMwgO8J4Zrue0e_xQ5RlqTXqihpzQNu6V3ckZvvpY,3978
57
57
  qubx/core/series.pyi,sha256=RaHm_oHHiWiNUMJqVfx5FXAXniGLsHxUFOUpacn7GC0,4604
58
58
  qubx/core/series.pyx,sha256=7cM3zZThW59waHiYcZmMxvYj-HYD7Ej_l7nKA4emPjE,46477
59
- qubx/core/utils.cpython-312-x86_64-linux-gnu.so,sha256=LWgrhKGrBQ7wFwPPHwZgjqPZxcRLzq81z0x3B1iiBE0,86568
59
+ qubx/core/utils.cpython-312-x86_64-linux-gnu.so,sha256=pP6PczrIK0qymrZDt2sywmhnkhCZqyPpzxT_4680uFU,86568
60
60
  qubx/core/utils.pyi,sha256=a-wS13V2p_dM1CnGq40JVulmiAhixTwVwt0ah5By0Hc,348
61
61
  qubx/core/utils.pyx,sha256=k5QHfEFvqhqWfCob89ANiJDKNG8gGbOh-O4CVoneZ8M,1696
62
62
  qubx/data/__init__.py,sha256=ELZykvpPGWc5rX7QoNyNQwMLgdKMG8MACOByA4pM5hA,549
@@ -76,9 +76,9 @@ qubx/exporters/__init__.py,sha256=7HeYHCZfKAaBVAByx9wE8DyGv6C55oeED9uUphcyjuc,36
76
76
  qubx/exporters/composite.py,sha256=c45XcMC0dsIDwOyOxxCuiyYQjUNhqPjptAulbaSqttU,2973
77
77
  qubx/exporters/formatters/__init__.py,sha256=La9rMsl3wyplza0xVyAFrUwhFyrGDIMJWmOB_boJyIg,488
78
78
  qubx/exporters/formatters/base.py,sha256=j381c-JgjUnUHJF7k1J1MPeHB0sFDC9xNcFt2jZNhNY,5671
79
- qubx/exporters/formatters/incremental.py,sha256=tzjD4eWzane_MqCI_s9EFMy4ZurLwWqpL0Uaitv-wS4,4918
79
+ qubx/exporters/formatters/incremental.py,sha256=06r7LId5LoZD5VY7V0VQE4q3h2t4VxlP2SgF8j3xua0,5209
80
80
  qubx/exporters/formatters/slack.py,sha256=MPjbEFh7PQufPdkg_Fwiu2tVw5zYJa977tCemoI790Y,7017
81
- qubx/exporters/redis_streams.py,sha256=8Cd39kAXUYSOS6-dQMSm1PpeQ4urOGVq0oe3dAXwUEI,8924
81
+ qubx/exporters/redis_streams.py,sha256=ywbZrrqJDbMmV4QIW_XHBFh8NZu8gbOb47P3WH6UXIk,9257
82
82
  qubx/exporters/slack.py,sha256=wnVZRwWOKq9lMQyW0MWh_6gkW1id1TUanfOKy-_clwI,7723
83
83
  qubx/features/__init__.py,sha256=ZFCX7K5bDAH7yTsG-mf8zibW8UW8GCneEagL1_p8kDQ,385
84
84
  qubx/features/core.py,sha256=eXa1qIu-LXo40td1X4EUBFQ5jJcSTuaQIi-562bPCoM,10587
@@ -123,7 +123,7 @@ qubx/restorers/signal.py,sha256=9TAaJOEKPjZXuciFFVn6Z8a-Z8CfVSjRGFRcwEgbPLY,1074
123
123
  qubx/restorers/state.py,sha256=dLaVnUwRCNRkUqbYyi0RfZs3Q3AdglkI_qTtQ8GDD5Y,7289
124
124
  qubx/restorers/utils.py,sha256=We2gfqwQKWziUYhuUnjb-xo-5tSlbuHWpPQn0CEMTn0,1155
125
125
  qubx/ta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
126
- qubx/ta/indicators.cpython-312-x86_64-linux-gnu.so,sha256=CCvVqxcz64fK-Am57qTJzknn3CNYY-8PFEHlRgj7RTI,654440
126
+ qubx/ta/indicators.cpython-312-x86_64-linux-gnu.so,sha256=NK4SU3DKjt9hjTM0N2_8zuGDYH8lZiLEMtOL3c4saog,654440
127
127
  qubx/ta/indicators.pxd,sha256=Goo0_N0Xnju8XGo3Xs-3pyg2qr_0Nh5C-_26DK8U_IE,4224
128
128
  qubx/ta/indicators.pyi,sha256=19W0uERft49In5bf9jkJHkzJYEyE9gzudN7_DJ5Vdv8,1963
129
129
  qubx/ta/indicators.pyx,sha256=Xgpew46ZxSXsdfSEWYn3A0Q35MLsopB9n7iyCsXTufs,25969
@@ -156,12 +156,12 @@ qubx/utils/runner/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
156
156
  qubx/utils/runner/_jupyter_runner.pyt,sha256=fDj4AUs25jsdGmY9DDeSFufH1JkVhLFwy0BOmVO7nIU,9609
157
157
  qubx/utils/runner/accounts.py,sha256=mpiv6oxr5z97zWt7STYyARMhWQIpc_XFKungb_pX38U,3270
158
158
  qubx/utils/runner/configs.py,sha256=nxIelzfHtv7GagkEHBJ6mRm_30jmBa6pSPujL-k0uqo,3749
159
- qubx/utils/runner/factory.py,sha256=Mh_soHKci7Xj5uYI3vhxzXkrPUm2Z-Cq3PGC6w3KCUY,14620
160
- qubx/utils/runner/runner.py,sha256=egv4OtPwEIwG0-Ia3ai9E9MYQIaslZLyoT4tL1FxQcY,28891
159
+ qubx/utils/runner/factory.py,sha256=8IxKvsEL0opx5OlO4XEQgAlmu05sgxXxkY4G2MQdLbg,14941
160
+ qubx/utils/runner/runner.py,sha256=DhICMOfgE0i7VEC7pNMSEzIyZbb-TbOa6FbR1obZpyc,28901
161
161
  qubx/utils/time.py,sha256=J0ZFGjzFL5T6GA8RPAel8hKG0sg2LZXeQ5YfDCfcMHA,10055
162
162
  qubx/utils/version.py,sha256=e52fIHyxzCiIuH7svCF6pkHuDlqL64rklqz-2XjWons,5309
163
- qubx-0.6.41.dist-info/LICENSE,sha256=qwMHOSJ2TD0nx6VUJvFhu1ynJdBfNozRMt6tnSul-Ts,35140
164
- qubx-0.6.41.dist-info/METADATA,sha256=TdDDd1n1SALzg1jwDaAG153aD7-MqDAJh40T--FQ-4c,4492
165
- qubx-0.6.41.dist-info/WHEEL,sha256=UckHTmFUCaLKpi4yFY8Dewu0c6XkY-KvEAGzGOnaWo8,110
166
- qubx-0.6.41.dist-info/entry_points.txt,sha256=VqilDTe8mVuV9SbR-yVlZJBTjbkHIL2JBgXfQw076HY,47
167
- qubx-0.6.41.dist-info/RECORD,,
163
+ qubx-0.6.42.dist-info/LICENSE,sha256=qwMHOSJ2TD0nx6VUJvFhu1ynJdBfNozRMt6tnSul-Ts,35140
164
+ qubx-0.6.42.dist-info/METADATA,sha256=IimoSRSYNj-wJp_LKP7T4Gr0OVu_9Wuxo7Pm2unbjp4,4492
165
+ qubx-0.6.42.dist-info/WHEEL,sha256=UckHTmFUCaLKpi4yFY8Dewu0c6XkY-KvEAGzGOnaWo8,110
166
+ qubx-0.6.42.dist-info/entry_points.txt,sha256=VqilDTe8mVuV9SbR-yVlZJBTjbkHIL2JBgXfQw076HY,47
167
+ qubx-0.6.42.dist-info/RECORD,,
File without changes
File without changes