or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/pypi-cryptofeed

Cryptocurrency Exchange Websocket Data Feed Handler for normalized market data across 30+ exchanges

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/cryptofeed@2.4.x

To install, run

npx @tessl/cli install tessl/pypi-cryptofeed@2.4.0

0

# Cryptofeed

1

2

A comprehensive Python library for cryptocurrency exchange data feeds that provides normalized and standardized market data from 30+ major cryptocurrency exchanges through websockets and REST APIs. Supports real-time data streaming, historical data access, multi-exchange NBBO calculation, and flexible data storage backends.

3

4

## Package Information

5

6

- **Package Name**: cryptofeed

7

- **Language**: Python

8

- **Installation**: `pip install cryptofeed`

9

- **Minimum Python Version**: 3.8+

10

- **Optional Dependencies**: `pip install cryptofeed[all]` for all backend support

11

12

## Core Imports

13

14

```python

15

from cryptofeed import FeedHandler

16

```

17

18

For exchanges and data types:

19

20

```python

21

from cryptofeed.exchanges import Coinbase, Binance, Kraken, Bitfinex

22

from cryptofeed.defines import L1_BOOK, L2_BOOK, L3_BOOK, TRADES, TICKER, FUNDING

23

from cryptofeed.types import Trade, Ticker, OrderBook, Candle

24

```

25

26

For backends:

27

28

```python

29

from cryptofeed.backends.redis import TradeRedis, BookRedis

30

from cryptofeed.backends.mongo import TradeMongo

31

from cryptofeed.backends.postgres import TradePostgres

32

```

33

34

## Basic Usage

35

36

```python

37

from cryptofeed import FeedHandler

38

from cryptofeed.exchanges import Coinbase, Binance

39

from cryptofeed.defines import TRADES, TICKER, L2_BOOK

40

41

def trade_handler(trade):

42

print(f'Trade: {trade.exchange} {trade.symbol} {trade.side} {trade.amount} @ {trade.price}')

43

44

def ticker_handler(ticker):

45

print(f'Ticker: {ticker.exchange} {ticker.symbol} bid: {ticker.bid} ask: {ticker.ask}')

46

47

def book_handler(book):

48

print(f'Book: {book.exchange} {book.symbol} best bid: {list(book.book.bids.keys())[0]}')

49

50

# Create feed handler

51

fh = FeedHandler()

52

53

# Add exchange feeds with callbacks

54

fh.add_feed(Coinbase(

55

symbols=['BTC-USD', 'ETH-USD'],

56

channels=[TRADES, TICKER],

57

callbacks={TRADES: trade_handler, TICKER: ticker_handler}

58

))

59

60

fh.add_feed(Binance(

61

symbols=['BTCUSDT', 'ETHUSDT'],

62

channels=[L2_BOOK],

63

callbacks={L2_BOOK: book_handler}

64

))

65

66

# Start processing feeds

67

fh.run()

68

```

69

70

## Architecture

71

72

Cryptofeed uses an event-driven architecture with these key components:

73

74

- **FeedHandler**: Central orchestrator managing multiple exchange feeds and event loops

75

- **Exchange Classes**: Individual implementations for each supported exchange, handling websocket connections and data normalization

76

- **Data Types**: Cython-based classes (Trade, Ticker, OrderBook, etc.) providing fast, standardized data structures

77

- **Callbacks**: User-defined functions or backend classes that process incoming data

78

- **Backends**: Storage and streaming interfaces for databases, message queues, and other systems

79

- **Symbol Management**: Unified symbol handling across exchanges with automatic normalization

80

81

The architecture enables high-throughput data processing with minimal latency while abstracting away exchange-specific details.

82

83

## Capabilities

84

85

### Feed Management

86

87

Core functionality for managing cryptocurrency data feeds from multiple exchanges, including feed lifecycle management, connection handling, and event processing.

88

89

```python { .api }

90

class FeedHandler:

91

def __init__(self, config=None, raw_data_collection=None): ...

92

def add_feed(self, feed, loop=None, **kwargs): ...

93

def run(self, start_loop=True, install_signal_handlers=True, exception_handler=None): ...

94

def stop(self, loop=None): ...

95

def add_nbbo(self, feeds, symbols, callback, config=None): ...

96

```

