decibel-python-sdk 0.1.0__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.
- decibel_python_sdk-0.1.0/PKG-INFO +255 -0
- decibel_python_sdk-0.1.0/README.md +232 -0
- decibel_python_sdk-0.1.0/pyproject.toml +82 -0
- decibel_python_sdk-0.1.0/src/decibel/__init__.py +247 -0
- decibel_python_sdk-0.1.0/src/decibel/_base.py +726 -0
- decibel_python_sdk-0.1.0/src/decibel/_constants.py +164 -0
- decibel_python_sdk-0.1.0/src/decibel/_fee_pay.py +301 -0
- decibel_python_sdk-0.1.0/src/decibel/_gas_price_manager.py +262 -0
- decibel_python_sdk-0.1.0/src/decibel/_order_status.py +138 -0
- decibel_python_sdk-0.1.0/src/decibel/_order_types.py +109 -0
- decibel_python_sdk-0.1.0/src/decibel/_pagination.py +82 -0
- decibel_python_sdk-0.1.0/src/decibel/_subaccount_types.py +43 -0
- decibel_python_sdk-0.1.0/src/decibel/_transaction_builder.py +325 -0
- decibel_python_sdk-0.1.0/src/decibel/_utils.py +432 -0
- decibel_python_sdk-0.1.0/src/decibel/_version.py +1 -0
- decibel_python_sdk-0.1.0/src/decibel/abi/__init__.py +23 -0
- decibel_python_sdk-0.1.0/src/decibel/abi/__main__.py +4 -0
- decibel_python_sdk-0.1.0/src/decibel/abi/_registry.py +89 -0
- decibel_python_sdk-0.1.0/src/decibel/abi/_types.py +55 -0
- decibel_python_sdk-0.1.0/src/decibel/abi/generate.py +183 -0
- decibel_python_sdk-0.1.0/src/decibel/abi/json/netna.json +2417 -0
- decibel_python_sdk-0.1.0/src/decibel/abi/json/testnet.json +2919 -0
- decibel_python_sdk-0.1.0/src/decibel/admin.py +868 -0
- decibel_python_sdk-0.1.0/src/decibel/py.typed +0 -0
- decibel_python_sdk-0.1.0/src/decibel/read/__init__.py +279 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_account_overview.py +119 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_base.py +137 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_candlesticks.py +97 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_delegations.py +32 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_leaderboard.py +64 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_market_contexts.py +35 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_market_depth.py +81 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_market_prices.py +100 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_market_trades.py +81 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_markets.py +146 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_portfolio_chart.py +48 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_trading_points.py +36 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_types.py +136 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_user_active_twaps.py +70 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_user_bulk_orders.py +73 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_user_fund_history.py +49 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_user_funding_history.py +45 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_user_notifications.py +87 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_user_open_orders.py +91 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_user_order_history.py +101 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_user_positions.py +84 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_user_subaccounts.py +35 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_user_trade_history.py +77 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_user_twap_history.py +32 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_vaults.py +218 -0
- decibel_python_sdk-0.1.0/src/decibel/read/_ws.py +245 -0
- decibel_python_sdk-0.1.0/src/decibel/write/__init__.py +1949 -0
- decibel_python_sdk-0.1.0/src/decibel/write/_types.py +190 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: decibel-python-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for interacting with Decibel, a fully on-chain trading engine built on Aptos.
|
|
5
|
+
Keywords: decibel,aptos,blockchain,trading,sdk
|
|
6
|
+
Author: Decibel
|
|
7
|
+
Author-email: Decibel <support@decibel.trade>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Dist: aptos-sdk>=0.11.0
|
|
18
|
+
Requires-Dist: httpx>=0.28.0
|
|
19
|
+
Requires-Dist: pydantic>=2.0.0
|
|
20
|
+
Requires-Dist: websockets>=14.0
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# decibel-python-sdk
|
|
25
|
+
|
|
26
|
+
<div align="center">
|
|
27
|
+
|
|
28
|
+
[](https://www.python.org/downloads/)
|
|
29
|
+
[](https://github.com/astral-sh/ruff)
|
|
30
|
+
[](https://github.com/microsoft/pyright)
|
|
31
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
32
|
+
[](https://opensource.org/licenses/MIT)
|
|
33
|
+
|
|
34
|
+
Python SDK for interacting with [Decibel](https://decibel.trade), a fully on-chain trading engine built on [Aptos](https://aptos.dev).
|
|
35
|
+
|
|
36
|
+
**[📚 View Full Documentation →](https://docs.decibel.trade)**
|
|
37
|
+
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install decibel-python-sdk
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Or with [uv](https://docs.astral.sh/uv/):
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
uv add decibel-python-sdk
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Configuration
|
|
53
|
+
|
|
54
|
+
Set the following environment variables:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Required for write operations
|
|
58
|
+
export PRIVATE_KEY="your_private_key_hex"
|
|
59
|
+
|
|
60
|
+
# Optional: for better rate limits
|
|
61
|
+
export APTOS_NODE_API_KEY="your_aptos_node_api_key"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
> **New to Decibel?** Follow the [Getting Started Guide](https://docs.decibel.trade/quickstart/overview) to create your API Wallet and get your API key from [Geomi](https://geomi.dev).
|
|
65
|
+
|
|
66
|
+
## Quick Start
|
|
67
|
+
|
|
68
|
+
### Reading Market Data
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
import asyncio
|
|
72
|
+
from decibel import NETNA_CONFIG
|
|
73
|
+
from decibel.read import DecibelReadDex
|
|
74
|
+
|
|
75
|
+
async def main():
|
|
76
|
+
read = DecibelReadDex(NETNA_CONFIG)
|
|
77
|
+
|
|
78
|
+
# Get all markets
|
|
79
|
+
markets = await read.markets.get_all()
|
|
80
|
+
for market in markets:
|
|
81
|
+
print(f"{market.market_name}: {market.max_leverage}x leverage")
|
|
82
|
+
|
|
83
|
+
# Get market prices
|
|
84
|
+
prices = await read.market_prices.get_all()
|
|
85
|
+
for price in prices:
|
|
86
|
+
print(f"{price.market}: ${price.mark_px}")
|
|
87
|
+
|
|
88
|
+
asyncio.run(main())
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Placing Orders
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
import asyncio
|
|
95
|
+
import os
|
|
96
|
+
from aptos_sdk.account import Account
|
|
97
|
+
from aptos_sdk.ed25519 import PrivateKey
|
|
98
|
+
from decibel import (
|
|
99
|
+
NETNA_CONFIG,
|
|
100
|
+
BaseSDKOptions,
|
|
101
|
+
DecibelWriteDex,
|
|
102
|
+
GasPriceManager,
|
|
103
|
+
PlaceOrderSuccess,
|
|
104
|
+
TimeInForce,
|
|
105
|
+
amount_to_chain_units,
|
|
106
|
+
)
|
|
107
|
+
from decibel.read import DecibelReadDex
|
|
108
|
+
|
|
109
|
+
async def main():
|
|
110
|
+
private_key = PrivateKey.from_hex(os.environ["PRIVATE_KEY"])
|
|
111
|
+
account = Account.load_key(private_key.hex())
|
|
112
|
+
|
|
113
|
+
gas = GasPriceManager(NETNA_CONFIG)
|
|
114
|
+
await gas.initialize()
|
|
115
|
+
|
|
116
|
+
read = DecibelReadDex(NETNA_CONFIG)
|
|
117
|
+
markets = await read.markets.get_all()
|
|
118
|
+
btc = next(m for m in markets if m.market_name == "BTC/USD")
|
|
119
|
+
|
|
120
|
+
write = DecibelWriteDex(
|
|
121
|
+
NETNA_CONFIG,
|
|
122
|
+
account,
|
|
123
|
+
opts=BaseSDKOptions(gas_price_manager=gas),
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
result = await write.place_order(
|
|
127
|
+
market_name="BTC/USD",
|
|
128
|
+
price=amount_to_chain_units(100000.0, btc.px_decimals),
|
|
129
|
+
size=amount_to_chain_units(0.001, btc.sz_decimals),
|
|
130
|
+
is_buy=True,
|
|
131
|
+
time_in_force=TimeInForce.GoodTilCancelled,
|
|
132
|
+
is_reduce_only=False,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
if isinstance(result, PlaceOrderSuccess):
|
|
136
|
+
print(f"Order placed! ID: {result.order_id}")
|
|
137
|
+
else:
|
|
138
|
+
print(f"Order failed: {result.error}")
|
|
139
|
+
|
|
140
|
+
await gas.destroy()
|
|
141
|
+
|
|
142
|
+
asyncio.run(main())
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### WebSocket Streaming
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
import asyncio
|
|
149
|
+
from decibel import NETNA_CONFIG
|
|
150
|
+
from decibel.read import DecibelReadDex
|
|
151
|
+
|
|
152
|
+
async def main():
|
|
153
|
+
read = DecibelReadDex(NETNA_CONFIG)
|
|
154
|
+
|
|
155
|
+
def on_price(msg):
|
|
156
|
+
price = msg.price
|
|
157
|
+
print(f"BTC/USD: ${price.mark_px}")
|
|
158
|
+
|
|
159
|
+
unsubscribe = read.market_prices.subscribe_by_name("BTC/USD", on_price)
|
|
160
|
+
|
|
161
|
+
await asyncio.sleep(30)
|
|
162
|
+
unsubscribe()
|
|
163
|
+
await read.ws.close()
|
|
164
|
+
|
|
165
|
+
asyncio.run(main())
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Examples
|
|
169
|
+
|
|
170
|
+
See the [examples](examples) directory for complete working examples:
|
|
171
|
+
|
|
172
|
+
- **[examples/read](examples/read)** - REST API queries (markets, prices, positions, orders)
|
|
173
|
+
- **[examples/read/ws](examples/read/ws)** - WebSocket subscriptions (real-time streaming)
|
|
174
|
+
- **[examples/write](examples/write)** - Trading operations (orders, deposits, withdrawals)
|
|
175
|
+
|
|
176
|
+
## API Reference
|
|
177
|
+
|
|
178
|
+
### Network Configs
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
from decibel import NETNA_CONFIG, TESTNET_CONFIG
|
|
182
|
+
|
|
183
|
+
# NETNA_CONFIG - Dev Network
|
|
184
|
+
# TESTNET_CONFIG - Test network
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Read Client
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from decibel.read import DecibelReadDex
|
|
191
|
+
|
|
192
|
+
read = DecibelReadDex(config, api_key=None)
|
|
193
|
+
|
|
194
|
+
# Market data
|
|
195
|
+
read.markets.get_all()
|
|
196
|
+
read.market_prices.get_all()
|
|
197
|
+
read.market_prices.get_by_name(market_name)
|
|
198
|
+
read.market_depth.get_by_name(market_name, limit=50)
|
|
199
|
+
read.market_trades.get_by_name(market_name)
|
|
200
|
+
read.candlesticks.get_by_name(market_name, interval, start_time, end_time)
|
|
201
|
+
|
|
202
|
+
# User data
|
|
203
|
+
read.user_positions.get_by_addr(sub_addr)
|
|
204
|
+
read.user_open_orders.get_by_addr(sub_addr)
|
|
205
|
+
read.user_order_history.get_by_addr(sub_addr)
|
|
206
|
+
read.user_trade_history.get_by_addr(sub_addr)
|
|
207
|
+
read.account_overview.get_by_addr(sub_addr)
|
|
208
|
+
|
|
209
|
+
# WebSocket subscriptions
|
|
210
|
+
read.market_prices.subscribe_by_name(market_name, callback)
|
|
211
|
+
read.market_depth.subscribe_by_name(market_name, aggregation_size, callback)
|
|
212
|
+
read.user_positions.subscribe_by_addr(sub_addr, callback)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Write Client
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
from decibel import DecibelWriteDex, TimeInForce
|
|
219
|
+
|
|
220
|
+
write = DecibelWriteDex(config, account, opts)
|
|
221
|
+
|
|
222
|
+
# Orders
|
|
223
|
+
write.place_order(market_name, price, size, is_buy, time_in_force, is_reduce_only)
|
|
224
|
+
write.cancel_order(market_name, order_id)
|
|
225
|
+
write.cancel_order_by_client_id(market_name, client_order_id)
|
|
226
|
+
|
|
227
|
+
# TP/SL
|
|
228
|
+
write.place_tp_sl_for_position(market_name, tp_price, sl_price, ...)
|
|
229
|
+
write.update_tp_order(market_name, order_id, new_trigger_price, ...)
|
|
230
|
+
write.update_sl_order(market_name, order_id, new_trigger_price, ...)
|
|
231
|
+
|
|
232
|
+
# Collateral
|
|
233
|
+
write.deposit(amount)
|
|
234
|
+
write.withdraw(amount)
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Development
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
uv sync --all-extras # Install dependencies
|
|
241
|
+
uv run pre-commit install # Setup pre-commit hooks
|
|
242
|
+
uv run pytest # Run tests
|
|
243
|
+
uv run ruff check . # Lint
|
|
244
|
+
uv run pyright # Type check
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Resources
|
|
248
|
+
|
|
249
|
+
- [📚 Documentation](https://docs.decibel.trade) - Full API documentation
|
|
250
|
+
- [🌐 Trading Platform](https://app.decibel.trade) - Decibel trading interface
|
|
251
|
+
- [💬 Discord](https://discord.gg/decibel) - Community support
|
|
252
|
+
|
|
253
|
+
## License
|
|
254
|
+
|
|
255
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# decibel-python-sdk
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
[](https://www.python.org/downloads/)
|
|
6
|
+
[](https://github.com/astral-sh/ruff)
|
|
7
|
+
[](https://github.com/microsoft/pyright)
|
|
8
|
+
[](https://github.com/pre-commit/pre-commit)
|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
10
|
+
|
|
11
|
+
Python SDK for interacting with [Decibel](https://decibel.trade), a fully on-chain trading engine built on [Aptos](https://aptos.dev).
|
|
12
|
+
|
|
13
|
+
**[📚 View Full Documentation →](https://docs.decibel.trade)**
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install decibel-python-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or with [uv](https://docs.astral.sh/uv/):
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
uv add decibel-python-sdk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Configuration
|
|
30
|
+
|
|
31
|
+
Set the following environment variables:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Required for write operations
|
|
35
|
+
export PRIVATE_KEY="your_private_key_hex"
|
|
36
|
+
|
|
37
|
+
# Optional: for better rate limits
|
|
38
|
+
export APTOS_NODE_API_KEY="your_aptos_node_api_key"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
> **New to Decibel?** Follow the [Getting Started Guide](https://docs.decibel.trade/quickstart/overview) to create your API Wallet and get your API key from [Geomi](https://geomi.dev).
|
|
42
|
+
|
|
43
|
+
## Quick Start
|
|
44
|
+
|
|
45
|
+
### Reading Market Data
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import asyncio
|
|
49
|
+
from decibel import NETNA_CONFIG
|
|
50
|
+
from decibel.read import DecibelReadDex
|
|
51
|
+
|
|
52
|
+
async def main():
|
|
53
|
+
read = DecibelReadDex(NETNA_CONFIG)
|
|
54
|
+
|
|
55
|
+
# Get all markets
|
|
56
|
+
markets = await read.markets.get_all()
|
|
57
|
+
for market in markets:
|
|
58
|
+
print(f"{market.market_name}: {market.max_leverage}x leverage")
|
|
59
|
+
|
|
60
|
+
# Get market prices
|
|
61
|
+
prices = await read.market_prices.get_all()
|
|
62
|
+
for price in prices:
|
|
63
|
+
print(f"{price.market}: ${price.mark_px}")
|
|
64
|
+
|
|
65
|
+
asyncio.run(main())
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Placing Orders
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
import asyncio
|
|
72
|
+
import os
|
|
73
|
+
from aptos_sdk.account import Account
|
|
74
|
+
from aptos_sdk.ed25519 import PrivateKey
|
|
75
|
+
from decibel import (
|
|
76
|
+
NETNA_CONFIG,
|
|
77
|
+
BaseSDKOptions,
|
|
78
|
+
DecibelWriteDex,
|
|
79
|
+
GasPriceManager,
|
|
80
|
+
PlaceOrderSuccess,
|
|
81
|
+
TimeInForce,
|
|
82
|
+
amount_to_chain_units,
|
|
83
|
+
)
|
|
84
|
+
from decibel.read import DecibelReadDex
|
|
85
|
+
|
|
86
|
+
async def main():
|
|
87
|
+
private_key = PrivateKey.from_hex(os.environ["PRIVATE_KEY"])
|
|
88
|
+
account = Account.load_key(private_key.hex())
|
|
89
|
+
|
|
90
|
+
gas = GasPriceManager(NETNA_CONFIG)
|
|
91
|
+
await gas.initialize()
|
|
92
|
+
|
|
93
|
+
read = DecibelReadDex(NETNA_CONFIG)
|
|
94
|
+
markets = await read.markets.get_all()
|
|
95
|
+
btc = next(m for m in markets if m.market_name == "BTC/USD")
|
|
96
|
+
|
|
97
|
+
write = DecibelWriteDex(
|
|
98
|
+
NETNA_CONFIG,
|
|
99
|
+
account,
|
|
100
|
+
opts=BaseSDKOptions(gas_price_manager=gas),
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
result = await write.place_order(
|
|
104
|
+
market_name="BTC/USD",
|
|
105
|
+
price=amount_to_chain_units(100000.0, btc.px_decimals),
|
|
106
|
+
size=amount_to_chain_units(0.001, btc.sz_decimals),
|
|
107
|
+
is_buy=True,
|
|
108
|
+
time_in_force=TimeInForce.GoodTilCancelled,
|
|
109
|
+
is_reduce_only=False,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
if isinstance(result, PlaceOrderSuccess):
|
|
113
|
+
print(f"Order placed! ID: {result.order_id}")
|
|
114
|
+
else:
|
|
115
|
+
print(f"Order failed: {result.error}")
|
|
116
|
+
|
|
117
|
+
await gas.destroy()
|
|
118
|
+
|
|
119
|
+
asyncio.run(main())
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### WebSocket Streaming
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
import asyncio
|
|
126
|
+
from decibel import NETNA_CONFIG
|
|
127
|
+
from decibel.read import DecibelReadDex
|
|
128
|
+
|
|
129
|
+
async def main():
|
|
130
|
+
read = DecibelReadDex(NETNA_CONFIG)
|
|
131
|
+
|
|
132
|
+
def on_price(msg):
|
|
133
|
+
price = msg.price
|
|
134
|
+
print(f"BTC/USD: ${price.mark_px}")
|
|
135
|
+
|
|
136
|
+
unsubscribe = read.market_prices.subscribe_by_name("BTC/USD", on_price)
|
|
137
|
+
|
|
138
|
+
await asyncio.sleep(30)
|
|
139
|
+
unsubscribe()
|
|
140
|
+
await read.ws.close()
|
|
141
|
+
|
|
142
|
+
asyncio.run(main())
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Examples
|
|
146
|
+
|
|
147
|
+
See the [examples](examples) directory for complete working examples:
|
|
148
|
+
|
|
149
|
+
- **[examples/read](examples/read)** - REST API queries (markets, prices, positions, orders)
|
|
150
|
+
- **[examples/read/ws](examples/read/ws)** - WebSocket subscriptions (real-time streaming)
|
|
151
|
+
- **[examples/write](examples/write)** - Trading operations (orders, deposits, withdrawals)
|
|
152
|
+
|
|
153
|
+
## API Reference
|
|
154
|
+
|
|
155
|
+
### Network Configs
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
from decibel import NETNA_CONFIG, TESTNET_CONFIG
|
|
159
|
+
|
|
160
|
+
# NETNA_CONFIG - Dev Network
|
|
161
|
+
# TESTNET_CONFIG - Test network
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Read Client
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from decibel.read import DecibelReadDex
|
|
168
|
+
|
|
169
|
+
read = DecibelReadDex(config, api_key=None)
|
|
170
|
+
|
|
171
|
+
# Market data
|
|
172
|
+
read.markets.get_all()
|
|
173
|
+
read.market_prices.get_all()
|
|
174
|
+
read.market_prices.get_by_name(market_name)
|
|
175
|
+
read.market_depth.get_by_name(market_name, limit=50)
|
|
176
|
+
read.market_trades.get_by_name(market_name)
|
|
177
|
+
read.candlesticks.get_by_name(market_name, interval, start_time, end_time)
|
|
178
|
+
|
|
179
|
+
# User data
|
|
180
|
+
read.user_positions.get_by_addr(sub_addr)
|
|
181
|
+
read.user_open_orders.get_by_addr(sub_addr)
|
|
182
|
+
read.user_order_history.get_by_addr(sub_addr)
|
|
183
|
+
read.user_trade_history.get_by_addr(sub_addr)
|
|
184
|
+
read.account_overview.get_by_addr(sub_addr)
|
|
185
|
+
|
|
186
|
+
# WebSocket subscriptions
|
|
187
|
+
read.market_prices.subscribe_by_name(market_name, callback)
|
|
188
|
+
read.market_depth.subscribe_by_name(market_name, aggregation_size, callback)
|
|
189
|
+
read.user_positions.subscribe_by_addr(sub_addr, callback)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Write Client
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
from decibel import DecibelWriteDex, TimeInForce
|
|
196
|
+
|
|
197
|
+
write = DecibelWriteDex(config, account, opts)
|
|
198
|
+
|
|
199
|
+
# Orders
|
|
200
|
+
write.place_order(market_name, price, size, is_buy, time_in_force, is_reduce_only)
|
|
201
|
+
write.cancel_order(market_name, order_id)
|
|
202
|
+
write.cancel_order_by_client_id(market_name, client_order_id)
|
|
203
|
+
|
|
204
|
+
# TP/SL
|
|
205
|
+
write.place_tp_sl_for_position(market_name, tp_price, sl_price, ...)
|
|
206
|
+
write.update_tp_order(market_name, order_id, new_trigger_price, ...)
|
|
207
|
+
write.update_sl_order(market_name, order_id, new_trigger_price, ...)
|
|
208
|
+
|
|
209
|
+
# Collateral
|
|
210
|
+
write.deposit(amount)
|
|
211
|
+
write.withdraw(amount)
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Development
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
uv sync --all-extras # Install dependencies
|
|
218
|
+
uv run pre-commit install # Setup pre-commit hooks
|
|
219
|
+
uv run pytest # Run tests
|
|
220
|
+
uv run ruff check . # Lint
|
|
221
|
+
uv run pyright # Type check
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Resources
|
|
225
|
+
|
|
226
|
+
- [📚 Documentation](https://docs.decibel.trade) - Full API documentation
|
|
227
|
+
- [🌐 Trading Platform](https://app.decibel.trade) - Decibel trading interface
|
|
228
|
+
- [💬 Discord](https://discord.gg/decibel) - Community support
|
|
229
|
+
|
|
230
|
+
## License
|
|
231
|
+
|
|
232
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "decibel-python-sdk"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Python SDK for interacting with Decibel, a fully on-chain trading engine built on Aptos."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
authors = [
|
|
8
|
+
{ name = "Decibel", email = "support@decibel.trade" }
|
|
9
|
+
]
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
keywords = ["decibel", "aptos", "blockchain", "trading", "sdk"]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 3 - Alpha",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Typing :: Typed",
|
|
21
|
+
]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"aptos-sdk>=0.11.0",
|
|
24
|
+
"httpx>=0.28.0",
|
|
25
|
+
"pydantic>=2.0.0",
|
|
26
|
+
"websockets>=14.0",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[dependency-groups]
|
|
30
|
+
dev = [
|
|
31
|
+
"ruff>=0.14.13",
|
|
32
|
+
"pyright>=1.1.399",
|
|
33
|
+
"pytest>=9.0.2",
|
|
34
|
+
"pytest-asyncio>=0.24.0",
|
|
35
|
+
"pre-commit>=4.0.0",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[tool.uv.build-backend]
|
|
39
|
+
module-name = "decibel"
|
|
40
|
+
data-includes = ["src/decibel/abi/json/*.json"]
|
|
41
|
+
|
|
42
|
+
[build-system]
|
|
43
|
+
requires = ["uv_build>=0.9.21,<0.10.0"]
|
|
44
|
+
build-backend = "uv_build"
|
|
45
|
+
|
|
46
|
+
[tool.ruff]
|
|
47
|
+
line-length = 100
|
|
48
|
+
target-version = "py311"
|
|
49
|
+
|
|
50
|
+
[tool.ruff.lint]
|
|
51
|
+
select = [
|
|
52
|
+
"E", # pycodestyle errors
|
|
53
|
+
"F", # pyflakes
|
|
54
|
+
"I", # isort
|
|
55
|
+
"UP", # pyupgrade
|
|
56
|
+
"B", # flake8-bugbear
|
|
57
|
+
"SIM", # flake8-simplify
|
|
58
|
+
"TC", # flake8-type-checking
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
[tool.ruff.lint.flake8-bugbear]
|
|
62
|
+
extend-immutable-calls = ["pydantic.Field"]
|
|
63
|
+
|
|
64
|
+
[tool.ruff.lint.flake8-type-checking]
|
|
65
|
+
runtime-evaluated-base-classes = ["pydantic.BaseModel"]
|
|
66
|
+
|
|
67
|
+
[tool.ruff.lint.isort]
|
|
68
|
+
known-first-party = ["decibel"]
|
|
69
|
+
|
|
70
|
+
[tool.ruff.format]
|
|
71
|
+
quote-style = "double"
|
|
72
|
+
|
|
73
|
+
[tool.pyright]
|
|
74
|
+
include = ["src"]
|
|
75
|
+
pythonVersion = "3.11"
|
|
76
|
+
typeCheckingMode = "strict"
|
|
77
|
+
|
|
78
|
+
[tool.pytest.ini_options]
|
|
79
|
+
testpaths = ["tests"]
|
|
80
|
+
python_files = ["test_*.py"]
|
|
81
|
+
python_functions = ["test_*"]
|
|
82
|
+
asyncio_mode = "auto"
|