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.
- walrasquant/__init__.py +7 -0
- walrasquant/aggregation.py +449 -0
- walrasquant/backends/__init__.py +5 -0
- walrasquant/backends/db.py +109 -0
- walrasquant/backends/db_memory.py +61 -0
- walrasquant/backends/db_postgresql.py +321 -0
- walrasquant/backends/db_sqlite.py +310 -0
- walrasquant/base/__init__.py +24 -0
- walrasquant/base/api_client.py +46 -0
- walrasquant/base/connector.py +863 -0
- walrasquant/base/ems.py +794 -0
- walrasquant/base/exchange.py +213 -0
- walrasquant/base/oms.py +428 -0
- walrasquant/base/retry.py +220 -0
- walrasquant/base/sms.py +545 -0
- walrasquant/base/ws_client.py +408 -0
- walrasquant/config.py +284 -0
- walrasquant/constants.py +413 -0
- walrasquant/core/__init__.py +0 -0
- walrasquant/core/cache.py +688 -0
- walrasquant/core/clock.py +59 -0
- walrasquant/core/connection.py +41 -0
- walrasquant/core/entity.py +504 -0
- walrasquant/core/nautilius_core.py +103 -0
- walrasquant/core/registry.py +41 -0
- walrasquant/engine.py +745 -0
- walrasquant/error.py +34 -0
- walrasquant/exchange/__init__.py +13 -0
- walrasquant/exchange/base_factory.py +172 -0
- walrasquant/exchange/binance/__init__.py +30 -0
- walrasquant/exchange/binance/connector.py +1093 -0
- walrasquant/exchange/binance/constants.py +934 -0
- walrasquant/exchange/binance/ems.py +140 -0
- walrasquant/exchange/binance/error.py +48 -0
- walrasquant/exchange/binance/exchange.py +144 -0
- walrasquant/exchange/binance/factory.py +115 -0
- walrasquant/exchange/binance/oms.py +1807 -0
- walrasquant/exchange/binance/rest_api.py +1653 -0
- walrasquant/exchange/binance/schema.py +1063 -0
- walrasquant/exchange/binance/websockets.py +389 -0
- walrasquant/exchange/bitget/__init__.py +28 -0
- walrasquant/exchange/bitget/connector.py +578 -0
- walrasquant/exchange/bitget/constants.py +392 -0
- walrasquant/exchange/bitget/ems.py +202 -0
- walrasquant/exchange/bitget/error.py +36 -0
- walrasquant/exchange/bitget/exchange.py +128 -0
- walrasquant/exchange/bitget/factory.py +135 -0
- walrasquant/exchange/bitget/oms.py +1619 -0
- walrasquant/exchange/bitget/rest_api.py +610 -0
- walrasquant/exchange/bitget/schema.py +885 -0
- walrasquant/exchange/bitget/websockets.py +753 -0
- walrasquant/exchange/bybit/__init__.py +32 -0
- walrasquant/exchange/bybit/connector.py +819 -0
- walrasquant/exchange/bybit/constants.py +479 -0
- walrasquant/exchange/bybit/ems.py +93 -0
- walrasquant/exchange/bybit/error.py +36 -0
- walrasquant/exchange/bybit/exchange.py +108 -0
- walrasquant/exchange/bybit/factory.py +128 -0
- walrasquant/exchange/bybit/oms.py +1195 -0
- walrasquant/exchange/bybit/rest_api.py +570 -0
- walrasquant/exchange/bybit/schema.py +867 -0
- walrasquant/exchange/bybit/websockets.py +307 -0
- walrasquant/exchange/hyperliquid/__init__.py +28 -0
- walrasquant/exchange/hyperliquid/connector.py +370 -0
- walrasquant/exchange/hyperliquid/constants.py +371 -0
- walrasquant/exchange/hyperliquid/ems.py +156 -0
- walrasquant/exchange/hyperliquid/error.py +48 -0
- walrasquant/exchange/hyperliquid/exchange.py +120 -0
- walrasquant/exchange/hyperliquid/factory.py +135 -0
- walrasquant/exchange/hyperliquid/oms.py +1081 -0
- walrasquant/exchange/hyperliquid/rest_api.py +348 -0
- walrasquant/exchange/hyperliquid/schema.py +583 -0
- walrasquant/exchange/hyperliquid/websockets.py +592 -0
- walrasquant/exchange/okx/__init__.py +25 -0
- walrasquant/exchange/okx/connector.py +931 -0
- walrasquant/exchange/okx/constants.py +518 -0
- walrasquant/exchange/okx/ems.py +144 -0
- walrasquant/exchange/okx/error.py +66 -0
- walrasquant/exchange/okx/exchange.py +102 -0
- walrasquant/exchange/okx/factory.py +138 -0
- walrasquant/exchange/okx/oms.py +1199 -0
- walrasquant/exchange/okx/rest_api.py +799 -0
- walrasquant/exchange/okx/schema.py +1449 -0
- walrasquant/exchange/okx/websockets.py +420 -0
- walrasquant/exchange/registry.py +201 -0
- walrasquant/execution/__init__.py +24 -0
- walrasquant/execution/algorithm.py +968 -0
- walrasquant/execution/algorithms/__init__.py +3 -0
- walrasquant/execution/algorithms/twap.py +392 -0
- walrasquant/execution/config.py +34 -0
- walrasquant/execution/constants.py +27 -0
- walrasquant/execution/schema.py +62 -0
- walrasquant/indicator.py +382 -0
- walrasquant/push.py +77 -0
- walrasquant/schema.py +755 -0
- walrasquant/strategy.py +1805 -0
- walrasquant/tools/__init__.py +0 -0
- walrasquant/tools/pm2_wrapper.py +1016 -0
- walrasquant/web/__init__.py +26 -0
- walrasquant/web/app.py +157 -0
- walrasquant/web/server.py +92 -0
- walrasquant_lib-0.4.20.dist-info/METADATA +162 -0
- walrasquant_lib-0.4.20.dist-info/RECORD +105 -0
- walrasquant_lib-0.4.20.dist-info/WHEEL +4 -0
- walrasquant_lib-0.4.20.dist-info/entry_points.txt +3 -0
walrasquant/error.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
class NexusTraderError(Exception):
|
|
2
|
+
def __init__(self, message: str):
|
|
3
|
+
self.message = message
|
|
4
|
+
super().__init__(self.message)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class EngineBuildError(NexusTraderError):
|
|
8
|
+
def __init__(self, message: str):
|
|
9
|
+
super().__init__(message)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SubscriptionError(NexusTraderError):
|
|
13
|
+
def __init__(self, message: str):
|
|
14
|
+
super().__init__(message)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class KlineSupportedError(NexusTraderError):
|
|
18
|
+
def __init__(self, message: str):
|
|
19
|
+
super().__init__(message)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class StrategyBuildError(NexusTraderError):
|
|
23
|
+
def __init__(self, message: str):
|
|
24
|
+
super().__init__(message)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class OrderError(NexusTraderError):
|
|
28
|
+
def __init__(self, message: str):
|
|
29
|
+
super().__init__(message)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class PositionModeError(NexusTraderError):
|
|
33
|
+
def __init__(self, message: str):
|
|
34
|
+
super().__init__(message)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from walrasquant.exchange.binance import BinanceAccountType
|
|
2
|
+
from walrasquant.exchange.bybit import BybitAccountType
|
|
3
|
+
from walrasquant.exchange.okx import OkxAccountType
|
|
4
|
+
from walrasquant.exchange.hyperliquid import HyperLiquidAccountType
|
|
5
|
+
from walrasquant.exchange.bitget import BitgetAccountType
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"BinanceAccountType",
|
|
9
|
+
"BybitAccountType",
|
|
10
|
+
"OkxAccountType",
|
|
11
|
+
"HyperLiquidAccountType",
|
|
12
|
+
"BitgetAccountType",
|
|
13
|
+
]
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Base factory interface for exchange components.
|
|
3
|
+
|
|
4
|
+
This module defines the abstract base class and context for creating exchange-specific
|
|
5
|
+
components in a standardized way.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from abc import ABC, abstractmethod
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from typing import Any, Optional
|
|
11
|
+
from walrasquant.constants import ExchangeType, AccountType
|
|
12
|
+
from walrasquant.core.entity import TaskManager
|
|
13
|
+
from walrasquant.base import (
|
|
14
|
+
ExchangeManager,
|
|
15
|
+
PublicConnector,
|
|
16
|
+
PrivateConnector,
|
|
17
|
+
ExecutionManagementSystem,
|
|
18
|
+
)
|
|
19
|
+
from walrasquant.config import (
|
|
20
|
+
PublicConnectorConfig,
|
|
21
|
+
PrivateConnectorConfig,
|
|
22
|
+
BasicConfig,
|
|
23
|
+
OrderQueryConfig,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass
|
|
28
|
+
class BuildContext:
|
|
29
|
+
"""Context object containing shared components for factory methods."""
|
|
30
|
+
|
|
31
|
+
msgbus: Any
|
|
32
|
+
clock: Any
|
|
33
|
+
task_manager: TaskManager
|
|
34
|
+
cache: Any
|
|
35
|
+
registry: Any # OrderRegistry
|
|
36
|
+
order_query_config: OrderQueryConfig
|
|
37
|
+
queue_maxsize: int = 0
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class ExchangeFactory(ABC):
|
|
41
|
+
"""
|
|
42
|
+
Abstract base class for creating exchange-specific components.
|
|
43
|
+
|
|
44
|
+
Each exchange should implement this factory to provide standardized
|
|
45
|
+
creation methods for all its components.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
@abstractmethod
|
|
50
|
+
def exchange_type(self) -> ExchangeType:
|
|
51
|
+
"""Return the exchange type this factory handles."""
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
@abstractmethod
|
|
55
|
+
def create_manager(self, basic_config: BasicConfig) -> ExchangeManager:
|
|
56
|
+
"""
|
|
57
|
+
Create an ExchangeManager instance.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
basic_config: Basic configuration containing API credentials
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
Configured ExchangeManager instance
|
|
64
|
+
"""
|
|
65
|
+
pass
|
|
66
|
+
|
|
67
|
+
@abstractmethod
|
|
68
|
+
def create_public_connector(
|
|
69
|
+
self,
|
|
70
|
+
config: PublicConnectorConfig,
|
|
71
|
+
exchange: ExchangeManager,
|
|
72
|
+
context: BuildContext,
|
|
73
|
+
) -> PublicConnector:
|
|
74
|
+
"""
|
|
75
|
+
Create a PublicConnector instance.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
config: Public connector configuration
|
|
79
|
+
exchange: Exchange manager instance
|
|
80
|
+
context: Build context with shared components
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
Configured PublicConnector instance
|
|
84
|
+
"""
|
|
85
|
+
pass
|
|
86
|
+
|
|
87
|
+
@abstractmethod
|
|
88
|
+
def create_private_connector(
|
|
89
|
+
self,
|
|
90
|
+
config: PrivateConnectorConfig,
|
|
91
|
+
exchange: ExchangeManager,
|
|
92
|
+
context: BuildContext,
|
|
93
|
+
account_type: Optional[AccountType] = None,
|
|
94
|
+
) -> PrivateConnector:
|
|
95
|
+
"""
|
|
96
|
+
Create a PrivateConnector instance.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
config: Private connector configuration
|
|
100
|
+
exchange: Exchange manager instance
|
|
101
|
+
context: Build context with shared components
|
|
102
|
+
account_type: Override account type (for testnet handling)
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
Configured PrivateConnector instance
|
|
106
|
+
"""
|
|
107
|
+
pass
|
|
108
|
+
|
|
109
|
+
@abstractmethod
|
|
110
|
+
def create_ems(
|
|
111
|
+
self, exchange: ExchangeManager, context: BuildContext
|
|
112
|
+
) -> ExecutionManagementSystem:
|
|
113
|
+
"""
|
|
114
|
+
Create an ExecutionManagementSystem instance.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
exchange: Exchange manager instance
|
|
118
|
+
context: Build context with shared components
|
|
119
|
+
|
|
120
|
+
Returns:
|
|
121
|
+
Configured ExecutionManagementSystem instance
|
|
122
|
+
"""
|
|
123
|
+
pass
|
|
124
|
+
|
|
125
|
+
def validate_config(self, basic_config: BasicConfig) -> None:
|
|
126
|
+
"""
|
|
127
|
+
Validate exchange-specific configuration.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
basic_config: Basic configuration to validate
|
|
131
|
+
|
|
132
|
+
Raises:
|
|
133
|
+
ValueError: If configuration is invalid
|
|
134
|
+
"""
|
|
135
|
+
# Default implementation - exchanges can override
|
|
136
|
+
pass
|
|
137
|
+
|
|
138
|
+
def get_private_account_type(
|
|
139
|
+
self, exchange: ExchangeManager, config: PrivateConnectorConfig
|
|
140
|
+
) -> AccountType:
|
|
141
|
+
"""
|
|
142
|
+
Determine the account type for private connector.
|
|
143
|
+
|
|
144
|
+
Some exchanges (like Bybit, OKX) map testnet to different account types.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
exchange: Exchange manager instance
|
|
148
|
+
config: Private connector configuration
|
|
149
|
+
|
|
150
|
+
Returns:
|
|
151
|
+
Account type to use
|
|
152
|
+
"""
|
|
153
|
+
return config.account_type
|
|
154
|
+
|
|
155
|
+
def setup_public_connector(
|
|
156
|
+
self,
|
|
157
|
+
exchange: ExchangeManager,
|
|
158
|
+
connector: PublicConnector,
|
|
159
|
+
account_type: AccountType,
|
|
160
|
+
) -> None:
|
|
161
|
+
"""
|
|
162
|
+
Perform any post-creation setup for public connector.
|
|
163
|
+
|
|
164
|
+
Some exchanges (like Bitget) need additional setup after creation.
|
|
165
|
+
|
|
166
|
+
Args:
|
|
167
|
+
exchange: Exchange manager instance
|
|
168
|
+
connector: Created public connector
|
|
169
|
+
account_type: Account type being used
|
|
170
|
+
"""
|
|
171
|
+
# Default implementation - exchanges can override
|
|
172
|
+
pass
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from walrasquant.exchange.binance.constants import BinanceAccountType
|
|
2
|
+
from walrasquant.exchange.binance.exchange import BinanceExchangeManager
|
|
3
|
+
from walrasquant.exchange.binance.connector import (
|
|
4
|
+
BinancePublicConnector,
|
|
5
|
+
BinancePrivateConnector,
|
|
6
|
+
)
|
|
7
|
+
from walrasquant.exchange.binance.rest_api import BinanceApiClient
|
|
8
|
+
from walrasquant.exchange.binance.ems import BinanceExecutionManagementSystem
|
|
9
|
+
from walrasquant.exchange.binance.oms import BinanceOrderManagementSystem
|
|
10
|
+
from walrasquant.exchange.binance.factory import BinanceFactory
|
|
11
|
+
|
|
12
|
+
# Auto-register factory on import
|
|
13
|
+
try:
|
|
14
|
+
from walrasquant.exchange.registry import register_factory
|
|
15
|
+
|
|
16
|
+
register_factory(BinanceFactory())
|
|
17
|
+
except ImportError:
|
|
18
|
+
# Registry not available yet during bootstrap
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"BinanceAccountType",
|
|
23
|
+
"BinanceExchangeManager",
|
|
24
|
+
"BinancePublicConnector",
|
|
25
|
+
"BinancePrivateConnector",
|
|
26
|
+
"BinanceApiClient",
|
|
27
|
+
"BinanceExecutionManagementSystem",
|
|
28
|
+
"BinanceOrderManagementSystem",
|
|
29
|
+
"BinanceFactory",
|
|
30
|
+
]
|