PyAlgoEngine 0.7.4__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.
Files changed (43) hide show
  1. PyAlgoEngine-0.7.4.dist-info/LICENSE +21 -0
  2. PyAlgoEngine-0.7.4.dist-info/METADATA +27 -0
  3. PyAlgoEngine-0.7.4.dist-info/RECORD +43 -0
  4. PyAlgoEngine-0.7.4.dist-info/WHEEL +5 -0
  5. PyAlgoEngine-0.7.4.dist-info/top_level.txt +1 -0
  6. algo_engine/__init__.py +41 -0
  7. algo_engine/apps/__init__.py +17 -0
  8. algo_engine/apps/backtest/__init__.py +20 -0
  9. algo_engine/apps/backtest/doc_server.py +331 -0
  10. algo_engine/apps/backtest/tester.py +254 -0
  11. algo_engine/apps/backtest/web_app.py +127 -0
  12. algo_engine/apps/bokeh_server.py +205 -0
  13. algo_engine/apps/demo/__init__.py +0 -0
  14. algo_engine/apps/demo/test.py +39 -0
  15. algo_engine/backtest/__init__.py +19 -0
  16. algo_engine/backtest/__main__.py +51 -0
  17. algo_engine/backtest/metrics.py +179 -0
  18. algo_engine/backtest/replay.py +261 -0
  19. algo_engine/backtest/sim_match.py +295 -0
  20. algo_engine/base/__init__.py +40 -0
  21. algo_engine/base/console_utils.py +1070 -0
  22. algo_engine/base/finance_decimal.py +258 -0
  23. algo_engine/base/market_buffer.py +571 -0
  24. algo_engine/base/market_utils.py +3092 -0
  25. algo_engine/base/market_utils_nt.py +188 -0
  26. algo_engine/base/market_utils_posix.py +3004 -0
  27. algo_engine/base/technical_analysis.py +406 -0
  28. algo_engine/base/telemetrics.py +78 -0
  29. algo_engine/base/trade_utils.py +709 -0
  30. algo_engine/engine/__init__.py +28 -0
  31. algo_engine/engine/algo_engine.py +901 -0
  32. algo_engine/engine/event_engine.py +53 -0
  33. algo_engine/engine/market_engine.py +370 -0
  34. algo_engine/engine/trade_engine.py +2037 -0
  35. algo_engine/monitor/__init__.py +15 -0
  36. algo_engine/monitor/advanced_data_interface.py +239 -0
  37. algo_engine/profile/__init__.py +121 -0
  38. algo_engine/profile/cn.py +175 -0
  39. algo_engine/strategy/__init__.py +44 -0
  40. algo_engine/strategy/strategy_engine.py +440 -0
  41. algo_engine/utils/__init__.py +3 -0
  42. algo_engine/utils/commit_regularizer.py +49 -0
  43. algo_engine/utils/data_utils.py +251 -0
