klingex 1.0.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.
@@ -0,0 +1,13 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(curl:*)",
5
+ "Bash(python3:*)",
6
+ "Bash(go vet:*)",
7
+ "Bash(go build:*)",
8
+ "Bash(npm install)",
9
+ "Bash(git add:*)",
10
+ "Bash(git commit:*)"
11
+ ]
12
+ }
13
+ }
@@ -0,0 +1,79 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+
27
+ # PyInstaller
28
+ *.manifest
29
+ *.spec
30
+
31
+ # Installer logs
32
+ pip-log.txt
33
+ pip-delete-this-directory.txt
34
+
35
+ # Unit test / coverage reports
36
+ htmlcov/
37
+ .tox/
38
+ .nox/
39
+ .coverage
40
+ .coverage.*
41
+ .cache
42
+ nosetests.xml
43
+ coverage.xml
44
+ *.cover
45
+ *.py,cover
46
+ .hypothesis/
47
+ .pytest_cache/
48
+
49
+ # Translations
50
+ *.mo
51
+ *.pot
52
+
53
+ # Environments
54
+ .env
55
+ .venv
56
+ env/
57
+ venv/
58
+ ENV/
59
+ env.bak/
60
+ venv.bak/
61
+
62
+ # IDE
63
+ .idea/
64
+ .vscode/
65
+ *.swp
66
+ *.swo
67
+ *~
68
+
69
+ # mypy
70
+ .mypy_cache/
71
+ .dmypy.json
72
+ dmypy.json
73
+
74
+ # Jupyter
75
+ .ipynb_checkpoints
76
+
77
+ # Project specific
78
+ .env.local
79
+ .env.*.local
klingex-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 KlingEx
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.
klingex-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,355 @@
1
+ Metadata-Version: 2.4
2
+ Name: klingex
3
+ Version: 1.0.0
4
+ Summary: Official Python SDK for KlingEx Exchange API
5
+ Project-URL: Homepage, https://klingex.io
6
+ Project-URL: Documentation, https://klingex.io/support/api-docs
7
+ Project-URL: Repository, https://github.com/Klingon-tech/klingex-py
8
+ Project-URL: Issues, https://github.com/Klingon-tech/klingex-py/issues
9
+ Author-email: KlingEx <support@klingex.io>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: api,bitcoin,crypto,cryptocurrency,exchange,klingex,sdk,trading
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Office/Business :: Financial :: Investment
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Requires-Python: >=3.9
25
+ Requires-Dist: httpx>=0.25.0
26
+ Requires-Dist: pydantic>=2.0.0
27
+ Requires-Dist: websockets>=12.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: black>=23.0.0; extra == 'dev'
30
+ Requires-Dist: mypy>=1.0.0; extra == 'dev'
31
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
32
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
33
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
34
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # KlingEx Python SDK
38
+
39
+ Official Python SDK for the KlingEx Exchange API.
40
+
41
+ ## Installation
42
+
43
+ ```bash
44
+ pip install klingex
45
+ ```
46
+
47
+ Or install from source:
48
+
49
+ ```bash
50
+ git clone https://github.com/Klingon-tech/klingex-py.git
51
+ cd klingex-py
52
+ pip install -e .
53
+ ```
54
+
55
+ ## Quick Start
56
+
57
+ ### Public API (No Authentication Required)
58
+
59
+ ```python
60
+ from klingex import KlingEx
61
+
62
+ # Create client (no credentials needed for public endpoints)
63
+ client = KlingEx()
64
+
65
+ # Get all available markets
66
+ markets = client.markets.get_markets()
67
+ for market in markets[:5]:
68
+ print(f"{market.symbol}: {market.base_asset_symbol}/{market.quote_asset_symbol}")
69
+
70
+ # Get tickers for all markets (CMC/CoinGecko format)
71
+ tickers = client.markets.get_tickers()
72
+ for ticker in tickers[:3]:
73
+ print(f"{ticker.ticker_id}: {ticker.last_price}")
74
+
75
+ # Get ticker for a specific market (use underscore format)
76
+ ticker = client.markets.get_ticker("BTC_USDT")
77
+ print(f"BTC_USDT: {ticker.last_price} (bid: {ticker.bid}, ask: {ticker.ask})")
78
+
79
+ # Get orderbook (market_id is an integer)
80
+ orderbook = client.markets.get_orderbook(market_id=1)
81
+ print(f"Best bid: {orderbook.bids[0][0]} @ {orderbook.bids[0][1]}")
82
+ print(f"Best ask: {orderbook.asks[0][0]} @ {orderbook.asks[0][1]}")
83
+
84
+ # Get OHLCV candlestick data
85
+ candles = client.markets.get_ohlcv(market_id=1, timeframe="1h", limit=24)
86
+ for candle in candles[:3]:
87
+ print(f"{candle.time_bucket}: O={candle.open_price} H={candle.high_price} L={candle.low_price} C={candle.close_price}")
88
+ ```
89
+
90
+ ### Authenticated API
91
+
92
+ ```python
93
+ from klingex import KlingEx, OrderSide
94
+
95
+ # Create client with API key
96
+ client = KlingEx(api_key="your_api_key")
97
+
98
+ # Get wallet balances
99
+ balances = client.wallet.get_balances()
100
+ for balance in balances:
101
+ if int(balance.balance) > 0:
102
+ print(f"{balance.symbol}: {balance.available} available, {balance.locked_balance} locked")
103
+
104
+ # Get balance for a specific asset
105
+ btc_balance = client.wallet.get_balance("BTC")
106
+ print(f"BTC: {btc_balance.balance}")
107
+
108
+ # Place a limit order (human-readable values by default)
109
+ order = client.orders.submit_order(
110
+ symbol="BTC-USDT",
111
+ trading_pair_id=1,
112
+ side=OrderSide.BUY,
113
+ quantity="0.001", # 0.001 BTC
114
+ price="50000", # $50,000 per BTC
115
+ )
116
+ print(f"Order placed: {order.order_id}")
117
+
118
+ # Place a market order (price="0")
119
+ market_order = client.orders.submit_order(
120
+ symbol="BTC-USDT",
121
+ trading_pair_id=1,
122
+ side=OrderSide.BUY,
123
+ quantity="0.001",
124
+ price="0", # Price 0 = market order
125
+ slippage=0.01, # 1% slippage tolerance
126
+ )
127
+
128
+ # Cancel an order (requires both order_id and trading_pair_id)
129
+ result = client.orders.cancel_order(order.order_id, trading_pair_id=1)
130
+ print(f"Cancelled: {result.message}, released: {result.released_balance}")
131
+
132
+ # Get open orders
133
+ open_orders = client.orders.get_open_orders()
134
+ for order in open_orders:
135
+ print(f"{order.id}: {order.side} {order.amount} @ {order.price}")
136
+
137
+ # Get all orders (with optional filters)
138
+ orders = client.orders.get_orders(trading_pair_id=1, status="pending", limit=50)
139
+ ```
140
+
141
+ ### Raw Values Mode
142
+
143
+ By default, quantity and price use human-readable values (e.g., "1.5" for 1.5 BTC). For raw base unit values (e.g., satoshis), use `raw_values=True`:
144
+
145
+ ```python
146
+ # Human-readable (default)
147
+ order = client.orders.submit_order(
148
+ symbol="BTC-USDT",
149
+ trading_pair_id=1,
150
+ side=OrderSide.BUY,
151
+ quantity="0.5", # 0.5 BTC
152
+ price="45000", # $45,000
153
+ )
154
+
155
+ # Raw base units
156
+ order = client.orders.submit_order(
157
+ symbol="BTC-USDT",
158
+ trading_pair_id=1,
159
+ side=OrderSide.BUY,
160
+ quantity="50000000", # 50,000,000 satoshis = 0.5 BTC
161
+ price="4500000", # $45,000 in base units
162
+ raw_values=True,
163
+ )
164
+ ```
165
+
166
+ ### Async Client
167
+
168
+ ```python
169
+ import asyncio
170
+ from klingex import AsyncKlingEx, OrderSide
171
+
172
+ async def main():
173
+ async with AsyncKlingEx(api_key="your_api_key") as client:
174
+ # Fetch multiple resources concurrently
175
+ markets, tickers, balances = await asyncio.gather(
176
+ client.markets.get_markets(),
177
+ client.markets.get_tickers(),
178
+ client.wallet.get_balances(),
179
+ )
180
+
181
+ # Place order
182
+ order = await client.orders.submit_order(
183
+ symbol="BTC-USDT",
184
+ trading_pair_id=1,
185
+ side=OrderSide.BUY,
186
+ quantity="0.001",
187
+ price="50000",
188
+ )
189
+
190
+ asyncio.run(main())
191
+ ```
192
+
193
+ ### WebSocket Streaming
194
+
195
+ ```python
196
+ import asyncio
197
+ from klingex import KlingExWebSocket
198
+
199
+ async def main():
200
+ ws = KlingExWebSocket(api_key="your_api_key") # Optional, for private channels
201
+
202
+ # Define handlers
203
+ def on_ticker(data):
204
+ ticker = data.get("data", {})
205
+ print(f"Ticker: {ticker.get('lastPrice')}")
206
+
207
+ def on_trade(data):
208
+ trade = data.get("data", {})
209
+ print(f"Trade: {trade.get('side')} {trade.get('quantity')} @ {trade.get('price')}")
210
+
211
+ def on_order_update(data):
212
+ order = data.get("data", {})
213
+ print(f"Order: {order.get('id')} - {order.get('status')}")
214
+
215
+ # Connect and subscribe
216
+ await ws.connect()
217
+
218
+ # Public channels
219
+ await ws.subscribe_ticker("BTC-USDT", on_ticker)
220
+ await ws.subscribe_trades("BTC-USDT", on_trade)
221
+ await ws.subscribe_orderbook("BTC-USDT")
222
+
223
+ # Private channels (requires auth)
224
+ await ws.subscribe_user_orders(on_order_update)
225
+ await ws.subscribe_user_trades()
226
+ await ws.subscribe_user_balances()
227
+
228
+ # Keep running
229
+ try:
230
+ while True:
231
+ await asyncio.sleep(1)
232
+ finally:
233
+ await ws.close()
234
+
235
+ asyncio.run(main())
236
+ ```
237
+
238
+ ### Invoice/Payment Processing
239
+
240
+ ```python
241
+ # Create an invoice
242
+ invoice = client.invoices.create_invoice(
243
+ currency="USDT",
244
+ amount="100.00",
245
+ accepted_coins=["BTC", "ETH", "USDT"],
246
+ description="Order #12345",
247
+ expires_in_minutes=60,
248
+ )
249
+ print(f"Invoice ID: {invoice.id}")
250
+ print(f"Payment URL: {invoice.payment_page_url}")
251
+
252
+ # List invoices
253
+ invoice_list = client.invoices.list_invoices(status="pending", page=1, page_size=20)
254
+ for inv in invoice_list.invoices:
255
+ print(f"{inv.id}: {inv.status}")
256
+
257
+ # Get invoice details
258
+ invoice = client.invoices.get_invoice(invoice.id)
259
+ print(f"Status: {invoice.status}")
260
+
261
+ # Cancel a pending invoice
262
+ client.invoices.cancel_invoice(invoice.id)
263
+
264
+ # Get fee statistics
265
+ fees = client.invoices.get_fee_stats()
266
+ print(f"Fee rate: {fees.current_fee_rate_percent}%")
267
+ ```
268
+
269
+ ## Error Handling
270
+
271
+ ```python
272
+ from klingex import (
273
+ KlingEx,
274
+ KlingExError,
275
+ AuthenticationError,
276
+ RateLimitError,
277
+ ValidationError,
278
+ )
279
+
280
+ client = KlingEx(api_key="your_api_key")
281
+
282
+ try:
283
+ order = client.orders.submit_order(
284
+ symbol="BTC-USDT",
285
+ trading_pair_id=1,
286
+ side="BUY",
287
+ quantity="0.001",
288
+ price="50000",
289
+ )
290
+ except AuthenticationError as e:
291
+ print(f"Auth failed: {e.message}")
292
+ except RateLimitError as e:
293
+ print(f"Rate limited. Retry after: {e.retry_after}s")
294
+ except ValidationError as e:
295
+ print(f"Invalid request: {e.message}")
296
+ except KlingExError as e:
297
+ print(f"API error: {e.message} (code: {e.code})")
298
+ ```
299
+
300
+ ## Configuration
301
+
302
+ ```python
303
+ client = KlingEx(
304
+ api_key="your_api_key",
305
+ base_url="https://api.klingex.io", # Custom API URL
306
+ timeout=30.0, # Request timeout in seconds
307
+ )
308
+ ```
309
+
310
+ ## API Reference
311
+
312
+ ### Client Classes
313
+
314
+ - `KlingEx` - Synchronous client
315
+ - `AsyncKlingEx` - Asynchronous client
316
+ - `KlingExWebSocket` - WebSocket client for real-time data
317
+
318
+ ### Endpoint Modules
319
+
320
+ - `client.markets` - Public market data (assets, markets, tickers, orderbook, OHLCV)
321
+ - `client.orders` - Order management (submit, cancel, list orders)
322
+ - `client.wallet` - Wallet operations (balances)
323
+ - `client.invoices` - Invoice/payment processing
324
+
325
+ ### Types
326
+
327
+ - `OrderSide` - `BUY`, `SELL`
328
+ - `OrderType` - `LIMIT`, `MARKET`
329
+ - `OrderStatus` - `PENDING`, `OPEN`, `PARTIAL`, `FILLED`, `CANCELLED`
330
+
331
+ ### Exceptions
332
+
333
+ - `KlingExError` - Base exception
334
+ - `AuthenticationError` - Invalid API credentials
335
+ - `RateLimitError` - Rate limit exceeded
336
+ - `ValidationError` - Invalid request parameters
337
+
338
+ ## Examples
339
+
340
+ See the [examples](./examples) directory for complete working examples:
341
+
342
+ - `basic_trading.py` - Basic trading operations
343
+ - `async_trading.py` - Async/concurrent operations
344
+ - `websocket_stream.py` - Real-time data streaming
345
+ - `market_maker.py` - Simple market-making strategy
346
+
347
+ ## License
348
+
349
+ MIT License - see [LICENSE](./LICENSE) for details.
350
+
351
+ ## Support
352
+
353
+ - Documentation: https://klingex.io/support/api-docs
354
+ - Issues: https://github.com/Klingon-tech/klingex-py/issues
355
+ - Email: support@klingex.io