walrasquant-lib 0.4.20__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 (105) hide show
  1. walrasquant/__init__.py +7 -0
  2. walrasquant/aggregation.py +449 -0
  3. walrasquant/backends/__init__.py +5 -0
  4. walrasquant/backends/db.py +109 -0
  5. walrasquant/backends/db_memory.py +61 -0
  6. walrasquant/backends/db_postgresql.py +321 -0
  7. walrasquant/backends/db_sqlite.py +310 -0
  8. walrasquant/base/__init__.py +24 -0
  9. walrasquant/base/api_client.py +46 -0
  10. walrasquant/base/connector.py +863 -0
  11. walrasquant/base/ems.py +794 -0
  12. walrasquant/base/exchange.py +213 -0
  13. walrasquant/base/oms.py +428 -0
  14. walrasquant/base/retry.py +220 -0
  15. walrasquant/base/sms.py +545 -0
  16. walrasquant/base/ws_client.py +408 -0
  17. walrasquant/config.py +284 -0
  18. walrasquant/constants.py +413 -0
  19. walrasquant/core/__init__.py +0 -0
  20. walrasquant/core/cache.py +688 -0
  21. walrasquant/core/clock.py +59 -0
  22. walrasquant/core/connection.py +41 -0
  23. walrasquant/core/entity.py +504 -0
  24. walrasquant/core/nautilius_core.py +103 -0
  25. walrasquant/core/registry.py +41 -0
  26. walrasquant/engine.py +745 -0
  27. walrasquant/error.py +34 -0
  28. walrasquant/exchange/__init__.py +13 -0
  29. walrasquant/exchange/base_factory.py +172 -0
  30. walrasquant/exchange/binance/__init__.py +30 -0
  31. walrasquant/exchange/binance/connector.py +1093 -0
  32. walrasquant/exchange/binance/constants.py +934 -0
  33. walrasquant/exchange/binance/ems.py +140 -0
  34. walrasquant/exchange/binance/error.py +48 -0
  35. walrasquant/exchange/binance/exchange.py +144 -0
  36. walrasquant/exchange/binance/factory.py +115 -0
  37. walrasquant/exchange/binance/oms.py +1807 -0
  38. walrasquant/exchange/binance/rest_api.py +1653 -0
  39. walrasquant/exchange/binance/schema.py +1063 -0
  40. walrasquant/exchange/binance/websockets.py +389 -0
  41. walrasquant/exchange/bitget/__init__.py +28 -0
  42. walrasquant/exchange/bitget/connector.py +578 -0
  43. walrasquant/exchange/bitget/constants.py +392 -0
  44. walrasquant/exchange/bitget/ems.py +202 -0
  45. walrasquant/exchange/bitget/error.py +36 -0
  46. walrasquant/exchange/bitget/exchange.py +128 -0
  47. walrasquant/exchange/bitget/factory.py +135 -0
  48. walrasquant/exchange/bitget/oms.py +1619 -0
  49. walrasquant/exchange/bitget/rest_api.py +610 -0
  50. walrasquant/exchange/bitget/schema.py +885 -0
  51. walrasquant/exchange/bitget/websockets.py +753 -0
  52. walrasquant/exchange/bybit/__init__.py +32 -0
  53. walrasquant/exchange/bybit/connector.py +819 -0
  54. walrasquant/exchange/bybit/constants.py +479 -0
  55. walrasquant/exchange/bybit/ems.py +93 -0
  56. walrasquant/exchange/bybit/error.py +36 -0
  57. walrasquant/exchange/bybit/exchange.py +108 -0
  58. walrasquant/exchange/bybit/factory.py +128 -0
  59. walrasquant/exchange/bybit/oms.py +1195 -0
  60. walrasquant/exchange/bybit/rest_api.py +570 -0
  61. walrasquant/exchange/bybit/schema.py +867 -0
  62. walrasquant/exchange/bybit/websockets.py +307 -0
  63. walrasquant/exchange/hyperliquid/__init__.py +28 -0
  64. walrasquant/exchange/hyperliquid/connector.py +370 -0
  65. walrasquant/exchange/hyperliquid/constants.py +371 -0
  66. walrasquant/exchange/hyperliquid/ems.py +156 -0
  67. walrasquant/exchange/hyperliquid/error.py +48 -0
  68. walrasquant/exchange/hyperliquid/exchange.py +120 -0
  69. walrasquant/exchange/hyperliquid/factory.py +135 -0
  70. walrasquant/exchange/hyperliquid/oms.py +1081 -0
  71. walrasquant/exchange/hyperliquid/rest_api.py +348 -0
  72. walrasquant/exchange/hyperliquid/schema.py +583 -0
  73. walrasquant/exchange/hyperliquid/websockets.py +592 -0
  74. walrasquant/exchange/okx/__init__.py +25 -0
  75. walrasquant/exchange/okx/connector.py +931 -0
  76. walrasquant/exchange/okx/constants.py +518 -0
  77. walrasquant/exchange/okx/ems.py +144 -0
  78. walrasquant/exchange/okx/error.py +66 -0
  79. walrasquant/exchange/okx/exchange.py +102 -0
  80. walrasquant/exchange/okx/factory.py +138 -0
  81. walrasquant/exchange/okx/oms.py +1199 -0
  82. walrasquant/exchange/okx/rest_api.py +799 -0
  83. walrasquant/exchange/okx/schema.py +1449 -0
  84. walrasquant/exchange/okx/websockets.py +420 -0
  85. walrasquant/exchange/registry.py +201 -0
  86. walrasquant/execution/__init__.py +24 -0
  87. walrasquant/execution/algorithm.py +968 -0
  88. walrasquant/execution/algorithms/__init__.py +3 -0
  89. walrasquant/execution/algorithms/twap.py +392 -0
  90. walrasquant/execution/config.py +34 -0
  91. walrasquant/execution/constants.py +27 -0
  92. walrasquant/execution/schema.py +62 -0
  93. walrasquant/indicator.py +382 -0
  94. walrasquant/push.py +77 -0
  95. walrasquant/schema.py +755 -0
  96. walrasquant/strategy.py +1805 -0
  97. walrasquant/tools/__init__.py +0 -0
  98. walrasquant/tools/pm2_wrapper.py +1016 -0
  99. walrasquant/web/__init__.py +26 -0
  100. walrasquant/web/app.py +157 -0
  101. walrasquant/web/server.py +92 -0
  102. walrasquant_lib-0.4.20.dist-info/METADATA +162 -0
  103. walrasquant_lib-0.4.20.dist-info/RECORD +105 -0
  104. walrasquant_lib-0.4.20.dist-info/WHEEL +4 -0
  105. walrasquant_lib-0.4.20.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,135 @@
