0
# Exchange Support
1
2
Pre-built exchange implementations supporting websocket and REST API access for 30+ major cryptocurrency exchanges, with unified interfaces and automatic data normalization across all supported venues.
3
4
## Capabilities
5
6
### Supported Exchanges
7
8
Complete list of all supported cryptocurrency exchanges with both websocket feeds and REST API access.
9
10
```python { .api }
11
# Major Spot Exchanges
12
class Coinbase(Feed): ...
13
class Binance(Feed): ...
14
class Kraken(Feed): ...
15
class Bitfinex(Feed): ...
16
class Bitstamp(Feed): ...
17
class Gemini(Feed): ...
18
class KuCoin(Feed): ...
19
class HitBTC(Feed): ...
20
class Poloniex(Feed): ...
21
22
# Futures and Derivatives
23
class BinanceFutures(Feed): ...
24
class BinanceDelivery(Feed): ...
25
class KrakenFutures(Feed): ...
26
class Deribit(Feed): ...
27
class BitMEX(Feed): ...
28
class Bybit(Feed): ...
29
class OKX(Feed): ...
30
class Phemex(Feed): ...
31
class Delta(Feed): ...
32
33
# Regional Exchanges
34
class BinanceUS(Feed): ...
35
class BinanceTR(Feed): ...
36
class Bithumb(Feed): ...
37
class Upbit(Feed): ...
38
class IndependentReserve(Feed): ...
39
40
# Additional Exchanges
41
class AscendEX(Feed): ...
42
class AscendEXFutures(Feed): ...
43
class Bequant(Feed): ...
44
class BitDotCom(Feed): ...
45
class Bitflyer(Feed): ...
46
class Bitget(Feed): ...
47
class Blockchain(Feed): ...
48
class CryptoDotCom(Feed): ...
49
class dYdX(Feed): ...
50
class EXX(Feed): ...
51
class FMFW(Feed): ...
52
class Gateio(Feed): ...
53
class GateioFutures(Feed): ...
54
class Huobi(Feed): ...
55
class HuobiDM(Feed): ...
56
class HuobiSwap(Feed): ...
57
class OKCoin(Feed): ...
58
class Probit(Feed): ...
59
```
60
61
### Exchange Base Classes
62
63
Base classes that provide common functionality for all exchange implementations.
64
65
```python { .api }
66
class Exchange:
67
def __init__(self, config=None, sandbox=False, subaccount=None, **kwargs):
68
"""
69
Initialize exchange with configuration and credentials.
70
71
Args:
72
config (Config, optional): Configuration object or file path
73
sandbox (bool): Whether to use sandbox/testnet environment
74
subaccount (str, optional): Subaccount name for multi-account support
75
**kwargs: Additional exchange-specific parameters
76
"""
77
78
def symbols(self, refresh=False):
79
"""Get supported symbols for the exchange."""
80
81
def symbol_mapping(self, refresh=False, headers=None):
82
"""Get symbol mapping between exchange and standard formats."""
83
84
def info(self):
85
"""Get exchange information and supported features."""
86
87
def std_channel_to_exchange(self, channel):
88
"""Convert standard channel name to exchange-specific format."""
89
90
def exchange_channel_to_std(self, channel):
91
"""Convert exchange channel name to standard format."""
92
93
@classmethod
94
def timestamp_normalize(cls, ts):
95
"""Normalize datetime to UTC timestamp."""
96
97
@classmethod
98
def normalize_order_options(cls, option):
99
"""Normalize order options to exchange-specific format."""
100
101
class Feed(Exchange):
102
def __init__(self, symbols=None, channels=None, callbacks=None, **kwargs):
103
"""
104
Initialize exchange feed.
105
106
Args:
107
symbols (List[str]): List of symbols to subscribe to
108
channels (List[str]): List of channels to subscribe to
109
callbacks (Dict[str, callable]): Channel to callback mapping
110
**kwargs: Exchange-specific configuration
111
"""
112
113
async def start(self, loop):
114
"""Start the websocket feed."""
115
116
async def stop(self):
117
"""Stop the websocket feed."""
118
```
119
120
### REST API Support
121
122
Synchronous and asynchronous REST API methods for historical data and trading operations.
123
124
```python { .api }
125
class RestExchange(Exchange):
126
# Market Data Methods
127
def ticker_sync(self, symbol, **kwargs):
128
"""Get ticker data synchronously."""
129
130
async def ticker(self, symbol, **kwargs):
131
"""Get ticker data asynchronously."""
132
133
def trades_sync(self, symbol, start=None, end=None, **kwargs):
134
"""Get trade history synchronously."""
135
136
async def trades(self, symbol, start=None, end=None, **kwargs):
137
"""Get trade history asynchronously."""
138
139
def candles_sync(self, symbol, start=None, end=None, interval='1m', **kwargs):
140
"""Get candle/OHLCV data synchronously."""
141
142
async def candles(self, symbol, start=None, end=None, interval='1m', **kwargs):
143
"""Get candle/OHLCV data asynchronously."""
144
145
def l2_book_sync(self, symbol, **kwargs):
146
"""Get L2 order book synchronously."""
147
148
async def l2_book(self, symbol, **kwargs):
149
"""Get L2 order book asynchronously."""
150
151
# Trading Methods (where supported)
152
def place_order_sync(self, symbol, side, order_type, amount, price=None, **kwargs):
153
"""Place order synchronously."""
154
155
async def place_order(self, symbol, side, order_type, amount, price=None, **kwargs):
156
"""Place order asynchronously."""
157
158
def cancel_order_sync(self, order_id, symbol=None, **kwargs):
159
"""Cancel order synchronously."""
160
161
async def cancel_order(self, order_id, symbol=None, **kwargs):
162
"""Cancel order asynchronously."""
163
164
def order_status_sync(self, order_id, symbol=None, **kwargs):
165
"""Get order status synchronously."""
166
167
async def order_status(self, order_id, symbol=None, **kwargs):
168
"""Get order status asynchronously."""
169
170
def balances_sync(self, **kwargs):
171
"""Get account balances synchronously."""
172
173
async def balances(self, **kwargs):
174
"""Get account balances asynchronously."""
175
```
176
177
## Usage Examples
178
179
### Basic Exchange Feed
180
181
```python
182
from cryptofeed import FeedHandler
183
from cryptofeed.exchanges import Coinbase
184
from cryptofeed.defines import TRADES, TICKER
185
186
def trade_handler(trade):
187
print(f'Trade: {trade.symbol} {trade.side} {trade.amount}@{trade.price}')
188
189
fh = FeedHandler()
190
fh.add_feed(Coinbase(
191
symbols=['BTC-USD', 'ETH-USD'],
192
channels=[TRADES, TICKER],
193
callbacks={TRADES: trade_handler}
194
))
195
fh.run()
196
```
197
198
### Multiple Exchanges
199
200
```python
201
from cryptofeed import FeedHandler
202
from cryptofeed.exchanges import Coinbase, Binance, Kraken
203
from cryptofeed.defines import TRADES
204
205
def trade_handler(trade):
206
print(f'{trade.exchange}: {trade.symbol} - {trade.side} {trade.amount}@{trade.price}')
207
208
fh = FeedHandler()
209
210
# Different exchanges may use different symbol formats
211
fh.add_feed(Coinbase(symbols=['BTC-USD'], channels=[TRADES], callbacks={TRADES: trade_handler}))
212
fh.add_feed(Binance(symbols=['BTCUSDT'], channels=[TRADES], callbacks={TRADES: trade_handler}))
213
fh.add_feed(Kraken(symbols=['XBT/USD'], channels=[TRADES], callbacks={TRADES: trade_handler}))
214
215
fh.run()
216
```
217
218
### Exchange Information
219
220
```python
221
from cryptofeed.exchanges import Coinbase, Binance
222
223
# Get exchange capabilities
224
coinbase = Coinbase()
225
print(coinbase.info()) # Shows supported channels, authentication, etc.
226
227
# Get supported symbols
228
symbols = coinbase.symbols()
229
print(f'Coinbase supports {len(symbols)} symbols')
230
231
# Check symbol mapping
232
mapping = coinbase.symbol_mapping()
233
print(mapping['BTC-USD']) # Shows exchange-specific symbol format
234
```
235
236
### REST API Usage
237
238
```python
239
import asyncio
240
from cryptofeed.exchanges import Coinbase
241
242
async def get_market_data():
243
exchange = Coinbase()
244
245
# Get current ticker
246
ticker = await exchange.ticker('BTC-USD')
247
print(f'BTC-USD: bid={ticker.bid}, ask={ticker.ask}')
248
249
# Get recent trades
250
trades = await exchange.trades('BTC-USD')
251
print(f'Latest trade: {trades[-1].price}')
252
253
# Get order book
254
book = await exchange.l2_book('BTC-USD')
255
print(f'Best bid: {list(book.book.bids.keys())[0]}')
256
257
asyncio.run(get_market_data())
258
```
259
260
### Authenticated Channels
261
262
```python
263
from cryptofeed import FeedHandler
264
from cryptofeed.exchanges import Coinbase
265
from cryptofeed.defines import ORDER_INFO, FILLS, BALANCES
266
267
def order_handler(order):
268
print(f'Order update: {order.symbol} {order.side} {order.status}')
269
270
def fill_handler(fill):
271
print(f'Fill: {fill.symbol} {fill.side} {fill.amount}@{fill.price}')
272
273
# Configure with API credentials
274
config = {
275
'coinbase': {
276
'key_id': 'your-api-key',
277
'secret': 'your-secret',
278
'passphrase': 'your-passphrase',
279
'sandbox': False
280
}
281
}
282
283
fh = FeedHandler()
284
fh.add_feed(Coinbase(
285
symbols=['BTC-USD'],
286
channels=[ORDER_INFO, FILLS],
287
callbacks={
288
ORDER_INFO: order_handler,
289
FILLS: fill_handler
290
},
291
config=config
292
))
293
fh.run()
294
```
295
296
### Channel Support by Exchange
297
298
```python
299
from cryptofeed.exchanges import Coinbase, Binance
300
from cryptofeed.defines import *
301
302
# Check what channels each exchange supports
303
coinbase = Coinbase()
304
binance = Binance()
305
306
# Coinbase supports
307
coinbase_channels = [TRADES, TICKER, L2_BOOK, L3_BOOK, ORDER_INFO, FILLS]
308
309
# Binance supports
310
binance_channels = [TRADES, TICKER, L1_BOOK, L2_BOOK, CANDLES, FUNDING, OPEN_INTEREST]
311
312
# Use exchange.info() to get definitive channel support
313
print(coinbase.info())
314
print(binance.info())
315
```