97

98

[Core Feed Management](./feed-management.md)

99

100

### Exchange Implementations

101

102

Pre-built exchange implementations supporting websocket and REST API access for major cryptocurrency exchanges, with unified interfaces and automatic data normalization.

103

104

```python { .api }

105

# Example exchange classes

106

class Coinbase(Feed): ...

107

class Binance(Feed): ...

108

class Kraken(Feed): ...

109

class Bitfinex(Feed): ...

110

# ... 30+ more exchanges

111

```

112

113

[Exchange Support](./exchanges.md)

114

115

### Data Types and Structures

116

117

Fast Cython-based data structures representing different types of market data with standardized formats across all exchanges.

118

119

```python { .api }

120

class Trade:

121

exchange: str

122

symbol: str

123

side: str

124

amount: float

125

price: float

126

timestamp: float

127

id: str

128

129

class Ticker:

130

exchange: str

131

symbol: str

132

bid: float

133

ask: float

134

timestamp: float

135

136

class OrderBook:

137

exchange: str

138

symbol: str

139

book: dict

140

timestamp: float

141

```

142

143

[Data Types](./types.md)

144

145

### Storage Backends

146

147

Built-in backend implementations for storing and streaming data to various databases, message queues, and other systems with minimal setup.

148

149

```python { .api }

150

# Redis backends

151

class TradeRedis(BackendCallback): ...

152

class BookRedis(BackendCallback): ...

153

154

# Database backends

155

class TradeMongo(BackendCallback): ...

156

class TradePostgres(BackendCallback): ...

157

class TradeInflux(BackendCallback): ...

158

159

# Streaming backends

160

class TradeKafka(BackendCallback): ...

161

class TradeZMQ(BackendCallback): ...

162

```

163

164

[Storage Backends](./backends.md)

165

166

### REST API Access

167

168

Synchronous and asynchronous REST API methods for historical data retrieval, order management, and account operations across all supported exchanges.

169

170

```python { .api }

171

# Market Data REST Methods

172

def ticker_sync(self, symbol, **kwargs): ...

173

async def ticker(self, symbol, **kwargs): ...

174

def trades_sync(self, symbol, start=None, end=None, **kwargs): ...

175

async def trades(self, symbol, start=None, end=None, **kwargs): ...

176

def candles_sync(self, symbol, start=None, end=None, interval='1m', **kwargs): ...

177

async def candles(self, symbol, start=None, end=None, interval='1m', **kwargs): ...

178

def l2_book_sync(self, symbol, **kwargs): ...

179

async def l2_book(self, symbol, **kwargs): ...

180

181

# Trading REST Methods

182

def place_order_sync(self, symbol, side, order_type, amount, price=None, **kwargs): ...

183

async def place_order(self, symbol, side, order_type, amount, price=None, **kwargs): ...

184

def cancel_order_sync(self, order_id, symbol=None, **kwargs): ...

185

async def cancel_order(self, order_id, symbol=None, **kwargs): ...

186

def order_status_sync(self, order_id, symbol=None, **kwargs): ...

187

async def order_status(self, order_id, symbol=None, **kwargs): ...

188

def balances_sync(self, **kwargs): ...

189

async def balances(self, **kwargs): ...

190

```

191

192

[Exchange Support](./exchanges.md)

193

194

### Constants and Configuration

195

196

Standard constants for exchanges, channels, trading sides, and other enumerations, plus configuration management for feeds and authentication.

197

198

```python { .api }

199

# Channel constants

200

L1_BOOK: str

201

L2_BOOK: str

202

L3_BOOK: str

203

TRADES: str

204

TICKER: str

205

FUNDING: str

206

OPEN_INTEREST: str

207

LIQUIDATIONS: str

208

209

# Exchange constants

210

COINBASE: str

211

BINANCE: str

212

KRAKEN: str

213

# ... all supported exchanges

214

215

# Trading constants

216

BUY: str

217

SELL: str

218

MAKER: str

219

TAKER: str

220

```

221

222

[Constants and Configuration](./constants.md)