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
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Public interface for strategy web integration."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .app import StrategyFastAPI, create_strategy_app
|
|
6
|
+
from .server import StrategyWebServer
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"StrategyFastAPI",
|
|
10
|
+
"StrategyWebServer",
|
|
11
|
+
"create_strategy_app",
|
|
12
|
+
"app",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def __getattr__(name: str) -> object:
|
|
17
|
+
"""Lazy-initialise the convenience ``app`` singleton on first access."""
|
|
18
|
+
if name == "app":
|
|
19
|
+
import sys
|
|
20
|
+
|
|
21
|
+
module = sys.modules[__name__]
|
|
22
|
+
instance = create_strategy_app()
|
|
23
|
+
# Cache so subsequent attribute access is O(1)
|
|
24
|
+
module.app = instance # type: ignore[attr-defined]
|
|
25
|
+
return instance
|
|
26
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
walrasquant/web/app.py
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""Strategy-aware FastAPI app utilities."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import inspect
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from functools import update_wrapper
|
|
8
|
+
from typing import Any, Callable, Dict, List, Optional
|
|
9
|
+
|
|
10
|
+
from fastapi import FastAPI
|
|
11
|
+
from fastapi.routing import APIRouter, APIRoute
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass
|
|
15
|
+
class _StrategyRoute:
|
|
16
|
+
path: str
|
|
17
|
+
endpoint: Callable[..., Any]
|
|
18
|
+
kwargs: Dict[str, Any]
|
|
19
|
+
bound_route: Optional[APIRoute] = None
|
|
20
|
+
bound_endpoint: Optional[Callable[..., Any]] = None
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class StrategyAPIRouter(APIRouter):
|
|
24
|
+
"""APIRouter that defers binding of strategy instance methods."""
|
|
25
|
+
|
|
26
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
27
|
+
super().__init__(*args, **kwargs)
|
|
28
|
+
self._strategy_routes: List[_StrategyRoute] = []
|
|
29
|
+
self._baseline_route_count = len(self.routes)
|
|
30
|
+
|
|
31
|
+
# when @app.post(...) is called, this method is invoked
|
|
32
|
+
def add_api_route(
|
|
33
|
+
self, path: str, endpoint: Callable[..., Any], **kwargs: Any
|
|
34
|
+
) -> None:
|
|
35
|
+
if self._is_strategy_endpoint(
|
|
36
|
+
endpoint
|
|
37
|
+
): # first parameter is 'self', indicating a method, save it to self._strategy_routes
|
|
38
|
+
self._strategy_routes.append(
|
|
39
|
+
_StrategyRoute(path=path, endpoint=endpoint, kwargs=dict(kwargs))
|
|
40
|
+
)
|
|
41
|
+
return None
|
|
42
|
+
return super().add_api_route(path, endpoint, **kwargs)
|
|
43
|
+
|
|
44
|
+
def bind_strategy(self, strategy: Any) -> None:
|
|
45
|
+
for route_def in self._strategy_routes:
|
|
46
|
+
self._remove_existing_route(route_def)
|
|
47
|
+
bound = self._wrap_endpoint(route_def.endpoint, strategy)
|
|
48
|
+
super().add_api_route(route_def.path, bound, **route_def.kwargs)
|
|
49
|
+
# Newly added route is the last item in self.routes
|
|
50
|
+
route_def.bound_route = self.routes[-1] # type: ignore[assignment]
|
|
51
|
+
route_def.bound_endpoint = bound
|
|
52
|
+
|
|
53
|
+
def unbind_strategy(self) -> None:
|
|
54
|
+
for route_def in self._strategy_routes:
|
|
55
|
+
if route_def.bound_route and route_def.bound_route in self.routes:
|
|
56
|
+
self.routes.remove(route_def.bound_route)
|
|
57
|
+
route_def.bound_route = None
|
|
58
|
+
route_def.bound_endpoint = None
|
|
59
|
+
|
|
60
|
+
def has_strategy_routes(self) -> bool:
|
|
61
|
+
return bool(self._strategy_routes)
|
|
62
|
+
|
|
63
|
+
def has_user_defined_routes(self) -> bool:
|
|
64
|
+
return (
|
|
65
|
+
self.has_strategy_routes() or len(self.routes) > self._baseline_route_count
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
@staticmethod
|
|
69
|
+
def _is_strategy_endpoint(endpoint: Callable[..., Any]) -> bool:
|
|
70
|
+
try:
|
|
71
|
+
signature = inspect.signature(endpoint)
|
|
72
|
+
except (TypeError, ValueError):
|
|
73
|
+
return False
|
|
74
|
+
|
|
75
|
+
params = list(signature.parameters.values())
|
|
76
|
+
if not params:
|
|
77
|
+
return False
|
|
78
|
+
return params[0].name == "self"
|
|
79
|
+
|
|
80
|
+
@staticmethod
|
|
81
|
+
def _wrap_endpoint(
|
|
82
|
+
endpoint: Callable[..., Any], strategy: Any
|
|
83
|
+
) -> Callable[..., Any]:
|
|
84
|
+
signature = inspect.signature(endpoint)
|
|
85
|
+
params = list(signature.parameters.values())
|
|
86
|
+
if not params or params[0].name != "self":
|
|
87
|
+
return endpoint
|
|
88
|
+
|
|
89
|
+
stripped_signature = signature.replace(parameters=params[1:])
|
|
90
|
+
|
|
91
|
+
if inspect.iscoroutinefunction(endpoint):
|
|
92
|
+
|
|
93
|
+
async def _call(*args: Any, **kwargs: Any) -> Any:
|
|
94
|
+
return await endpoint(strategy, *args, **kwargs)
|
|
95
|
+
|
|
96
|
+
else:
|
|
97
|
+
|
|
98
|
+
def _call(*args: Any, **kwargs: Any) -> Any:
|
|
99
|
+
return endpoint(strategy, *args, **kwargs)
|
|
100
|
+
|
|
101
|
+
update_wrapper(_call, endpoint)
|
|
102
|
+
_call.__signature__ = stripped_signature # type: ignore[attr-defined]
|
|
103
|
+
return _call
|
|
104
|
+
|
|
105
|
+
def _remove_existing_route(self, route_def: _StrategyRoute) -> None:
|
|
106
|
+
if not route_def.bound_route:
|
|
107
|
+
return
|
|
108
|
+
if route_def.bound_route in self.routes:
|
|
109
|
+
self.routes.remove(route_def.bound_route)
|
|
110
|
+
route_def.bound_route = None
|
|
111
|
+
route_def.bound_endpoint = None
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class StrategyFastAPI(FastAPI):
|
|
115
|
+
"""FastAPI application that understands strategy instance methods."""
|
|
116
|
+
|
|
117
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
118
|
+
super().__init__(*args, **kwargs)
|
|
119
|
+
|
|
120
|
+
original_router: APIRouter = self.router
|
|
121
|
+
router = StrategyAPIRouter(
|
|
122
|
+
prefix=original_router.prefix,
|
|
123
|
+
tags=original_router.tags,
|
|
124
|
+
dependencies=original_router.dependencies,
|
|
125
|
+
default_response_class=original_router.default_response_class,
|
|
126
|
+
responses=original_router.responses,
|
|
127
|
+
callbacks=original_router.callbacks,
|
|
128
|
+
routes=list(original_router.routes),
|
|
129
|
+
deprecated=original_router.deprecated,
|
|
130
|
+
include_in_schema=original_router.include_in_schema,
|
|
131
|
+
generate_unique_id_function=original_router.generate_unique_id_function,
|
|
132
|
+
)
|
|
133
|
+
router.route_class = original_router.route_class
|
|
134
|
+
router.on_startup = original_router.on_startup
|
|
135
|
+
router.on_shutdown = original_router.on_shutdown
|
|
136
|
+
router.lifespan_context = original_router.lifespan_context
|
|
137
|
+
|
|
138
|
+
self.router = router
|
|
139
|
+
self._strategy_router: StrategyAPIRouter = router
|
|
140
|
+
|
|
141
|
+
def bind_strategy(self, strategy: Any) -> None:
|
|
142
|
+
self._strategy_router.bind_strategy(strategy)
|
|
143
|
+
|
|
144
|
+
def unbind_strategy(self) -> None:
|
|
145
|
+
self._strategy_router.unbind_strategy()
|
|
146
|
+
|
|
147
|
+
def has_strategy_routes(self) -> bool:
|
|
148
|
+
return self._strategy_router.has_strategy_routes()
|
|
149
|
+
|
|
150
|
+
def has_user_routes(self) -> bool:
|
|
151
|
+
return self._strategy_router.has_user_defined_routes()
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def create_strategy_app(**kwargs: Any) -> StrategyFastAPI:
|
|
155
|
+
"""Create a strategy-aware FastAPI application."""
|
|
156
|
+
|
|
157
|
+
return StrategyFastAPI(**kwargs)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""Background web server runner for strategy FastAPI apps."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import threading
|
|
7
|
+
|
|
8
|
+
import uvicorn
|
|
9
|
+
from fastapi import FastAPI
|
|
10
|
+
import platform
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class StrategyWebServer:
|
|
14
|
+
"""Run a FastAPI application in a dedicated background thread."""
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
app: FastAPI,
|
|
19
|
+
*,
|
|
20
|
+
host: str = "0.0.0.0",
|
|
21
|
+
port: int = 8000,
|
|
22
|
+
log_level: str = "info",
|
|
23
|
+
) -> None:
|
|
24
|
+
self._app = app
|
|
25
|
+
self._host = host
|
|
26
|
+
self._port = port
|
|
27
|
+
self._log_level = log_level
|
|
28
|
+
|
|
29
|
+
self._server: uvicorn.Server | None = None
|
|
30
|
+
self._thread: threading.Thread | None = None
|
|
31
|
+
self._started = threading.Event()
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def app(self) -> FastAPI:
|
|
35
|
+
return self._app
|
|
36
|
+
|
|
37
|
+
def start(self) -> None:
|
|
38
|
+
if self._server is not None:
|
|
39
|
+
return
|
|
40
|
+
|
|
41
|
+
try:
|
|
42
|
+
import uvloop # noqa: F401
|
|
43
|
+
|
|
44
|
+
_uvloop_available = True
|
|
45
|
+
except Exception:
|
|
46
|
+
_uvloop_available = False
|
|
47
|
+
|
|
48
|
+
loop_type = (
|
|
49
|
+
"uvloop"
|
|
50
|
+
if platform.system() in {"Linux", "Darwin"} and _uvloop_available
|
|
51
|
+
else "asyncio"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
config = uvicorn.Config(
|
|
55
|
+
self._app,
|
|
56
|
+
host=self._host,
|
|
57
|
+
port=self._port,
|
|
58
|
+
log_level=self._log_level,
|
|
59
|
+
loop=loop_type,
|
|
60
|
+
lifespan="on",
|
|
61
|
+
)
|
|
62
|
+
self._server = uvicorn.Server(config)
|
|
63
|
+
|
|
64
|
+
def _run() -> None:
|
|
65
|
+
server = self._server
|
|
66
|
+
if server is None:
|
|
67
|
+
return
|
|
68
|
+
loop = asyncio.new_event_loop()
|
|
69
|
+
asyncio.set_event_loop(loop)
|
|
70
|
+
self._started.set()
|
|
71
|
+
try:
|
|
72
|
+
loop.run_until_complete(server.serve())
|
|
73
|
+
finally:
|
|
74
|
+
loop.run_until_complete(loop.shutdown_asyncgens())
|
|
75
|
+
loop.close()
|
|
76
|
+
|
|
77
|
+
self._thread = threading.Thread(
|
|
78
|
+
target=_run, name="StrategyWebServer", daemon=True
|
|
79
|
+
)
|
|
80
|
+
self._thread.start()
|
|
81
|
+
self._started.wait()
|
|
82
|
+
|
|
83
|
+
def stop(self) -> None:
|
|
84
|
+
if not self._server:
|
|
85
|
+
return
|
|
86
|
+
|
|
87
|
+
self._server.should_exit = True
|
|
88
|
+
if self._thread and self._thread.is_alive():
|
|
89
|
+
self._thread.join(timeout=1.0)
|
|
90
|
+
self._server = None
|
|
91
|
+
self._thread = None
|
|
92
|
+
self._started.clear()
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: walrasquant-lib
|
|
3
|
+
Version: 0.4.20
|
|
4
|
+
Summary: fastest python trading bot
|
|
5
|
+
Author: River-Shi
|
|
6
|
+
Author-email: River-Shi <nachuan.shi.quant@gmail.com>
|
|
7
|
+
License: MIT LICENSE
|
|
8
|
+
Requires-Dist: numpy>=1.26.4,<2.2.1
|
|
9
|
+
Requires-Dist: redis>=5.2.1,<6.0.0
|
|
10
|
+
Requires-Dist: zmq>=0.0.0,<0.0.1
|
|
11
|
+
Requires-Dist: apscheduler>=3.11.0,<4.0.0
|
|
12
|
+
Requires-Dist: returns>=0.24.0,<0.25.0
|
|
13
|
+
Requires-Dist: aiosqlite>=0.21.0,<0.22.0
|
|
14
|
+
Requires-Dist: uvloop>=0.21.0
|
|
15
|
+
Requires-Dist: throttled-py>=2.2.3
|
|
16
|
+
Requires-Dist: asyncpg>=0.30.0
|
|
17
|
+
Requires-Dist: psycopg2-binary>=2.9.10
|
|
18
|
+
Requires-Dist: click>=8.1.0
|
|
19
|
+
Requires-Dist: pycryptodome>=3.23.0
|
|
20
|
+
Requires-Dist: eth-account>=0.13.7
|
|
21
|
+
Requires-Dist: fastapi>=0.117.1
|
|
22
|
+
Requires-Dist: uvicorn>=0.36.0
|
|
23
|
+
Requires-Dist: dynaconf[redis]>=3.2.12
|
|
24
|
+
Requires-Dist: pandas>=2.3.3,<3.0.0
|
|
25
|
+
Requires-Dist: aiohttp>=3.13.3
|
|
26
|
+
Requires-Dist: rich>=14.0.0
|
|
27
|
+
Requires-Dist: picows>=2.1.1
|
|
28
|
+
Requires-Dist: ccxt>=4.5.63
|
|
29
|
+
Requires-Dist: nexuscore-lib>=0.2.0
|
|
30
|
+
Requires-Dist: flashduty-lib>=0.2.0
|
|
31
|
+
Requires-Dist: nexuslog-lib>=0.5.0
|
|
32
|
+
Requires-Dist: msgspec>=0.21.1
|
|
33
|
+
Requires-Python: >=3.11, <3.15
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# walrasquant
|
|
37
|
+
|
|
38
|
+
`walrasquant` is a high-performance Python framework for quantitative trading.
|
|
39
|
+
It is designed for low-latency execution, multi-exchange connectivity, and strategy development at scale.
|
|
40
|
+
|
|
41
|
+
## Highlights
|
|
42
|
+
|
|
43
|
+
- Async-first architecture for real-time trading workflows
|
|
44
|
+
- Multi-exchange support (OKX, Binance, Bybit, Hyperliquid, Bitget)
|
|
45
|
+
- Built-in order and position lifecycle management
|
|
46
|
+
- Strategy framework with execution algorithms (including TWAP)
|
|
47
|
+
- Optional web API integration with FastAPI
|
|
48
|
+
- CLI and PM2 tooling for monitoring and operations
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
### Requirements
|
|
53
|
+
|
|
54
|
+
- Python `>=3.11,<3.14`
|
|
55
|
+
- Redis (recommended for monitoring and shared runtime state)
|
|
56
|
+
|
|
57
|
+
### From PyPI
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install walrasquant
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### From source
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
git clone https://github.com/walras-group/WalrasQuant.git
|
|
67
|
+
cd WalrasQuant
|
|
68
|
+
uv pip install -e .
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Quick start
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from decimal import Decimal
|
|
75
|
+
|
|
76
|
+
from walrasquant.constants import settings, ExchangeType, OrderSide, OrderType
|
|
77
|
+
from walrasquant.config import Config, BasicConfig, PublicConnectorConfig, PrivateConnectorConfig
|
|
78
|
+
from walrasquant.engine import Engine
|
|
79
|
+
from walrasquant.exchange.okx import OkxAccountType
|
|
80
|
+
from walrasquant.schema import BookL1, Order
|
|
81
|
+
from walrasquant.strategy import Strategy
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
OKX_API_KEY = settings.OKX.DEMO_1.api_key
|
|
85
|
+
OKX_SECRET = settings.OKX.DEMO_1.secret
|
|
86
|
+
OKX_PASSPHRASE = settings.OKX.DEMO_1.passphrase
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class DemoStrategy(Strategy):
|
|
90
|
+
def __init__(self):
|
|
91
|
+
super().__init__()
|
|
92
|
+
self.subscribe_bookl1(symbols=["BTCUSDT-PERP.OKX"])
|
|
93
|
+
self.signal = True
|
|
94
|
+
|
|
95
|
+
def on_filled_order(self, order: Order):
|
|
96
|
+
print(order)
|
|
97
|
+
|
|
98
|
+
def on_bookl1(self, bookl1: BookL1):
|
|
99
|
+
if not self.signal:
|
|
100
|
+
return
|
|
101
|
+
|
|
102
|
+
self.create_order(
|
|
103
|
+
symbol="BTCUSDT-PERP.OKX",
|
|
104
|
+
side=OrderSide.BUY,
|
|
105
|
+
type=OrderType.MARKET,
|
|
106
|
+
amount=Decimal("0.1"),
|
|
107
|
+
)
|
|
108
|
+
self.create_order(
|
|
109
|
+
symbol="BTCUSDT-PERP.OKX",
|
|
110
|
+
side=OrderSide.SELL,
|
|
111
|
+
type=OrderType.MARKET,
|
|
112
|
+
amount=Decimal("0.1"),
|
|
113
|
+
)
|
|
114
|
+
self.signal = False
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
config = Config(
|
|
118
|
+
strategy_id="okx_demo_buy_sell",
|
|
119
|
+
user_id="user_test",
|
|
120
|
+
strategy=DemoStrategy(),
|
|
121
|
+
basic_config={
|
|
122
|
+
ExchangeType.OKX: BasicConfig(
|
|
123
|
+
api_key=OKX_API_KEY,
|
|
124
|
+
secret=OKX_SECRET,
|
|
125
|
+
passphrase=OKX_PASSPHRASE,
|
|
126
|
+
testnet=True,
|
|
127
|
+
)
|
|
128
|
+
},
|
|
129
|
+
public_conn_config={
|
|
130
|
+
ExchangeType.OKX: [PublicConnectorConfig(account_type=OkxAccountType.DEMO)]
|
|
131
|
+
},
|
|
132
|
+
private_conn_config={
|
|
133
|
+
ExchangeType.OKX: [PrivateConnectorConfig(account_type=OkxAccountType.DEMO)]
|
|
134
|
+
},
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
engine = Engine(config)
|
|
138
|
+
|
|
139
|
+
if __name__ == "__main__":
|
|
140
|
+
try:
|
|
141
|
+
engine.start()
|
|
142
|
+
finally:
|
|
143
|
+
engine.dispose()
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## CLI tools
|
|
147
|
+
|
|
148
|
+
After installation, the following commands are available:
|
|
149
|
+
|
|
150
|
+
- `wq` for PM2-based strategy process operations
|
|
151
|
+
|
|
152
|
+
## Documentation
|
|
153
|
+
|
|
154
|
+
- Local docs source: `docs/`
|
|
155
|
+
|
|
156
|
+
## Contributing
|
|
157
|
+
|
|
158
|
+
Contributions are welcome. Please open an issue or submit a PR.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
MIT License
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
walrasquant/__init__.py,sha256=A2Cke68pmeuBin50KHfD0n_O9QZBQVZM4Rqo7sySAts,170
|
|
2
|
+
walrasquant/aggregation.py,sha256=Mbz9Ps2BfFK46Hbt9X9nE3Lv5dw5luTxv9NC403iG3s,13098
|
|
3
|
+
walrasquant/backends/__init__.py,sha256=QGZK3ABQteHQQWvRNFCsBV8qX352EgbB-tKq_fd7L2w,246
|
|
4
|
+
walrasquant/backends/db.py,sha256=PP7Q1fMSDt4AfM0JV7VvZhiEYehojlo49OHRPtaojIM,2755
|
|
5
|
+
walrasquant/backends/db_memory.py,sha256=Xa2twotFbRBlWK7_EQpiJent4Ps7fXx4d-DdOs8nKzo,1787
|
|
6
|
+
walrasquant/backends/db_postgresql.py,sha256=iYoHtYJmha1wB96eeagFYJX5Vion-S5P3xzmRlQn7SA,12812
|
|
7
|
+
walrasquant/backends/db_sqlite.py,sha256=EAygEVJ1vJb0kKbdZaK4ir87XO6s2akd3QMmQ4CpCec,12030
|
|
8
|
+
walrasquant/base/__init__.py,sha256=cTIW90ws8PjiaE5--hhmYmEl8EFbFzp17dnpM91yn80,699
|
|
9
|
+
walrasquant/base/api_client.py,sha256=IbixhCNNcZDp3Beb0y1dk3h2lxzy55owi2vXGZyAz2s,1536
|
|
10
|
+
walrasquant/base/connector.py,sha256=keiTuIz3fmhqyaoNoxa0PGs7pQhWYkNbLXU0iyim7FY,28733
|
|
11
|
+
walrasquant/base/ems.py,sha256=0SRuXBzHbo5xRzWW1vLihMRLaLeXHceNBVEDyqkQbDs,29364
|
|
12
|
+
walrasquant/base/exchange.py,sha256=7vm_b3hN4nTfbNHsDgE_6V0M8UehQ278ExBAwPZ4OyI,6865
|
|
13
|
+
walrasquant/base/oms.py,sha256=7oTEzxtIrHH8BFIgaMGeYRdJBRNpRJbgnlOSoS043fA,14305
|
|
14
|
+
walrasquant/base/retry.py,sha256=g2MgJMxgJjF5nzQQWy7dHd2AH_Qf1dToiE_lasTt_LA,6903
|
|
15
|
+
walrasquant/base/sms.py,sha256=PBr6cEkXyTJ8whhlHni-Ihr0X_4oRvxzTslSsIKTCrc,21728
|
|
16
|
+
walrasquant/base/ws_client.py,sha256=-kphgR6OYFgdM4338AccCiQBr7Jv7AbppMX6pN3scBs,15677
|
|
17
|
+
walrasquant/config.py,sha256=AGSr5gBE9Uzm0k8ovvR_s3mnTp_z5uXjOOB1Z3mKfw8,10697
|
|
18
|
+
walrasquant/constants.py,sha256=e0H9VcHhQ6urwttuxnHMeVr_4iXgKLSHkPl_J31-INc,9389
|
|
19
|
+
walrasquant/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
+
walrasquant/core/cache.py,sha256=30KO0Y8Zif9U6GHZFbE7aAsE4fLMX9faUrp7qx1RONY,25337
|
|
21
|
+
walrasquant/core/clock.py,sha256=IfFZNr6mBt5DGsJ9O9oCtRQuyBhkTK1wtwc5IEF1DiI,1866
|
|
22
|
+
walrasquant/core/connection.py,sha256=Psp2b8yoTft2vZ5FHMYHTTiK0oX8ZS1oXHwrjnQO9jM,794
|
|
23
|
+
walrasquant/core/entity.py,sha256=6st4msoTp2_n6Z6oQ1RFcJYV0KwP2Kawp4pwXSfAAoU,17897
|
|
24
|
+
walrasquant/core/nautilius_core.py,sha256=V_PUnOfDBqtABRYZvFbP1Tgl865JRO2E_yLcx4TNwVg,3189
|
|
25
|
+
walrasquant/core/registry.py,sha256=QHxs9pBAumVnLryxy1zXnJgT0mSzCC4DKDQMuC5uLyg,1449
|
|
26
|
+
walrasquant/engine.py,sha256=LmNRNIXvtshyto7U_RuEGAoFZD8TP_ZwCDkYC97H_dQ,28025
|
|
27
|
+
walrasquant/error.py,sha256=lKmA5t5npXiAWHaS2J7F0lVKApPXHFTSddAPETf_Mdg,840
|
|
28
|
+
walrasquant/exchange/__init__.py,sha256=4gv6koc7ZAXgvK26QaMY3XVrga4Gp5rFa__w1h9HGcI,436
|
|
29
|
+
walrasquant/exchange/base_factory.py,sha256=MXMbUqWQ7zUXUbxlNEf-AE4PhPiMBmc2jEkyF97EdQY,4652
|
|
30
|
+
walrasquant/exchange/binance/__init__.py,sha256=tP5To0h9R61ac7WQa_sjJG3Wdn7AMVtL5zveSRm8tfQ,1014
|
|
31
|
+
walrasquant/exchange/binance/connector.py,sha256=SVZpEX0_psJHYh1-8rqRSqL4TmpPjcOhEmz2V7hUKzs,40107
|
|
32
|
+
walrasquant/exchange/binance/constants.py,sha256=TX6xZmoMpEZoU9QzG40918YQl_XW7iWAZV7OvGSXyVA,31032
|
|
33
|
+
walrasquant/exchange/binance/ems.py,sha256=a6obprsQSkM3rhaPeSdPDYljiIk_qyvVzOGTJQ7-43g,5318
|
|
34
|
+
walrasquant/exchange/binance/error.py,sha256=x2PIQZBag1fYGr4V82N98uY_DZdETHaX8ALR4Ye_TJE,1212
|
|
35
|
+
walrasquant/exchange/binance/exchange.py,sha256=SH6sg0_w1lbDBTJ5ihQpRRU369UcPdjMlTd7Sun5N0c,5294
|
|
36
|
+
walrasquant/exchange/binance/factory.py,sha256=7LcfwOZywSTIaT7lVrpD5WKRP7_Nd51QG2Zs9kL1yTM,4284
|
|
37
|
+
walrasquant/exchange/binance/oms.py,sha256=9peVk1MlR_y6VdLZpso5rk2hLiJH7OCm36b3T2KwoQ8,71682
|
|
38
|
+
walrasquant/exchange/binance/rest_api.py,sha256=pZUXz0GULNoqdE1nqgk7OpLISkWMcCON5e779ypa1dk,60943
|
|
39
|
+
walrasquant/exchange/binance/schema.py,sha256=K8KyQ450kjYwthslqcJuiK8teMYLDDXQ0Rmkvt2DBrM,32236
|
|
40
|
+
walrasquant/exchange/binance/websockets.py,sha256=wQVoFjVt0dfMnq49C3G2l_jofR-s-MQ3Yk9g2qKE-Rs,13496
|
|
41
|
+
walrasquant/exchange/bitget/__init__.py,sha256=1X8yx_GH6PtbplAKgVHMCZho8TMyQ_51mO46V-oxXAQ,902
|
|
42
|
+
walrasquant/exchange/bitget/connector.py,sha256=azNNTaGNIeUyXYA1tGPn1fJQYa-oZqe_fQfKIVETSco,21240
|
|
43
|
+
walrasquant/exchange/bitget/constants.py,sha256=11trNiYGmcS4hjOhuZWzje9nc5rfHzk8nCLyFvn7OQU,11649
|
|
44
|
+
walrasquant/exchange/bitget/ems.py,sha256=fJlj2ZNJba3s9DUb2LjCRph9PasqspqdACjs-PV6-MU,7609
|
|
45
|
+
walrasquant/exchange/bitget/error.py,sha256=SC6bixnF86cijFQqKSwXQcWv8xs9UhlZoEG4IkbsKwM,825
|
|
46
|
+
walrasquant/exchange/bitget/exchange.py,sha256=6_khiYygt4nWQAD6rG38IHfNnqGpnpnOI49p9mEagDs,5101
|
|
47
|
+
walrasquant/exchange/bitget/factory.py,sha256=We6CmObESJMohXMDQoTQU2H85GxfQ919RXtYOs28d3w,4977
|
|
48
|
+
walrasquant/exchange/bitget/oms.py,sha256=T6UJUz4RPZhadGV_H0qeAilq3qVuuw2D9yG2ACbvOSw,62204
|
|
49
|
+
walrasquant/exchange/bitget/rest_api.py,sha256=UqnuJ6OgjrsGMO1xqzBzzifFUgyFV59zAaja2JnRDsQ,18732
|
|
50
|
+
walrasquant/exchange/bitget/schema.py,sha256=Ay3pQNlut7whqHIjQtwkel3gZyaW2RSQsmUDXMFHoJY,21644
|
|
51
|
+
walrasquant/exchange/bitget/websockets.py,sha256=k9DvNWiI6Li9A0w78lADN8cu1YjXvtibfghAJ_mdRUE,21551
|
|
52
|
+
walrasquant/exchange/bybit/__init__.py,sha256=ENq_1JMVvqHUNg-v2nkOcUCrmrEMUBA1kgUXNQcw0I0,1051
|
|
53
|
+
walrasquant/exchange/bybit/connector.py,sha256=JurFXbdjZREPwBIcbbCRmgGTFZcaclrCbB_lfO_eEbc,28301
|
|
54
|
+
walrasquant/exchange/bybit/constants.py,sha256=0LPO6WERxxDE8l9pc9o7vdIeEyy2WWaFHbj2fnZjl3c,14914
|
|
55
|
+
walrasquant/exchange/bybit/ems.py,sha256=owue3dRZ_rMKDghVSQthLzxrVM9ovLJIE0wtR9yjb_w,3583
|
|
56
|
+
walrasquant/exchange/bybit/error.py,sha256=d74RM-kxB1TpS4nhZEABwUVptlbDU1qSmAkwEAT-mKU,822
|
|
57
|
+
walrasquant/exchange/bybit/exchange.py,sha256=5jDPtnpABdzaUEdMO7yTfj5XB_aZZtmkLNHQGBNN7KU,4322
|
|
58
|
+
walrasquant/exchange/bybit/factory.py,sha256=EXpSNA4hzvET4Vn-wuGy7wL4jmi0HF4XIurzdmo2UJs,4678
|
|
59
|
+
walrasquant/exchange/bybit/oms.py,sha256=pOMYL0NeUyPj3497aHgpPe6KlBgkqGngaMEqgLxZBiw,45395
|
|
60
|
+
walrasquant/exchange/bybit/rest_api.py,sha256=PzHOWnFTh3PX0XiqCew7-kRwIAuuYYigX8VnLrtzmoA,19289
|
|
61
|
+
walrasquant/exchange/bybit/schema.py,sha256=xHBeKAyN_m6DYQXGaLLPD-eAUBw-h4_HFdIPEI0x-_g,22462
|
|
62
|
+
walrasquant/exchange/bybit/websockets.py,sha256=rkgjv6eW_BqcFIr2z0G9QclHJ48HQfBUNKVT8aTo0CU,10361
|
|
63
|
+
walrasquant/exchange/hyperliquid/__init__.py,sha256=00hjGrV2z1E7TcPzr_oerwf_sgne-2E1f6WKmXopiYs,1007
|
|
64
|
+
walrasquant/exchange/hyperliquid/connector.py,sha256=OVgzYRuhLgiOae2jKQRHGeAcEfj9eguzd5z72hzz5cU,13493
|
|
65
|
+
walrasquant/exchange/hyperliquid/constants.py,sha256=88fKuKgH1EUeJs4YotuAM97V4exW-3FGI1pk0-xEkVo,13243
|
|
66
|
+
walrasquant/exchange/hyperliquid/ems.py,sha256=jKbybVNCrtbBUvt9ISakgOykPdq7zeF-Tcdo3oK4UKc,5704
|
|
67
|
+
walrasquant/exchange/hyperliquid/error.py,sha256=bGMUqd0q3JuiwUtlMa9DuKjntRZeE95R6ayoPq4XA5M,1264
|
|
68
|
+
walrasquant/exchange/hyperliquid/exchange.py,sha256=ImPGTFvEMilvIkBSCBY2PHapZe1yvlnxQCfq-_Ll6vE,4982
|
|
69
|
+
walrasquant/exchange/hyperliquid/factory.py,sha256=IlP7pZalnofjwlNdywWKBEj7QNPKZFURS7VnuyGYlqY,5012
|
|
70
|
+
walrasquant/exchange/hyperliquid/oms.py,sha256=8F2xmH9Ai7lo4kGB2KO6sxOYvP0wN9az3OeB-NJLkW4,41463
|
|
71
|
+
walrasquant/exchange/hyperliquid/rest_api.py,sha256=TulgC9Ezsmwa8t4I7vjQR0w1EOQqjT13onGDzJ9DKug,12457
|
|
72
|
+
walrasquant/exchange/hyperliquid/schema.py,sha256=Mhh19CN1IBUhXhO-2f8AyFy-79OyZ6jcfySd8mmsrzI,13622
|
|
73
|
+
walrasquant/exchange/hyperliquid/websockets.py,sha256=Ow-iZ-VEnvwxTXCCFLotshZuSDPUulDxm3lY0SPglyQ,18889
|
|
74
|
+
walrasquant/exchange/okx/__init__.py,sha256=PJg4CxjCxR8iGVV3qoFvSL51ofXNV5WFtWHHE4zQAsY,826
|
|
75
|
+
walrasquant/exchange/okx/connector.py,sha256=uFAZ8GAL0qEcqfzktKDVuexeRKKPkZtV7pIIN1BxTvw,33116
|
|
76
|
+
walrasquant/exchange/okx/constants.py,sha256=8hN693cAnAuDW-2zRT3ZvstISotQJwYh5TLa2iDMTlQ,15957
|
|
77
|
+
walrasquant/exchange/okx/ems.py,sha256=UhTNWARz9uNJ4ZbXKr3JusUTaWwvexInc5hqkCh46Eo,5821
|
|
78
|
+
walrasquant/exchange/okx/error.py,sha256=_-ZXlbqwOLW4dgTi7gnOofsoFfoETLoTaJ_Ic2Y_4JY,1645
|
|
79
|
+
walrasquant/exchange/okx/exchange.py,sha256=S1Jt9Oh2HEneS6wDdQ-pavZDJ3YrMlB7rI8ZY23ZUfE,4413
|
|
80
|
+
walrasquant/exchange/okx/factory.py,sha256=gn3-VF6TQlp3-n-03Ob9xcvV4jTe4DVR73TVSycnNpY,5147
|
|
81
|
+
walrasquant/exchange/okx/oms.py,sha256=ZtjtLWZajNYoQ9lTfy8LvyZGFlMv9b6xa2F3y9R3RDQ,45308
|
|
82
|
+
walrasquant/exchange/okx/rest_api.py,sha256=pURULpkDwz47y0bc4Iy_CMMLgOzzgrhv5rHrtfn7b6E,29708
|
|
83
|
+
walrasquant/exchange/okx/schema.py,sha256=S6tyZPf1fKLsoWgJ_aaaTury5e9P9qs6KGjupBiWW_E,39438
|
|
84
|
+
walrasquant/exchange/okx/websockets.py,sha256=ySL-Zyu67qXmiYH5eSAwO1vo92pCX1_sNI3S_v_iIgs,13652
|
|
85
|
+
walrasquant/exchange/registry.py,sha256=14XIbIZWxh_GKURqHlGtyfZXRkvjutGKTEPrO-PNvho,5982
|
|
86
|
+
walrasquant/execution/__init__.py,sha256=Sk93f9WIgStiUWKALa2kjnxk_jsRl-GNk9P33FsaMG8,673
|
|
87
|
+
walrasquant/execution/algorithm.py,sha256=vbbjmQM216aDvbtTCm3de2VLHMO8j7K4qOo7mndaX1E,32676
|
|
88
|
+
walrasquant/execution/algorithms/__init__.py,sha256=j2MLJXeTy5JVrfd3-_gbTK_9K0CF4dCqJ64BrSvpKic,101
|
|
89
|
+
walrasquant/execution/algorithms/twap.py,sha256=PHIyyz2qx_pBIfz7GWMaRW_HzgeRluVehkvl71MnsSE,14800
|
|
90
|
+
walrasquant/execution/config.py,sha256=VgLvXj8-ScTAjUx_KyvSxWEqObwCdEEI-YDkuvPv_GQ,927
|
|
91
|
+
walrasquant/execution/constants.py,sha256=KE8PGOV4qBiCbSi1Ybp68FtarNyfVBI1rISbP4XkZkk,792
|
|
92
|
+
walrasquant/execution/schema.py,sha256=oKFprpHZK3KrvuZ9e0fzP67oRSXnL2YVZJMOqV_wY3s,1854
|
|
93
|
+
walrasquant/indicator.py,sha256=ZICABnUvQyMkL4fOb4dWY_94V_ivzvfy1pd_0NllX18,13496
|
|
94
|
+
walrasquant/push.py,sha256=ZgHgh9glecjqYqYoAOCYCVs-2c13n0Ibd9_fia6vdpc,2281
|
|
95
|
+
walrasquant/schema.py,sha256=cQ2_RfDKx6GbERAOVpwkYNhGLIqmspU_iyNzoK-mc-c,20698
|
|
96
|
+
walrasquant/strategy.py,sha256=nWKy72pT6dZLDCI9p-Jm7ltiN5SwCz3QZyuqo9Ngt2k,63658
|
|
97
|
+
walrasquant/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
98
|
+
walrasquant/tools/pm2_wrapper.py,sha256=6Wc-7gvqW7f78zI9Xl-yyV0rXMKvwvrCsckfxNifNm4,29806
|
|
99
|
+
walrasquant/web/__init__.py,sha256=yz4Elsi-8dJY3WUfrORr1-XtTLICss19KooqalPHf8I,736
|
|
100
|
+
walrasquant/web/app.py,sha256=K8-O19kAXnd8CpO96pvO_GzOgZxYVx50Xrjhk0WI0tI,5676
|
|
101
|
+
walrasquant/web/server.py,sha256=6XerIbfvCswf0yCrYqF1vER4gwaCtuwjnALIPuII6dY,2351
|
|
102
|
+
walrasquant_lib-0.4.20.dist-info/WHEEL,sha256=uOqnPWqgFlbov4NeTCercq7cBQ2UN7xh5fiW55lOnAg,81
|
|
103
|
+
walrasquant_lib-0.4.20.dist-info/entry_points.txt,sha256=RVdNOLYwpk1cp4s-USe_0N6PD0k0-Jf6gLE3AN6GPOg,59
|
|
104
|
+
walrasquant_lib-0.4.20.dist-info/METADATA,sha256=wpNBcuvgSYFTNC3CDZ2IQOg-IOJBlSia-OT9WatqYbM,4173
|
|
105
|
+
walrasquant_lib-0.4.20.dist-info/RECORD,,
|