No project description provided
Project description
cex-adaptors
This package is designed for interacting with many crypto centralized exchanges. Currently only support public API endpoints in Version 1.0.x. Will add private API endpoints in version 2.0.x.
Getting started
use pip install cex-adaptor to install the package.
Usage
After installing the package, you can use the following code start using the adaptors. All the codes is written in async mode.
from cex_adaptors.binance import Binance
import asyncio
async def main():
binance = Binance()
await binance.sync_exchange_info()
# get exchange info
print(await binance.get_exchange_info())
# get all tickers
print(await binance.get_tickers())
if __name__ == "__main__":
asyncio.run(main())
Unified function parameters and output format
1. get_exchange_info
Input
Output (Nested Dictionary)
2. get_tickers
Input
{
"market": "spot" // must be in "spot", "perp", "futures". If `null` will return all tickers on the exchange
}
Output (nested dict)
{
"BTC/USDT:USDT" : {
"timestamp": 1630000000000,
"instrument_id": "BTC/USDT:USDT",
"open_time": 1630000000000,
"close_time": 1630000000000,
"open": 10000.0,
"high": 11000.0,
"low": 9000.0,
"last": 10000.0,
"base_volume": 1000.0,
"quote_volume": 10000000.0,
"price_change": 0.0, // must in quote currency
"price_change_percent": 0.01, // must in percentage, if 0.01 means 1%,
"raw_data": {},
},
// many instrument ticker
}
3. get_ticker
Input
{
"instrument_id": "BTC/USDT:USDT" // must be perp_instrument_id in exchange's exchange info
}
Output (Dictionary)
{
"BTC/USDT:USDT" : {
"timestamp": 1630000000000,
"instrument_id": "BTC/USDT:USDT",
"open_time": 1630000000000,
"close_time": 1630000000000,
"open": 10000.0,
"high": 11000.0,
"low": 9000.0,
"last": 10000.0,
"base_volume": 1000.0,
"quote_volume": 10000000.0,
"price_change": 0.0, // must in quote currency
"price_change_percent": 0.01, // must in percentage, if 0.01 means 1%,
"raw_data": {},
}
}
4. get_current_candlestick
Input
{
"instrument_id": "BTC/USDT:USDT-PERP", // required
"interval": "1m", // required, vary from different exchanges
}
Output (List of Dictionary)
{
"timestamp": 1629350400000, // timestamp in millisecond
"interval": "1m",
"instrument_id": "BTC/USDT:USDT-PERP",
"market_type": "perp", // "spot", "futures", "perp
"open": 10000.0, // open price
"high": 10100, // high price
"low": 9900, // low price
"close": 10050, // close price
"base_volume": 1000, // volume in base currency
"quote_volume": 10000000, // quote volume
"contract_volume": 1000, // contract volume
"raw_data": {} // raw data from exchange
}
5. get_history_candlesticks
Input
{
"instrument_id": "BTC/USDT:USDT-PERP", // required
"interval": "1m", // required, vary from different exchanges
"start": 1629350400000, // optional, timestamp in millisecond
"end": 1629350400000, // optional, timestamp in millisecond
"num": 100, // optional, number of data to return
}
Output (List of Dictionary)
[
{
"timestamp": 1629350400000, // timestamp in millisecond
"interval": "1m",
"instrument_id": "BTC/USDT:USDT-PERP",
"market_type": "perp", // "spot", "futures", "perp
"open": 10000.0, // open price
"high": 10100, // high price
"low": 9900, // low price
"close": 10050, // close price
"base_volume": 1000, // volume in base currency
"quote_volume": 10000000, // quote volume
"contract_volume": 1000, // contract volume, if is spot then will equal to base_volume
"raw_data": {} // raw data from exchange
},
// many history candlesticks data
]
6. get_current_funding_rate
Input
{
"instrument_id": "BTC/USDT:USDT-PERP", // required, funding rate only support futures and perp
}
Output
{
"BTC/USDT:USDT-PERP": {
"timestamp": 1629350400000, // timestamp in millisecond
"next_funding_time": 1629350400000, // timestamp in milliseconds
"instrument_id": "BTC/USDT:USDT-PERP",
"market_type": "perp",
"funding_rate": 0.001, // funding rate in percentage, 0.01 means 1%
"raw_data": {} // raw data from exchange
}
}
7. get_history_funding_rate
Input
{
"instrument_id": "BTC/USDT:USDT-PERP", // required, funding rate only support futures and perp
"start": 1629350400000, // optional, timestamp in millisecond
"end": 1629350400000, // optional, timestamp in millisecond
"num": 100, // optional, number of data to return
}
(start, end) or num must be provided, if both provided, use start and end.
Output
[
{
"timestamp": 1629350400000, // timestamp in millisecond
"instrument_id": "BTC/USDT:USDT-PERP",
"market_type": "perp",
"funding_rate": 0.001, // funding rate in percentage, 0.01 means 1%
"realized_rate": 0.001, // realized rate in percentage, 0.01 means 1%
"raw_data": {} // raw data from exchange
}, // many history funding rate data
]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cex_adaptors-1.0.8.tar.gz.
File metadata
- Download URL: cex_adaptors-1.0.8.tar.gz
- Upload date:
- Size: 33.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7fa09bb73b2a2b9ece933cd6e164aaa800187083e077d27ea723e58b201e428
|
|
| MD5 |
d5e50c53478f5df1cf3848a613aef079
|
|
| BLAKE2b-256 |
94ff3641f68fbdcd79e99d53718262761899099aa19ba7269743b4ce75873531
|
File details
Details for the file cex_adaptors-1.0.8-py3-none-any.whl.
File metadata
- Download URL: cex_adaptors-1.0.8-py3-none-any.whl
- Upload date:
- Size: 82.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dca817bb5cd95879e06a1500c249e84c3b51f08864295935fe509742285918a3
|
|
| MD5 |
4d3d64c85fc61f2a3effc2e0601bc6ed
|
|
| BLAKE2b-256 |
44b9b02c9da2633e01a3e87792abd0597312cb40edf1e30697848ffc8b0449da
|