@@ -0,0 +1,188 @@
1
+ import ctypes
2
+ import os
3
+ import platform
4
+
5
+ from . import LOGGER
6
+ from . import market_utils_posix
7
+ from .market_utils_posix import Contexts, BufferConstructor as _BufferConstructor
8
+ from .market_utils_posix import TransactionSide, OrderType, MarketData, OrderBook, BarData, DailyBar, CandleStick, TickData, TransactionData, TradeData, OrderData, MarketDataBuffer, MarketDataRingBuffer
9
+
10
+ LOGGER = LOGGER.getChild('MarketUtils')
11
+ __all__ = ['TransactionSide', 'OrderType',
12
+ 'MarketData', 'OrderBook', 'BarData', 'DailyBar', 'CandleStick', 'TickData', 'TransactionData', 'TradeData', 'OrderData',
13
+ 'MarketDataBuffer', 'MarketDataRingBuffer']
14
+ __cache__ = {}
15
+
16
+ if os.name == 'nt':
17
+ LOGGER.warning(f'MarketUtils support for {platform.system()}-{platform.release()}-{platform.machine()} is limited! Setting contents will have no effect!')
18
+
19
+
20
+ class _OrderBookBuffer(ctypes.Structure):
21
+ ticker_size = Contexts.TICKER_SIZE
22
+ book_size = Contexts.BOOK_SIZE
23
+
24
+ _fields_ = [
25
+ ("dtype", ctypes.c_uint8),
26
+ ("ticker", ctypes.c_char * ticker_size),
27
+ ("timestamp", ctypes.c_double),
28
+ ('bid_price', ctypes.c_double * book_size),
29
+ ('ask_price', ctypes.c_double * book_size),
30
+ ('bid_volume', ctypes.c_double * book_size),
31
+ ('ask_volume', ctypes.c_double * book_size),
32
+ ('bid_n_orders', ctypes.c_uint * book_size),
33
+ ('ask_n_orders', ctypes.c_uint * book_size)
34
+ ]
35
+
36
+
37
+ class _CandlestickBuffer(ctypes.Structure):
38
+ ticker_size = Contexts.TICKER_SIZE
39
+
40
+ _fields_ = [
41
+ ("dtype", ctypes.c_uint8),
42
+ ("ticker", ctypes.c_char * ticker_size),
43
+ ("timestamp", ctypes.c_double),
44
+ ('start_timestamp', ctypes.c_double),
45
+ ('bar_span', ctypes.c_double),
46
+ ('high_price', ctypes.c_double),
47
+ ('low_price', ctypes.c_double),
48
+ ('open_price', ctypes.c_double),
49
+ ('close_price', ctypes.c_double),
50
+ ('volume', ctypes.c_double),
51
+ ('notional', ctypes.c_double),
52
+ ('trade_count', ctypes.c_uint),
53
+ ]
54
+
55
+
56
+ class _TickDataBuffer(ctypes.Structure):
57
+ ticker_size = Contexts.TICKER_SIZE
58
+
59
+ _fields_ = [
60
+ ("dtype", ctypes.c_uint8),
61
+ ("ticker", ctypes.c_char * ticker_size),
62
+ ("timestamp", ctypes.c_double),
63
+ ('order_book', _OrderBookBuffer),
64
+ ('bid_price', ctypes.c_double),
65
+ ('bid_volume', ctypes.c_double),
66
+ ('ask_price', ctypes.c_double),
67
+ ('ask_volume', ctypes.c_double),
68
+ ('last_price', ctypes.c_double),
69
+ ('total_traded_volume', ctypes.c_double),
70
+ ('total_traded_notional', ctypes.c_double),
71
+ ('total_trade_count', ctypes.c_uint),
72
+ ]
73
+
74
+
75
+ class IntID(ctypes.Structure):
76
+ id_size = Contexts.ID_SIZE
77
+
78
+ _fields_ = [
79
+ ('id_type', ctypes.c_int),
80
+ ('data', ctypes.c_byte * id_size),
81
+ ]
82
+
83
+
84
+ class StrID(ctypes.Structure):
85
+ id_size = Contexts.ID_SIZE
86
+
87
+ _fields_ = [
88
+ ('id_type', ctypes.c_int),
89
+ ('data', ctypes.c_char * id_size),
90
+ ]
91
+
92
+
93
+ class UnionID(ctypes.Union):
94
+ id_size = Contexts.ID_SIZE
95
+
96
+ _fields_ = [
97
+ ('id_type', ctypes.c_int),
98
+ ('id_int', IntID),
99
+ ('id_str', StrID),
100
+ ]
101
+
102
+
103
+ class _TransactionDataBuffer(ctypes.Structure):
104
+ ticker_size = Contexts.TICKER_SIZE
105
+ id_size = Contexts.ID_SIZE
106
+
107
+ _fields_ = [
108
+ ("dtype", ctypes.c_uint8),
109
+ ("ticker", ctypes.c_char * ticker_size), # Dynamic size based on TICKER_LEN
110
+ ("timestamp", ctypes.c_double),
111
+ ("price", ctypes.c_double),
112
+ ("volume", ctypes.c_double),
113
+ ("side", ctypes.c_int),
114
+ ("multiplier", ctypes.c_double),
115
+ ("notional", ctypes.c_double),
116
+ ("transaction_id", UnionID),
117
+ ("buy_id", UnionID),
118
+ ("sell_id", UnionID)
119
+ ]
120
+
121
+
122
+ class _OrderDataBuffer(ctypes.Structure):
123
+ ticker_size = Contexts.TICKER_SIZE
124
+ id_size = Contexts.ID_SIZE
125
+
126
+ _fields_ = [
127
+ ("dtype", ctypes.c_uint8),
128
+ ("ticker", ctypes.c_char * ticker_size), # Dynamic size based on TICKER_LEN
129
+ ("timestamp", ctypes.c_double),
130
+ ("price", ctypes.c_double),
131
+ ("volume", ctypes.c_double),
132
+ ("side", ctypes.c_int),
133
+ ("order_id", UnionID),
134
+ ("order_type", ctypes.c_int),
135
+ ]
136
+
137
+
138
+ class _MarketDataBuffer(ctypes.Union):
139
+ _fields_ = [
140
+ ("dtype", ctypes.c_uint8),
141
+ ("OrderBook", _OrderBookBuffer),
142
+ ("BarData", _CandlestickBuffer),
143
+ ("TickData", _TickDataBuffer),
144
+ ("TransactionData", _TransactionDataBuffer),
145
+ ('OrderData', _OrderDataBuffer())
146
+ ]
147
+
148
+
149
+ class BufferConstructor(_BufferConstructor):
150
+ def __init__(self, **kwargs):
151
+ pass
152
+
153
+ def __call__(self, dtype: 'str') -> type[ctypes.Structure]:
154
+ match dtype:
155
+ case 'MarketData':
156
+ return self.new_market_data_buffer()
157
+ case 'OrderBook':
158
+ return self.new_orderbook_buffer()
159
+ case 'BarData':
160
+ return self.new_candlestick_buffer()
161
+ case 'TickData':
162
+ return self.new_tick_buffer()
163
+ case 'TradeData' | 'TransactionData':
164
+ return self.new_transaction_buffer()
165
+ case _:
166
+ raise ValueError(f'Invalid dtype {dtype}')
167
+
168
+ def new_orderbook_buffer(self) -> type[ctypes.Structure]:
169
+ return _OrderBookBuffer
170
+
171
+ def new_candlestick_buffer(self) -> type[ctypes.Structure]:
172
+ return _CandlestickBuffer
173
+
174
+ def new_tick_buffer(self) -> type[ctypes.Structure]:
175
+ return _TickDataBuffer
176
+
177
+ def new_transaction_buffer(self) -> type[ctypes.Structure]:
178
+ return _TransactionDataBuffer
179
+
180
+ def new_order_buffer(self) -> type[ctypes.Structure]:
181
+ return _OrderDataBuffer
182
+
183
+ def new_market_data_buffer(self) -> type[ctypes.Union]:
184
+ return _MarketDataBuffer
185
+
186
+
187
+ market_utils_posix._BUFFER_CONSTRUCTOR = BufferConstructor()
188
+ MarketDataBuffer.ctype_buffer = _MarketDataBuffer