Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def _ticker(self, msg: dict, timestamp: float):
# currencyPair, last, lowestAsk, highestBid, percentChange, baseVolume,
# quoteVolume, isFrozen, 24hrHigh, 24hrLow
pair_id, _, ask, bid, _, _, _, _, _, _ = msg
if pair_id not in self.pair_mapping:
# Ignore new trading pairs that are added during long running sessions
return
pair = pair_exchange_to_std(self.pair_mapping[pair_id])
if self.__do_callback(TICKER, pair):
await self.callback(TICKER, feed=self.id,
pair=pair,
bid=Decimal(bid),
ask=Decimal(ask),
timestamp=timestamp,
receipt_timestamp=timestamp)
def main():
f = FeedHandler(raw_message_capture=AsyncFileCallback('./'), handler_enabled=False)
f.add_feed(Coinbase(pairs=['BTC-USD'], channels=[L3_BOOK, TICKER, TRADES]))
f.run()
def main():
fh = FeedHandler()
config = {OPEN_INTEREST: ['PI_XBTUSD', 'PI_ETHUSD'], TRADES: ['PI_XBTUSD'], TICKER: ['PI_XBTUSD', 'PI_ETHUSD'], L2_BOOK: ['PI_XBTUSD'], FUNDING: ['PI_XBTUSD']}
fh.add_feed(KrakenFutures(config=config, callbacks={OPEN_INTEREST: oi, FUNDING: funding, TICKER: TickerCallback(ticker), TRADES: TradeCallback(trade), L2_BOOK: BookCallback(book)}))
fh.run()
async def _ticker(self, msg: dict, timestamp: float):
for data in msg['data']:
await self.callback(TICKER, feed=self.id,
pair=data['symbol'],
bid=Decimal(data['bidPrice']),
ask=Decimal(data['askPrice']),
timestamp=timestamp_normalize(self.id, data['timestamp']),
receipt_timestamp=timestamp)
async def _ticker(self, msg: dict, pair: str, timestamp: float):
"""
[93, {'a': ['105.85000', 0, '0.46100000'], 'b': ['105.77000', 45, '45.00000000'], 'c': ['105.83000', '5.00000000'], 'v': ['92170.25739498', '121658.17399954'], 'p': ['107.58276', '107.95234'], 't': [4966, 6717], 'l': ['105.03000', '105.03000'], 'h': ['110.33000', '110.33000'], 'o': ['109.45000', '106.78000']}]
channel id, asks: price, wholeLotVol, vol, bids: price, wholeLotVol, close: ...,, vol: ..., VWAP: ..., trades: ..., low: ...., high: ..., open: ...
"""
await self.callback(TICKER, feed=self.id,
pair=pair,
bid=Decimal(msg[1]['b'][0]),
ask=Decimal(msg[1]['a'][0]),
timestamp=timestamp,
receipt_timestamp=timestamp)
5. In order to get TRADES of "BTC-KRW", ORDERBOOK of "ETH-KRW and TICKER of "EOS-KRW" with in shorter format
> [{"ticket":"UNIQUE_TICKET"},{"format":"SIMPLE"},{"type":"trade","codes":["KRW-BTC"]},{"type":"orderbook","codes":["KRW-ETH"]},{"type":"ticker", "codes":["KRW-EOS"]}]
"""
self.__reset()
chans = [{"ticket": "UNIQUE_TICKET"}, {"format": "SIMPLE"}]
for channel in self.channels if not self.config else self.config:
codes = list()
for pair in self.pairs if not self.config else self.config[channel]:
codes.append(pair)
if channel == L2_BOOK:
chans.append({"type": "orderbook", "codes": codes})
if channel == TRADES:
chans.append({"type": "trade", "codes": codes})
if channel == TICKER:
chans.append({"type": "ticker", "codes": codes})
await websocket.send(json.dumps(chans))
async def _ticker(self, msg: dict, timestamp: float):
await self.callback(TICKER, feed=self.id,
pair=pair_exchange_to_std(msg['symbol']),
bid=Decimal(msg['bid']),
ask=Decimal(msg['ask']),
timestamp=timestamp_normalize(self.id, msg['timestamp']),
receipt_timestamp=timestamp)
def main():
f = FeedHandler()
# Note: EXX is extremely unreliable - sometimes a connection can take many many retries
# f.add_feed(EXX(pairs=['BTC-USDT'], channels=[L2_BOOK, TRADES], callbacks={L2_BOOK: BookCallback(book), TRADES: TradeCallback(trade)}))
f.add_feed(Binance(pairs=['BTC-USDT'], channels=[TRADES, TICKER, L2_BOOK], callbacks={L2_BOOK: BookCallback(book), TRADES: TradeCallback(trade), TICKER: TickerCallback(ticker)}))
f.add_feed(COINBASE, pairs=['BTC-USD'], channels=[TICKER], callbacks={TICKER: TickerCallback(ticker)})
f.add_feed(Coinbase(pairs=['BTC-USD'], channels=[TRADES], callbacks={TRADES: TradeCallback(trade)}))
f.add_feed(Coinbase(config={L2_BOOK: ['BTC-USD', 'ETH-USD'], TRADES: ['ETH-USD', 'BTC-USD']}, callbacks={TRADES: TradeCallback(trade), L2_BOOK: BookCallback(book)}))
f.add_feed(Bitfinex(pairs=['BTC-USD'], channels=[L2_BOOK], callbacks={L2_BOOK: BookCallback(book)}))
f.add_feed(Poloniex(pairs=['BTC-USDT', 'BTC-USDC'], channels=[TICKER, TRADES, VOLUME], callbacks={VOLUME: volume, TICKER: TickerCallback(ticker), TRADES: TradeCallback(trade)}))
f.add_feed(Poloniex(config={TRADES: ['DOGE-BTC', 'ETH-BTC'], TICKER: ['ETH-BTC'], L2_BOOK: ['LTC-BTC']}, callbacks={TRADES: TradeCallback(trade), TICKER: TickerCallback(ticker), L2_BOOK: BookCallback(book)}))
f.add_feed(GEMINI, config={L2_BOOK: ['BTC-USD', 'ETH-USD'], TRADES: ['ETH-USD', 'BTC-USD']}, callbacks={TRADES: TradeCallback(trade), L2_BOOK: BookCallback(book)})
f.add_feed(HitBTC(channels=[TRADES], pairs=['BTC-USD'], callbacks={TRADES: TradeCallback(trade)}))
f.add_feed(HitBTC(channels=[L2_BOOK], pairs=['BTC-USD'], callbacks={L2_BOOK: BookCallback(book)}))
f.add_feed(Bitstamp(channels=[L2_BOOK, TRADES], pairs=['BTC-USD'], callbacks={L2_BOOK: BookCallback(book), TRADES: TradeCallback(trade)}))
bitmex_symbols = Bitmex.get_active_symbols()
f.add_feed(Bitmex(channels=[OPEN_INTEREST], pairs=['XBTUSD'], callbacks={OPEN_INTEREST: oi}))
f.add_feed(Bitmex(channels=[TRADES], pairs=bitmex_symbols, callbacks={TRADES: TradeCallback(trade)}))
f.add_feed(Bitmex(pairs=['XBTUSD'], channels=[FUNDING, TRADES], callbacks={FUNDING: FundingCallback(funding), TRADES: TradeCallback(trade)}))
f.add_feed(Bitfinex(pairs=['BTC'], channels=[FUNDING], callbacks={FUNDING: FundingCallback(funding)}))
f.add_feed(Bitmex(pairs=['XBTUSD'], channels=[L2_BOOK], callbacks={L2_BOOK: BookCallback(book)}))
f.add_feed(Kraken(config={TRADES: ['BTC-USD'], TICKER: ['ETH-USD']}, callbacks={TRADES: TradeCallback(trade), TICKER: TickerCallback(ticker)}))
config = {TRADES: ['BTC-USDT', 'ETH-USDT'], L2_BOOK: ['BTC-USDT']}
async def _ticker(self, msg: dict, timestamp: float):
# currencyPair, last, lowestAsk, highestBid, percentChange, baseVolume,
# quoteVolume, isFrozen, 24hrHigh, 24hrLow
pair_id, _, ask, bid, _, _, _, _, _, _ = msg
if pair_id not in self.pair_mapping:
# Ignore new trading pairs that are added during long running sessions
return
pair = pair_exchange_to_std(self.pair_mapping[pair_id])
if self.__do_callback(TICKER, pair):
await self.callback(TICKER, feed=self.id,
pair=pair,
bid=Decimal(bid),
ask=Decimal(ask),
timestamp=timestamp,
receipt_timestamp=timestamp)