sory 0.0.2__tar.gz
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.
- sory-0.0.2/LICENSE +21 -0
- sory-0.0.2/PKG-INFO +277 -0
- sory-0.0.2/README.md +246 -0
- sory-0.0.2/pyproject.toml +54 -0
- sory-0.0.2/setup.cfg +4 -0
- sory-0.0.2/setup.py +27 -0
- sory-0.0.2/src/sory/__init__.py +15 -0
- sory-0.0.2/src/sory/client.py +183 -0
- sory-0.0.2/src/sory/config.py +45 -0
- sory-0.0.2/src/sory/core/__init__.py +1 -0
- sory-0.0.2/src/sory/core/base.py +104 -0
- sory-0.0.2/src/sory/core/executor.py +233 -0
- sory-0.0.2/src/sory/core/orderbook.py +356 -0
- sory-0.0.2/src/sory/core/trades.py +154 -0
- sory-0.0.2/src/sory/exceptions.py +4 -0
- sory-0.0.2/src/sory/models.py +138 -0
- sory-0.0.2/src/sory/utils/__init__.py +5 -0
- sory-0.0.2/src/sory/utils/helpers.py +59 -0
- sory-0.0.2/src/sory/utils/logger.py +58 -0
- sory-0.0.2/src/sory.egg-info/PKG-INFO +277 -0
- sory-0.0.2/src/sory.egg-info/SOURCES.txt +22 -0
- sory-0.0.2/src/sory.egg-info/dependency_links.txt +1 -0
- sory-0.0.2/src/sory.egg-info/requires.txt +15 -0
- sory-0.0.2/src/sory.egg-info/top_level.txt +1 -0
sory-0.0.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Manuel de Cara
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
sory-0.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sory
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Smart order routing package for cryptocurrency trading
|
|
5
|
+
Author-email: Manuel de Cara <manu.de.cara@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: ccxt>=4.1.13
|
|
17
|
+
Requires-Dist: pydantic>=2.5.2
|
|
18
|
+
Requires-Dist: loguru>=0.7.2
|
|
19
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
20
|
+
Requires-Dist: logtail-python>=0.2.5
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: build; extra == "dev"
|
|
23
|
+
Requires-Dist: twine; extra == "dev"
|
|
24
|
+
Requires-Dist: black; extra == "dev"
|
|
25
|
+
Requires-Dist: isort; extra == "dev"
|
|
26
|
+
Requires-Dist: mypy; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# Sory - Smart Order Router
|
|
33
|
+
|
|
34
|
+
A sophisticated cryptocurrency trading package that provides real-time market data aggregation, smart order routing (SOR), and execution capabilities across multiple exchanges.
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
- **Real-time Market Data**
|
|
39
|
+
- Aggregated and individual orderbooks across multiple exchanges
|
|
40
|
+
- Trade monitoring with customizable size filters
|
|
41
|
+
- Support for spot, margin, perpetuals, futures and options data/trading
|
|
42
|
+
- Fee-aware price adjustments
|
|
43
|
+
|
|
44
|
+
- **Smart Order Routing**
|
|
45
|
+
- Best execution path calculation
|
|
46
|
+
- VWAP-based price discovery
|
|
47
|
+
- Slippage simulation
|
|
48
|
+
- Cross-exchange liquidity aggregation
|
|
49
|
+
|
|
50
|
+
- **Advanced Orderbook Processing**
|
|
51
|
+
- Symbol grouping for related markets (e.g., USDT/USDC pairs)
|
|
52
|
+
- Configurable depth levels
|
|
53
|
+
- Custom fee structures
|
|
54
|
+
- Volume-weighted price calculations for slippage simulations
|
|
55
|
+
|
|
56
|
+
- **Exchange Support**
|
|
57
|
+
- Multiple exchanges (Binance, Bybit, OKX, Coinbase, etc.)
|
|
58
|
+
- Unified API interface
|
|
59
|
+
- Sandbox/testnet mode for testing
|
|
60
|
+
- Comprehensive error handling and logging
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## For Users
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install sory
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Quick Start
|
|
74
|
+
|
|
75
|
+
### Market Data Monitoring
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import asyncio
|
|
79
|
+
from sory import SoryClient
|
|
80
|
+
|
|
81
|
+
async def orderbook_callback(orderbook):
|
|
82
|
+
print(f"\nOrderbook Update for {orderbook['symbol']}:")
|
|
83
|
+
print("Top 5 Bids:")
|
|
84
|
+
for price, amount, exchange in orderbook['bids'][:5]:
|
|
85
|
+
print(f" {exchange}: {price:.2f} @ {amount:.4f}")
|
|
86
|
+
|
|
87
|
+
async def main():
|
|
88
|
+
# Initialize 'sory'
|
|
89
|
+
sory = SoryClient()
|
|
90
|
+
|
|
91
|
+
# Configure orderbook settings
|
|
92
|
+
await sory.set_config(
|
|
93
|
+
type="orderbook",
|
|
94
|
+
aggregated=True,
|
|
95
|
+
exchanges=["binance", "bybit", "okx"],
|
|
96
|
+
symbols=["BTC/USDT", "ETH/USDT"], # Will return 2 different aggregated books
|
|
97
|
+
depth=20
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
# Start streaming
|
|
101
|
+
await sory.start_stream("orderbook", callback=orderbook_callback)
|
|
102
|
+
|
|
103
|
+
# Run for 60 seconds
|
|
104
|
+
await asyncio.sleep(60)
|
|
105
|
+
|
|
106
|
+
# Cleanup
|
|
107
|
+
await sory.stop_stream("orderbook")
|
|
108
|
+
await sory.close()
|
|
109
|
+
|
|
110
|
+
if __name__ == "__main__":
|
|
111
|
+
asyncio.run(main())
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Trade Execution
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
import asyncio
|
|
118
|
+
from sory import VolyClient
|
|
119
|
+
from sory.models import OrderConfig
|
|
120
|
+
|
|
121
|
+
async def main():
|
|
122
|
+
# Initialize 'sory'
|
|
123
|
+
sory = VolyClient()
|
|
124
|
+
|
|
125
|
+
# Configure for trading
|
|
126
|
+
await sory.set_config(
|
|
127
|
+
type="orderbook",
|
|
128
|
+
aggregated=True,
|
|
129
|
+
exchanges=["binance", "bybit", "okx", "kraken"],
|
|
130
|
+
symbols=["BTC/USDT"],
|
|
131
|
+
depth=20
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
# Initialize order executor
|
|
135
|
+
api_configs = [
|
|
136
|
+
{
|
|
137
|
+
"exchange": "binance",
|
|
138
|
+
"api_key": "your_api_key",
|
|
139
|
+
"api_secret": "your_secret"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"exchange": "bybit",
|
|
143
|
+
"api_key": "your_api_key",
|
|
144
|
+
"api_secret": "your_api_secret"
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
|
|
148
|
+
await sory.initialize_executor(api_configs)
|
|
149
|
+
|
|
150
|
+
# Create and execute order
|
|
151
|
+
order = OrderConfig(
|
|
152
|
+
side="buy",
|
|
153
|
+
amount=0.01 # BTC
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
result = await sory.execute_order(order)
|
|
157
|
+
print(f"Order execution result: {result}")
|
|
158
|
+
|
|
159
|
+
await sory.close()
|
|
160
|
+
|
|
161
|
+
if __name__ == "__main__":
|
|
162
|
+
asyncio.run(main())
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Configuration
|
|
166
|
+
|
|
167
|
+
API configurations can be passed directly as the `api_configs` dictionary or added to your `.env` file and accessed using the `get_api_config` function.
|
|
168
|
+
```python
|
|
169
|
+
from sory.utils.helpers import get_api_configs
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Environment Variables
|
|
173
|
+
|
|
174
|
+
Create a `.env` file in your project root:
|
|
175
|
+
|
|
176
|
+
```env
|
|
177
|
+
# Exchange API Keys
|
|
178
|
+
BINANCE_API_KEY=your_api_key
|
|
179
|
+
BINANCE_API_SECRET=your_secret
|
|
180
|
+
|
|
181
|
+
BYBIT_API_KEY=your_api_key
|
|
182
|
+
BYBIT_API_SECRET=your_secret
|
|
183
|
+
|
|
184
|
+
OKX_API_KEY=your_api_key
|
|
185
|
+
OKX_API_SECRET=your_secret
|
|
186
|
+
OKX_API_PASSWORD=your_password
|
|
187
|
+
|
|
188
|
+
# Optional Logging
|
|
189
|
+
BETTERSTACK_TOKEN=your_token
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Orderbook Configuration
|
|
193
|
+
|
|
194
|
+
Sory supports various orderbook configuration options:
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
await sory.set_config(
|
|
198
|
+
type="orderbook",
|
|
199
|
+
aggregated=True, # Enable cross-exchange aggregation
|
|
200
|
+
exchanges=["binance", "bybit", "coinbase", "okx"],
|
|
201
|
+
symbols=["BTC/USDT", "BTC/USDC"],
|
|
202
|
+
depth=100, # Orderbook depth to maintain
|
|
203
|
+
fees_bps={ # Optional fee configuration
|
|
204
|
+
"binance": 10, # 0.1% fee
|
|
205
|
+
"bybit": {"BTC/USDT": 10} # Symbol-specific fees
|
|
206
|
+
},
|
|
207
|
+
group={ # Optional symbol grouping
|
|
208
|
+
"BTC/USDT": "BTC/USDC" # Treat BTC/USDT and BTC/USDC pairs as same market
|
|
209
|
+
},
|
|
210
|
+
weighting={"BTC/USDT": # VWAP to make every level worth $1,000
|
|
211
|
+
{"USDT": 1000}
|
|
212
|
+
}
|
|
213
|
+
)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Trade Monitor Configuration
|
|
217
|
+
|
|
218
|
+
For monitoring trades across exchanges:
|
|
219
|
+
|
|
220
|
+
```python
|
|
221
|
+
await sory.set_config(
|
|
222
|
+
type="trades",
|
|
223
|
+
exchanges=["binance", "bybit", "okx"],
|
|
224
|
+
symbols=["BTC/USDT", "ETH/USDT"],
|
|
225
|
+
size={ # Optional size filters
|
|
226
|
+
"BTC/USDT": {"USDT": 10000} # Only trades > $10,000
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Advanced Usage
|
|
232
|
+
|
|
233
|
+
### Sandbox Testing
|
|
234
|
+
|
|
235
|
+
Enable sandbox/testnet mode for testing. Note that you will need to pass the testnet API keys, and only Binance and Bybit are currently supported for sandbox mode:
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
await sory.set_config(
|
|
239
|
+
type="orderbook",
|
|
240
|
+
aggregated=True,
|
|
241
|
+
exchanges=["binance", "bybit"],
|
|
242
|
+
sandbox_mode={
|
|
243
|
+
"binance": True,
|
|
244
|
+
"bybit": True
|
|
245
|
+
},
|
|
246
|
+
symbols=["BTC/USDT"],
|
|
247
|
+
depth=20
|
|
248
|
+
)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Margin Trading
|
|
252
|
+
|
|
253
|
+
Enable spot margin trading mode:
|
|
254
|
+
|
|
255
|
+
```python
|
|
256
|
+
await sory.initialize_executor(api_configs, margin_mode=True)
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## For developers
|
|
262
|
+
|
|
263
|
+
### Deployment
|
|
264
|
+
|
|
265
|
+
1. Update version:
|
|
266
|
+
```bash
|
|
267
|
+
./run.sh bump_version.py patch # or minor/major
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
2. Deploy to PyPI:
|
|
271
|
+
```bash
|
|
272
|
+
./deploy.sh
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## License
|
|
276
|
+
|
|
277
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
sory-0.0.2/README.md
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# Sory - Smart Order Router
|
|
2
|
+
|
|
3
|
+
A sophisticated cryptocurrency trading package that provides real-time market data aggregation, smart order routing (SOR), and execution capabilities across multiple exchanges.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Real-time Market Data**
|
|
8
|
+
- Aggregated and individual orderbooks across multiple exchanges
|
|
9
|
+
- Trade monitoring with customizable size filters
|
|
10
|
+
- Support for spot, margin, perpetuals, futures and options data/trading
|
|
11
|
+
- Fee-aware price adjustments
|
|
12
|
+
|
|
13
|
+
- **Smart Order Routing**
|
|
14
|
+
- Best execution path calculation
|
|
15
|
+
- VWAP-based price discovery
|
|
16
|
+
- Slippage simulation
|
|
17
|
+
- Cross-exchange liquidity aggregation
|
|
18
|
+
|
|
19
|
+
- **Advanced Orderbook Processing**
|
|
20
|
+
- Symbol grouping for related markets (e.g., USDT/USDC pairs)
|
|
21
|
+
- Configurable depth levels
|
|
22
|
+
- Custom fee structures
|
|
23
|
+
- Volume-weighted price calculations for slippage simulations
|
|
24
|
+
|
|
25
|
+
- **Exchange Support**
|
|
26
|
+
- Multiple exchanges (Binance, Bybit, OKX, Coinbase, etc.)
|
|
27
|
+
- Unified API interface
|
|
28
|
+
- Sandbox/testnet mode for testing
|
|
29
|
+
- Comprehensive error handling and logging
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## For Users
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install sory
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Quick Start
|
|
43
|
+
|
|
44
|
+
### Market Data Monitoring
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import asyncio
|
|
48
|
+
from sory import SoryClient
|
|
49
|
+
|
|
50
|
+
async def orderbook_callback(orderbook):
|
|
51
|
+
print(f"\nOrderbook Update for {orderbook['symbol']}:")
|
|
52
|
+
print("Top 5 Bids:")
|
|
53
|
+
for price, amount, exchange in orderbook['bids'][:5]:
|
|
54
|
+
print(f" {exchange}: {price:.2f} @ {amount:.4f}")
|
|
55
|
+
|
|
56
|
+
async def main():
|
|
57
|
+
# Initialize 'sory'
|
|
58
|
+
sory = SoryClient()
|
|
59
|
+
|
|
60
|
+
# Configure orderbook settings
|
|
61
|
+
await sory.set_config(
|
|
62
|
+
type="orderbook",
|
|
63
|
+
aggregated=True,
|
|
64
|
+
exchanges=["binance", "bybit", "okx"],
|
|
65
|
+
symbols=["BTC/USDT", "ETH/USDT"], # Will return 2 different aggregated books
|
|
66
|
+
depth=20
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# Start streaming
|
|
70
|
+
await sory.start_stream("orderbook", callback=orderbook_callback)
|
|
71
|
+
|
|
72
|
+
# Run for 60 seconds
|
|
73
|
+
await asyncio.sleep(60)
|
|
74
|
+
|
|
75
|
+
# Cleanup
|
|
76
|
+
await sory.stop_stream("orderbook")
|
|
77
|
+
await sory.close()
|
|
78
|
+
|
|
79
|
+
if __name__ == "__main__":
|
|
80
|
+
asyncio.run(main())
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Trade Execution
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
import asyncio
|
|
87
|
+
from sory import VolyClient
|
|
88
|
+
from sory.models import OrderConfig
|
|
89
|
+
|
|
90
|
+
async def main():
|
|
91
|
+
# Initialize 'sory'
|
|
92
|
+
sory = VolyClient()
|
|
93
|
+
|
|
94
|
+
# Configure for trading
|
|
95
|
+
await sory.set_config(
|
|
96
|
+
type="orderbook",
|
|
97
|
+
aggregated=True,
|
|
98
|
+
exchanges=["binance", "bybit", "okx", "kraken"],
|
|
99
|
+
symbols=["BTC/USDT"],
|
|
100
|
+
depth=20
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
# Initialize order executor
|
|
104
|
+
api_configs = [
|
|
105
|
+
{
|
|
106
|
+
"exchange": "binance",
|
|
107
|
+
"api_key": "your_api_key",
|
|
108
|
+
"api_secret": "your_secret"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"exchange": "bybit",
|
|
112
|
+
"api_key": "your_api_key",
|
|
113
|
+
"api_secret": "your_api_secret"
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
await sory.initialize_executor(api_configs)
|
|
118
|
+
|
|
119
|
+
# Create and execute order
|
|
120
|
+
order = OrderConfig(
|
|
121
|
+
side="buy",
|
|
122
|
+
amount=0.01 # BTC
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
result = await sory.execute_order(order)
|
|
126
|
+
print(f"Order execution result: {result}")
|
|
127
|
+
|
|
128
|
+
await sory.close()
|
|
129
|
+
|
|
130
|
+
if __name__ == "__main__":
|
|
131
|
+
asyncio.run(main())
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Configuration
|
|
135
|
+
|
|
136
|
+
API configurations can be passed directly as the `api_configs` dictionary or added to your `.env` file and accessed using the `get_api_config` function.
|
|
137
|
+
```python
|
|
138
|
+
from sory.utils.helpers import get_api_configs
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Environment Variables
|
|
142
|
+
|
|
143
|
+
Create a `.env` file in your project root:
|
|
144
|
+
|
|
145
|
+
```env
|
|
146
|
+
# Exchange API Keys
|
|
147
|
+
BINANCE_API_KEY=your_api_key
|
|
148
|
+
BINANCE_API_SECRET=your_secret
|
|
149
|
+
|
|
150
|
+
BYBIT_API_KEY=your_api_key
|
|
151
|
+
BYBIT_API_SECRET=your_secret
|
|
152
|
+
|
|
153
|
+
OKX_API_KEY=your_api_key
|
|
154
|
+
OKX_API_SECRET=your_secret
|
|
155
|
+
OKX_API_PASSWORD=your_password
|
|
156
|
+
|
|
157
|
+
# Optional Logging
|
|
158
|
+
BETTERSTACK_TOKEN=your_token
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Orderbook Configuration
|
|
162
|
+
|
|
163
|
+
Sory supports various orderbook configuration options:
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
await sory.set_config(
|
|
167
|
+
type="orderbook",
|
|
168
|
+
aggregated=True, # Enable cross-exchange aggregation
|
|
169
|
+
exchanges=["binance", "bybit", "coinbase", "okx"],
|
|
170
|
+
symbols=["BTC/USDT", "BTC/USDC"],
|
|
171
|
+
depth=100, # Orderbook depth to maintain
|
|
172
|
+
fees_bps={ # Optional fee configuration
|
|
173
|
+
"binance": 10, # 0.1% fee
|
|
174
|
+
"bybit": {"BTC/USDT": 10} # Symbol-specific fees
|
|
175
|
+
},
|
|
176
|
+
group={ # Optional symbol grouping
|
|
177
|
+
"BTC/USDT": "BTC/USDC" # Treat BTC/USDT and BTC/USDC pairs as same market
|
|
178
|
+
},
|
|
179
|
+
weighting={"BTC/USDT": # VWAP to make every level worth $1,000
|
|
180
|
+
{"USDT": 1000}
|
|
181
|
+
}
|
|
182
|
+
)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Trade Monitor Configuration
|
|
186
|
+
|
|
187
|
+
For monitoring trades across exchanges:
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
await sory.set_config(
|
|
191
|
+
type="trades",
|
|
192
|
+
exchanges=["binance", "bybit", "okx"],
|
|
193
|
+
symbols=["BTC/USDT", "ETH/USDT"],
|
|
194
|
+
size={ # Optional size filters
|
|
195
|
+
"BTC/USDT": {"USDT": 10000} # Only trades > $10,000
|
|
196
|
+
}
|
|
197
|
+
)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Advanced Usage
|
|
201
|
+
|
|
202
|
+
### Sandbox Testing
|
|
203
|
+
|
|
204
|
+
Enable sandbox/testnet mode for testing. Note that you will need to pass the testnet API keys, and only Binance and Bybit are currently supported for sandbox mode:
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
await sory.set_config(
|
|
208
|
+
type="orderbook",
|
|
209
|
+
aggregated=True,
|
|
210
|
+
exchanges=["binance", "bybit"],
|
|
211
|
+
sandbox_mode={
|
|
212
|
+
"binance": True,
|
|
213
|
+
"bybit": True
|
|
214
|
+
},
|
|
215
|
+
symbols=["BTC/USDT"],
|
|
216
|
+
depth=20
|
|
217
|
+
)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Margin Trading
|
|
221
|
+
|
|
222
|
+
Enable spot margin trading mode:
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
await sory.initialize_executor(api_configs, margin_mode=True)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## For developers
|
|
231
|
+
|
|
232
|
+
### Deployment
|
|
233
|
+
|
|
234
|
+
1. Update version:
|
|
235
|
+
```bash
|
|
236
|
+
./run.sh bump_version.py patch # or minor/major
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
2. Deploy to PyPI:
|
|
240
|
+
```bash
|
|
241
|
+
./deploy.sh
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## License
|
|
245
|
+
|
|
246
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sory"
|
|
7
|
+
version = "0.0.2"
|
|
8
|
+
description = "Smart order routing package for cryptocurrency trading"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{name = "Manuel de Cara", email = "manu.de.cara@gmail.com"}
|
|
12
|
+
]
|
|
13
|
+
license = {text = "MIT"}
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.9"
|
|
21
|
+
]
|
|
22
|
+
requires-python = ">=3.9"
|
|
23
|
+
dependencies = [
|
|
24
|
+
"ccxt>=4.1.13",
|
|
25
|
+
"pydantic>=2.5.2",
|
|
26
|
+
"loguru>=0.7.2",
|
|
27
|
+
"python-dotenv>=1.0.0",
|
|
28
|
+
"logtail-python>=0.2.5"
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
dev = [
|
|
33
|
+
"build",
|
|
34
|
+
"twine",
|
|
35
|
+
"black",
|
|
36
|
+
"isort",
|
|
37
|
+
"mypy",
|
|
38
|
+
"pytest",
|
|
39
|
+
"pytest-asyncio",
|
|
40
|
+
"pytest-cov"
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["src"]
|
|
45
|
+
include = ["sory*"]
|
|
46
|
+
|
|
47
|
+
[tool.black]
|
|
48
|
+
line-length = 100
|
|
49
|
+
target-version = ['py39']
|
|
50
|
+
|
|
51
|
+
[tool.isort]
|
|
52
|
+
profile = "black"
|
|
53
|
+
line_length = 100
|
|
54
|
+
multi_line_output = 3
|
sory-0.0.2/setup.cfg
ADDED
sory-0.0.2/setup.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
if __name__ == "__main__":
|
|
4
|
+
setup(
|
|
5
|
+
name="sory",
|
|
6
|
+
package_dir={"": "src"},
|
|
7
|
+
packages=find_packages(where="src", exclude=["tests*", "scripts*"]),
|
|
8
|
+
install_requires=[
|
|
9
|
+
"ccxt>=4.1.13",
|
|
10
|
+
"pydantic>=2.5.2",
|
|
11
|
+
"loguru>=0.7.2",
|
|
12
|
+
"python-dotenv>=1.0.0",
|
|
13
|
+
"logtail-python>=0.2.5"
|
|
14
|
+
],
|
|
15
|
+
extras_require={
|
|
16
|
+
'dev': [
|
|
17
|
+
'build',
|
|
18
|
+
'twine',
|
|
19
|
+
'black',
|
|
20
|
+
'isort',
|
|
21
|
+
'mypy',
|
|
22
|
+
'pytest',
|
|
23
|
+
'pytest-asyncio',
|
|
24
|
+
'pytest-cov'
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Sory package for cryptocurrency trading."""
|
|
2
|
+
from sory.client import SoryClient
|
|
3
|
+
from sory.models import OrderbookConfig, TradesConfig, APIConfig, OrderConfig
|
|
4
|
+
from sory.exceptions import SoryError
|
|
5
|
+
|
|
6
|
+
__version__ = "3.0.2"
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"SoryClient",
|
|
10
|
+
"SoryError",
|
|
11
|
+
"OrderbookConfig",
|
|
12
|
+
"TradesConfig",
|
|
13
|
+
"APIConfig",
|
|
14
|
+
"OrderConfig",
|
|
15
|
+
]
|