1
+ """
2
+ HyperLiquid exchange factory implementation.
3
+ """
4
+
5
+ from typing import cast
6
+
7
+ from walrasquant.constants import ExchangeType, AccountType, ConfigType
8
+ from walrasquant.config import (
9
+ PublicConnectorConfig,
10
+ PrivateConnectorConfig,
11
+ BasicConfig,
12
+ )
13
+ from walrasquant.exchange.base_factory import ExchangeFactory, BuildContext
14
+ from walrasquant.base import (
15
+ ExchangeManager,
16
+ PublicConnector,
17
+ PrivateConnector,
18
+ ExecutionManagementSystem,
19
+ )
20
+
21
+ from walrasquant.exchange.hyperliquid.exchange import HyperLiquidExchangeManager
22
+ from walrasquant.exchange.hyperliquid.connector import (
23
+ HyperLiquidPublicConnector,
24
+ HyperLiquidPrivateConnector,
25
+ )
26
+ from walrasquant.exchange.hyperliquid.ems import HyperLiquidExecutionManagementSystem
27
+ from walrasquant.exchange.hyperliquid.constants import HyperLiquidAccountType
28
+ from walrasquant.exchange.hyperliquid.schema import HyperLiquidMarket
29
+
30
+
31
+ class HyperLiquidFactory(ExchangeFactory):
32
+ """Factory for creating HyperLiquid exchange components."""
33
+
34
+ @property
35
+ def exchange_type(self) -> ExchangeType:
36
+ return ExchangeType.HYPERLIQUID
37
+
38
+ def create_manager(self, basic_config: BasicConfig) -> ExchangeManager:
39
+ """Create HyperLiquidExchangeManager."""
40
+ ccxt_config: ConfigType = {
41
+ "apiKey": basic_config.api_key or "",
42
+ "secret": basic_config.secret or "",
43
+ "exchange_id": "hyperliquid",
44
+ "sandbox": basic_config.testnet,
45
+ }
46
+ if basic_config.passphrase:
47
+ ccxt_config["password"] = basic_config.passphrase
48
+
49
+ return HyperLiquidExchangeManager(ccxt_config)
50
+
51
+ def create_public_connector(
52
+ self,
53
+ config: PublicConnectorConfig,
54
+ exchange: ExchangeManager,
55
+ context: BuildContext,
56
+ ) -> PublicConnector:
57
+ """Create HyperLiquidPublicConnector."""
58
+ if not isinstance(config.account_type, HyperLiquidAccountType):
59
+ raise TypeError(
60
+ "HyperLiquid public connector requires HyperLiquidAccountType"
61
+ )
62
+ connector = HyperLiquidPublicConnector(
63
+ account_type=config.account_type,
64
+ exchange=cast(HyperLiquidExchangeManager, exchange),
65
+ msgbus=context.msgbus,
66
+ clock=context.clock,
67
+ task_manager=context.task_manager,
68
+ enable_rate_limit=config.enable_rate_limit,
69
+ custom_url=config.custom_url,
70
+ max_subscriptions_per_client=config.max_subscriptions_per_client,
71
+ max_clients=config.max_clients,
72
+ )
73
+
74
+ # HyperLiquid needs post-creation setup
75
+ self.setup_public_connector(exchange, connector, config.account_type)
76
+ return connector
77
+
78
+ def create_private_connector(
79
+ self,
80
+ config: PrivateConnectorConfig,
81
+ exchange: ExchangeManager,
82
+ context: BuildContext,
83
+ account_type: AccountType | None = None,
84
+ ) -> PrivateConnector:
85
+ """Create HyperLiquidPrivateConnector."""
86
+ # Use provided account_type or fall back to config
87
+ final_account_type = account_type or config.account_type
88
+
89
+ if not isinstance(final_account_type, HyperLiquidAccountType):
90
+ raise TypeError(
91
+ "HyperLiquid private connector requires HyperLiquidAccountType"
92
+ )
93
+ return HyperLiquidPrivateConnector(
94
+ exchange=cast(HyperLiquidExchangeManager, exchange),
95
+ account_type=final_account_type,
96
+ cache=context.cache,
97
+ clock=context.clock,
98
+ msgbus=context.msgbus,
99
+ registry=context.registry,
100
+ enable_rate_limit=config.enable_rate_limit,
101
+ task_manager=context.task_manager,
102
+ max_slippage=config.max_slippage,
103
+ max_subscriptions_per_client=config.max_subscriptions_per_client,
104
+ max_clients=config.max_clients,
105
+ order_query_config=context.order_query_config,
106
+ )
107
+
108
+ def create_ems(
109
+ self, exchange: ExchangeManager, context: BuildContext
110
+ ) -> ExecutionManagementSystem:
111
+ """Create HyperLiquidExecutionManagementSystem."""
112
+ return HyperLiquidExecutionManagementSystem(
113
+ market=cast(dict[str, HyperLiquidMarket], exchange.market),
114
+ cache=context.cache,
115
+ msgbus=context.msgbus,
116
+ clock=context.clock,
117
+ task_manager=context.task_manager,
118
+ registry=context.registry,
119
+ queue_maxsize=context.queue_maxsize,
120
+ )
121
+
122
+ def setup_public_connector(
123
+ self,
124
+ exchange: ExchangeManager,
125
+ connector: PublicConnector,
126
+ account_type: AccountType,
127
+ ) -> None:
128
+ """Setup public connector account type."""
129
+ if not isinstance(account_type, HyperLiquidAccountType):
130
+ raise TypeError(
131
+ "HyperLiquid public connector requires HyperLiquidAccountType"
132
+ )
133
+ cast(HyperLiquidExchangeManager, exchange).set_public_connector_account_type(
134
+ account_type
135
+ )