Esempio n. 1
0
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']}
    f.add_feed(
        Huobi(config=config,
              callbacks={
                  TRADES: TradeCallback(trade),
                  L2_BOOK: BookCallback(book)
              }))
    config = {L2_BOOK: ['BTC_CQ']}
    f.add_feed(
        HuobiDM(config=config,
                callbacks={
                    TRADES: TradeCallback(trade),
                    L2_BOOK: BookCallback(book)
                }))

    f.add_feed(
        OKCoin(pairs=['BTC-USD'],
               channels=[L2_BOOK],
               callbacks={L2_BOOK: BookCallback(book)}))
    f.add_feed(
        OKEx(pairs=['BTC-USDT'],
             channels=[TRADES],
             callbacks={TRADES: TradeCallback(trade)}))
    f.add_feed(
        Bittrex(config={
            TRADES: ['BTC-USD'],
            TICKER: ['ETH-USD'],
            L2_BOOK: ['BTC-USDT']
        },
                callbacks={
                    L2_BOOK: BookCallback(book),
                    TICKER: TickerCallback(ticker),
                    TRADES: TradeCallback(trade)
                }))
    f.add_feed(
        FTX(pairs=[
            'ADA-PERP', 'ALGO-PERP', 'ALT-PERP', 'ATOM-PERP', 'BCH-PERP',
            'BNB-PERP', 'BSV-PERP', 'BTC-PERP', 'BTMX-PERP', 'DOGE-PERP',
            'DRGN-PERP', 'EOS-PERP', 'ETC-PERP'
        ],
            channels=[TICKER],
            callbacks={
                TICKER: ticker,
                TRADES: TradeCallback(trade)
            }))
    f.run()
Esempio n. 2
0
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(pairs=['BTC-USD'],
                 channels=[L2_BOOK],
                 callbacks={L2_BOOK: BookCallback(book)}))
    f.add_feed(
        Bitfinex(pairs=['BTC-USD'],
                 channels=[L2_BOOK],
                 callbacks={L2_BOOK: BookCallback(book)}))
    f.add_feed(
        Poloniex(channels=[TICKER, 'BTC-USDT', 'BTC-USDC'],
                 callbacks={
                     L2_BOOK: BookCallback(book),
                     TICKER: TickerCallback(ticker)
                 }))
    f.add_feed(
        Poloniex(channels=['BTC-USDT', 'BTC-USDC'],
                 callbacks={TRADES: TradeCallback(trade)}))
    f.add_feed(
        Gemini(pairs=['BTC-USD'],
               callbacks={
                   L2_BOOK: BookCallback(book),
                   TRADES: TradeCallback(trade)
               }))
    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=[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=[L3_BOOK],
               callbacks={L3_BOOK: BookCallback(book)}))
    f.add_feed(
        Kraken(config={
            TRADES: ['BTC-USD'],
            TICKER: ['ETH-USD']
        },
               callbacks={
                   TRADES: TradeCallback(trade),
                   TICKER: TickerCallback(ticker)
               }))

    f.run()
Esempio n. 3
0
def main():
    f = FeedHandler()
    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(pairs=['BTC-USD'],
                 channels=[L2_BOOK],
                 callbacks={L2_BOOK: BookCallback(book)}))
    f.add_feed(
        Bitfinex(pairs=['BTC-USD'],
                 channels=[L2_BOOK],
                 callbacks={L2_BOOK: BookCallback(book)}))
    f.add_feed(
        Poloniex(channels=[TICKER, 'BTC-USDT', 'BTC-USDC'],
                 callbacks={
                     L2_BOOK: BookCallback(book),
                     TICKER: TickerCallback(ticker)
                 }))
    f.add_feed(
        Poloniex(channels=['BTC-USDT', 'BTC-USDC'],
                 callbacks={TRADES: TradeCallback(trade)}))
    f.add_feed(
        Gemini(pairs=['BTC-USD'],
               callbacks={
                   L2_BOOK: BookCallback(book),
                   TRADES: TradeCallback(trade)
               }))
    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=[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=[L3_BOOK],
               callbacks={L3_BOOK: BookCallback(book)}))
    f.add_feed(
        Kraken(pairs=['BTC-USD'],
               channels=[TRADES, TICKER, L2_BOOK],
               callbacks={
                   TRADES: TradeCallback(trade),
                   TICKER: TickerCallback(ticker),
                   L2_BOOK: BookCallback(book)
               }))

    f.run()
Esempio n. 4
0
def main():
    f = FeedHandler()
    # Note: EXX is extremely unreliable - sometimes a connection can take many many retries
    # from cryptofeed.exchanges import EXX
    # f.add_feed(EXX(pairs=['BTC-USDT'], channels=[L2_BOOK, TRADES], callbacks={L2_BOOK: BookCallback(book), TRADES: TradeCallback(trade)}))
    f.add_feed(
        Gateio(pairs=['BTC-USDT', 'ETH-USDT'],
               channels=[TRADES, L2_BOOK],
               callbacks={
                   TRADES: TradeCallback(trade),
                   L2_BOOK: BookCallback(book)
               }))
    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.info()['pairs']
    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(checksum_validation=True,
               config={
                   L2_BOOK: ['BTC-USD'],
                   TRADES: ['BTC-USD'],
                   TICKER: ['ETH-USD']
               },
               callbacks={
                   L2_BOOK: book,
                   TRADES: TradeCallback(trade),
                   TICKER: TickerCallback(ticker)
               }))
    config = {TRADES: ['BTC-USDT', 'ETH-USDT'], L2_BOOK: ['BTC-USDT']}
    f.add_feed(
        Huobi(config=config,
              callbacks={
                  TRADES: TradeCallback(trade),
                  L2_BOOK: BookCallback(book)
              }))
    config = {L2_BOOK: ['BTC_CQ', 'BTC_NQ']}
    f.add_feed(
        HuobiDM(config=config,
                callbacks={
                    TRADES: TradeCallback(trade),
                    L2_BOOK: BookCallback(book)
                }))
    pairs = ['BTC-USD', 'ETH-USD', 'EOS-USD', 'BCH-USD', 'BSV-USD', 'LTC-USD']
    f.add_feed(
        HuobiSwap(pairs=pairs,
                  channels=[TRADES, L2_BOOK, FUNDING],
                  callbacks={
                      FUNDING: funding,
                      TRADES: TradeCallback(trade),
                      L2_BOOK: BookCallback(book)
                  }))
    f.add_feed(
        OKCoin(pairs=['BTC-USD'],
               channels=[L2_BOOK],
               callbacks={L2_BOOK: BookCallback(book)}))
    f.add_feed(
        OKEx(pairs=['BTC-USDT'],
             channels=[TRADES],
             callbacks={TRADES: TradeCallback(trade)}))
    f.add_feed(
        Bittrex(config={
            TRADES: ['BTC-USD'],
            TICKER: ['ETH-USD'],
            L2_BOOK: ['BTC-USDT']
        },
                callbacks={
                    L2_BOOK: BookCallback(book),
                    TICKER: TickerCallback(ticker),
                    TRADES: TradeCallback(trade)
                }))
    f.add_feed(
        FTX(pairs=[
            'ADA-PERP', 'ALGO-PERP', 'ALT-PERP', 'ATOM-PERP', 'BCH-PERP',
            'BNB-PERP', 'BSV-PERP', 'BTC-PERP', 'BTMX-PERP', 'DOGE-PERP',
            'DRGN-PERP', 'EOS-PERP', 'ETC-PERP'
        ],
            channels=[TICKER],
            callbacks={
                TICKER: ticker,
                TRADES: TradeCallback(trade)
            }))
    f.add_feed(
        Bybit(pairs=['BTC-USD'],
              channels=[FUTURES_INDEX],
              callbacks={
                  OPEN_INTEREST: OpenInterestCallback(oi),
                  FUTURES_INDEX: FuturesIndexCallback(futures_index)
              }))

    f.add_feed(BLOCKCHAIN,
               pairs=['BTC-USD', 'ETH-USD'],
               channels=[L2_BOOK, TRADES],
               callbacks={
                   L2_BOOK: BookCallback(book),
                   TRADES: trade
               })

    f.run()
Esempio n. 5
0
    #print(huobi[market])
\
"""
bcontracts = []

pairs = requests.get('https://dapi.binance.com/dapi/v1/exchangeInfo').json()
for symbol in pairs['symbols']:
    split = len(symbol['baseAsset'])
    #if 'BTC' in symbol['symbol']:
    #print(symbol['symbol'])
    normalized = symbol['symbol'][:split] + '-' + symbol['symbol'][split:]
    bcontracts.append(normalized)
config = {TICKER: bcontracts}
fh.add_feed(
    BinanceFutures(config=config, callbacks={TICKER: TickerCallback(ticker)}))
"""
ofuts = []
oswaps = []
swaps = requests.get('https://www.okex.com/api/swap/v3/instruments').json()

futures = requests.get('https://www.okex.com/api/futures/v3/instruments').json()
for s in swaps:
    oswaps.append(s['instrument_id'])
for f in futures:
    ofuts.append(f['instrument_id'])
config = {TICKER_OKS: oswaps
,TICKER_FUTURES: ofuts}
fh.add_feed(OKEx(config=config, callbacks={TICKER_FUTURES: TickerCallback(ticker), TICKER_OKS: TickerCallback(ticker)}))

#print(expis)
Esempio n. 6
0
def main():
    config = {'log': {'filename': 'demo.log', 'level': 'INFO'}}
    # the config will be automatically passed into any exchanges set up by string. Instantiated exchange objects would need to pass the config in manually.
    f = FeedHandler(config=config)
    # Note: EXX is extremely unreliable - sometimes a connection can take many many retries
    # from cryptofeed.exchanges import EXX
    # f.add_feed(EXX(symbols=['BTC-USDT'], channels=[L2_BOOK, TRADES], callbacks={L2_BOOK: BookCallback(book), TRADES: TradeCallback(trade)}))
    f.add_feed(
        Gateio(symbols=['BTC-USDT', 'ETH-USDT'],
               channels=[TRADES, L2_BOOK],
               callbacks={
                   TRADES: TradeCallback(trade),
                   L2_BOOK: BookCallback(book)
               }))
    pairs = Binance.info()['symbols']
    f.add_feed(
        Binance(symbols=pairs,
                channels=[TRADES],
                callbacks={TRADES: TradeCallback(trade)}))
    f.add_feed(COINBASE,
               symbols=['BTC-USD'],
               channels=[TICKER],
               callbacks={TICKER: TickerCallback(ticker)})
    f.add_feed(
        Coinbase(symbols=['BTC-USD'],
                 channels=[TRADES],
                 callbacks={TRADES: TradeCallback(trade)}))
    f.add_feed(
        Coinbase(subscription={
            L2_BOOK: ['BTC-USD', 'ETH-USD'],
            TRADES: ['ETH-USD']
        },
                 callbacks={
                     TRADES: TradeCallback(trade),
                     L2_BOOK: BookCallback(book)
                 }))
    f.add_feed(
        Coinbase(subscription={L3_BOOK: ['LTC-USD']},
                 callbacks={L3_BOOK: BookCallback(book)}))
    f.add_feed(
        Bitfinex(symbols=['BTC-USDT'],
                 channels=[L2_BOOK],
                 callbacks={L2_BOOK: BookCallback(book)}))
    f.add_feed(
        Bitfinex(symbols=['BTC'],
                 channels=[FUNDING],
                 callbacks={FUNDING: FundingCallback(funding)}))
    f.add_feed(
        Poloniex(symbols=['BTC-ETH'],
                 channels=[TICKER, TRADES, VOLUME],
                 callbacks={
                     VOLUME: volume,
                     TICKER: TickerCallback(ticker),
                     TRADES: TradeCallback(trade)
                 }))
    f.add_feed(
        Poloniex(subscription={
            TRADES: ['BTC-DOGE'],
            L2_BOOK: ['BTC-LTC']
        },
                 callbacks={
                     TRADES: TradeCallback(trade),
                     TICKER: TickerCallback(ticker),
                     L2_BOOK: BookCallback(book)
                 }))
    f.add_feed(GEMINI,
               subscription={
                   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],
               symbols=['BTC-USD'],
               callbacks={TRADES: TradeCallback(trade)}))
    f.add_feed(
        HitBTC(channels=[L2_BOOK],
               symbols=['BTC-USD'],
               callbacks={L2_BOOK: BookCallback(book)}))
    f.add_feed(
        Bitstamp(channels=[L2_BOOK, TRADES],
                 symbols=['BTC-USD'],
                 callbacks={
                     L2_BOOK: BookCallback(book),
                     TRADES: TradeCallback(trade)
                 }))
    bitmex_symbols = Bitmex.info()['symbols']
    f.add_feed(
        Bitmex(channels=[OPEN_INTEREST],
               symbols=['BTC-USD'],
               callbacks={OPEN_INTEREST: oi}))
    f.add_feed(
        Bitmex(channels=[TRADES],
               symbols=bitmex_symbols,
               callbacks={TRADES: TradeCallback(trade)}))
    f.add_feed(
        Bitmex(symbols=['BTC-USD'],
               channels=[FUNDING, TRADES],
               callbacks={
                   FUNDING: FundingCallback(funding),
                   TRADES: TradeCallback(trade)
               }))
    f.add_feed(
        Bitmex(symbols=['BTC-USD'],
               channels=[L2_BOOK],
               callbacks={L2_BOOK: BookCallback(book)}))
    f.add_feed(
        Kraken(checksum_validation=True,
               subscription={
                   L2_BOOK: ['BTC-USD'],
                   TRADES: ['BTC-USD'],
                   TICKER: ['ETH-USD']
               },
               callbacks={
                   L2_BOOK: book,
                   TRADES: TradeCallback(trade),
                   TICKER: TickerCallback(ticker)
               }))
    sub = {TRADES: ['BTC-USDT', 'ETH-USDT'], L2_BOOK: ['BTC-USDT']}
    f.add_feed(
        Huobi(subscription=sub,
              callbacks={
                  TRADES: TradeCallback(trade),
                  L2_BOOK: BookCallback(book)
              }))
    f.add_feed(
        Huobi(candle_closed_only=True,
              symbols=['BTC-USDT'],
              channels=[CANDLES],
              callbacks={CANDLES: candle_callback}))
    sub = {L2_BOOK: ['BTC_CQ', 'BTC_NQ']}
    f.add_feed(
        HuobiDM(subscription=sub,
                callbacks={
                    TRADES: TradeCallback(trade),
                    L2_BOOK: BookCallback(book)
                }))
    pairs = ['BTC-USD', 'ETH-USD', 'EOS-USD', 'BCH-USD', 'BSV-USD', 'LTC-USD']
    f.add_feed(
        HuobiSwap(symbols=pairs,
                  channels=[TRADES, L2_BOOK, FUNDING],
                  callbacks={
                      FUNDING: funding,
                      TRADES: TradeCallback(trade),
                      L2_BOOK: BookCallback(book)
                  }))
    f.add_feed(
        OKCoin(symbols=['BTC-USD'],
               channels=[L2_BOOK],
               callbacks={L2_BOOK: BookCallback(book)}))
    f.add_feed(
        OKEx(symbols=['BTC-USDT'],
             channels=[TRADES],
             callbacks={TRADES: TradeCallback(trade)}))
    f.add_feed(
        Bittrex(subscription={
            TRADES: ['BTC-USD'],
            TICKER: ['ETH-USD'],
            L2_BOOK: ['BTC-USDT']
        },
                callbacks={
                    L2_BOOK: BookCallback(book),
                    TICKER: TickerCallback(ticker),
                    TRADES: TradeCallback(trade)
                }))
    f.add_feed(
        FTX(symbols=[
            'ADA-PERP', 'ALGO-PERP', 'ALT-PERP', 'ATOM-PERP', 'BCH-PERP',
            'BNB-PERP', 'BSV-PERP', 'BTC-PERP', 'BTMX-PERP', 'DOGE-PERP',
            'DRGN-PERP', 'EOS-PERP', 'ETC-PERP'
        ],
            channels=[TICKER],
            callbacks={
                TICKER: ticker,
                TRADES: TradeCallback(trade)
            }))
    f.add_feed(
        Bybit(symbols=['BTC-USDT', 'BTC-USD'],
              channels=[FUTURES_INDEX],
              callbacks={
                  OPEN_INTEREST: OpenInterestCallback(oi),
                  FUTURES_INDEX: FuturesIndexCallback(futures_index)
              }))
    f.add_feed(
        Bybit(symbols=['BTC-USDT', 'BTC-USD'],
              channels=[L2_BOOK, TRADES],
              callbacks={
                  TRADES: trade,
                  L2_BOOK: book
              }))
    f.add_feed(BLOCKCHAIN,
               symbols=['BTC-USD', 'ETH-USD'],
               channels=[L2_BOOK, TRADES],
               callbacks={
                   L2_BOOK: BookCallback(book),
                   TRADES: trade
               })
    f.add_feed(
        Bitmax(symbols=['XRP-USDT', 'BTC-USDT'],
               channels=[L2_BOOK],
               callbacks={
                   TRADES: trade,
                   L2_BOOK: book
               }))
    f.add_feed(
        Bitflyer(symbols=['BTC-JPY'],
                 channels=[L2_BOOK, TRADES, TICKER],
                 callbacks={
                     L2_BOOK: book,
                     BOOK_DELTA: delta,
                     TICKER: ticker,
                     TRADES: trade
                 }))
    f.add_feed(
        BinanceFutures(symbols=['BTC-USDT'],
                       channels=[TICKER],
                       callbacks={TICKER: ticker}))
    f.add_feed(
        BinanceFutures(subscription={
            TRADES: ['BTC-USDT'],
            CANDLES: ['BTC-USDT', 'BTC-USDT-PINDEX']
        },
                       callbacks={
                           CANDLES: candle_callback,
                           TRADES: trade
                       }))

    f.run()
Esempio n. 7
0
def main():
    fh = FeedHandler()

    # Add futures contracts
    callbacks = {TRADES: TradeCallback(trade), L2_BOOK: BookCallback(book), TRADES: trade, TICKER: TickerCallback(ticker)}
    pairs = OKEx.get_active_symbols()[:5]
    fh.add_feed(OKEx(pairs=pairs, channels=[TRADES, L2_BOOK, TICKER], callbacks=callbacks))
    # Add swaps. Futures and swaps could be added together in one feed, but its clearer to
    # add them as separate feeds.
    # EOS-USD-SWAP is from the swap exchange, BTC-USDT is from spot exchage.
    fh.add_feed(OKEx(pairs=['EOS-USD-SWAP', 'BTC-USDT'], channels=[L2_BOOK, TICKER, TRADES], callbacks={L2_BOOK: book, TRADES: trade, TICKER: ticker}))

    # Open Interest and Funding Rates
    fh.add_feed(OKEx(pairs=['EOS-USD-SWAP'], channels=[FUNDING], callbacks={FUNDING: funding}))
    fh.add_feed(OKEx(pairs=pairs, channels=[OPEN_INTEREST], callbacks={OPEN_INTEREST: open_int}))


    fh.run()
Esempio n. 8
0
def main():

    f = FeedHandler()
    #BitFinex
    f.add_feed(
        Bitfinex(pairs=['BTC-USD'],
                 channels=[L2_BOOK, TICKER],
                 callbacks={
                     L2_BOOK: BookCallback(book),
                     TICKER: TickerCallback(ticker)
                 }))
    f.add_feed(
        Bitfinex(pairs=['BTC-USD'],
                 channels=[TRADES],
                 callbacks={TRADES: TradeCallback(trade)}))
    f.add_nbbo([Bitfinex, Gemini, HitBTC, Bitstamp], ['BTC-USD'], nbbo_ticker)
    f.add_feed(
        Poloniex(channels=['USDT-BTC', 'USDC-BTC'],
                 callbacks={TICKER: TickerCallback(ticker)}))
    f.add_feed(
        Poloniex(channels=['USDT-BTC', 'USDC-BTC'],
                 callbacks={L2_BOOK: BookCallback(book)}))
    f.add_feed(
        Poloniex(channels=['USDT-BTC', 'USDC-BTC'],
                 callbacks={TRADES: TradeCallback(trade)}))
    f.add_feed(
        Gemini(pairs=['BTC-USD'],
               callbacks={
                   L2_BOOK: BookCallback(book),
                   TRADES: TradeCallback(trade)
               }))
    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(
        Bitmex(pairs=['XBTUSD'],
               channels=[TRADES],
               callbacks={TRADES: TradeCallback(trade)}))
    f.add_feed(
        Bitmex(pairs=['XBTUSD'],
               channels=[L3_BOOK],
               callbacks={L3_BOOK: BookCallback(book)}))
    f.add_feed(
        Bitstamp(channels=[L2_BOOK, TRADES],
                 pairs=['BTC-USD'],
                 callbacks={
                     L2_BOOK: BookCallback(book),
                     TRADES: TradeCallback(trade)
                 }))
    #f.add_nbbo([Bitfinex, Gemini], ['BTC-USD'], nbbo_ticker)

    f.add_feed(
        Bitfinex(pairs=['BTC-USD'],
                 channels=[TICKER],
                 callbacks={TICKER: TickerCallback(ticker)}))
    f.add_feed(
        Gemini(pairs=['BTC-USD'], callbacks={TICKER: TickerCallback(ticker)}))
    f.add_feed(
        HitBTC(pairs=['BTC-USD'],
               channels=[TICKER],
               callbacks={TICKER: TickerCallback(ticker)}))
    #f.add_feed(Bitmex(Bitstamp=['BTC-USD'], channels=[TICKER], callbacks={TICKER: TickerCallback(ticker)}))
    f.run()
def main():
    fh = FeedHandler()

    sub = {OPEN_INTEREST: ['PI_XBTUSD', 'PI_ETHUSD'], TRADES: ['PI_XBTUSD'], TICKER: ['PI_XBTUSD', 'PI_ETHUSD'], L2_BOOK: ['PI_ETHUSD', 'PI_XBTUSD'], FUNDING: ['PI_XBTUSD']}
    fh.add_feed(KrakenFutures(subscription=sub, callbacks={OPEN_INTEREST: oi, FUNDING: funding, TICKER: TickerCallback(ticker), TRADES: TradeCallback(trade), L2_BOOK: BookCallback(book)}))

    fh.run()
Esempio n. 10
0
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],
                 callbacks={
                     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=[INSTRUMENT],
               pairs=['XBTUSD'],
               callbacks={INSTRUMENT: InstrumentCallback(instrument)}))
    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-USD', 'ETH-USD', 'BTC-USDT', 'ETH-USDT'],
        L2_BOOK: ['BTC-USD', 'BTC-USDT']
    }
    f.add_feed(
        HuobiUS(config=config,
                callbacks={
                    TRADES: TradeCallback(trade),
                    L2_BOOK: BookCallback(book)
                }))

    config = {TRADES: ['BTC-USDT', 'ETH-USDT'], L2_BOOK: ['BTC-USDT']}
    f.add_feed(
        Huobi(config=config,
              callbacks={
                  TRADES: TradeCallback(trade),
                  L2_BOOK: BookCallback(book)
              }))
    config = {L2_BOOK: ['BTC_CQ']}
    f.add_feed(
        HuobiDM(config=config,
                callbacks={
                    TRADES: TradeCallback(trade),
                    L2_BOOK: BookCallback(book)
                }))

    f.add_feed(
        OKCoin(pairs=['BTC-USD'],
               channels=[L2_BOOK],
               callbacks={L2_BOOK: BookCallback(book)}))
    f.add_feed(
        OKEx(pairs=['BTC-USDT'],
             channels=[TRADES],
             callbacks={TRADES: TradeCallback(trade)}))
    f.add_feed(
        Coinbene(channels=[L2_BOOK, TRADES, TICKER],
                 pairs=['BTC-USDT'],
                 callbacks={
                     L2_BOOK: BookCallback(book),
                     TICKER: TickerCallback(ticker),
                     TRADES: TradeCallback(trade)
                 }))
    f.add_feed(
        Bittrex(config={
            TRADES: ['BTC-USD'],
            TICKER: ['ETH-USD'],
            L2_BOOK: ['BTC-USDT']
        },
                callbacks={
                    L2_BOOK: BookCallback(book),
                    TICKER: TickerCallback(ticker),
                    TRADES: TradeCallback(trade)
                }))

    f.run()
def main():
    f = FeedHandler(config='config.yaml')
    f.add_feed(BEQUANT,
               channels=[TICKER],
               symbols=['ADA-USDT'],
               callbacks={TICKER: TickerCallback(ticker)})
    f.add_feed(HITBTC,
               channels=[TICKER],
               symbols=['XLM-USDT'],
               callbacks={TICKER: TickerCallback(ticker)})
    f.add_feed(BEQUANT,
               channels=[L2_BOOK],
               symbols=['ALGO-USDT'],
               callbacks={L2_BOOK: (book)})
    f.add_feed(HITBTC,
               channels=[L2_BOOK],
               symbols=['ATOM-USDT'],
               callbacks={L2_BOOK: (book)})
    f.add_feed(BEQUANT,
               channels=[CANDLES],
               candle_interval='30m',
               symbols=['ETH-USDT'],
               callbacks={CANDLES: candles_callback})
    f.add_feed(HITBTC,
               channels=[CANDLES],
               candle_interval='30m',
               symbols=['NEO-USDT'],
               callbacks={CANDLES: candles_callback})
    f.add_feed(BEQUANT,
               channels=[TRADES],
               symbols=['XLM-USDT'],
               callbacks={TRADES: trade})
    f.add_feed(HITBTC,
               channels=[TRADES],
               symbols=['DASH-USDT'],
               callbacks={TRADES: trade})

    # The following channels are authenticated (non public). Make sure you have set the correct privileges on your API key(s)
    f.add_feed(BEQUANT,
               subscription={ORDER_INFO: ['BTC-USD', 'ETH-USD']},
               callbacks={ORDER_INFO: order})
    f.add_feed(HITBTC,
               subscription={ORDER_INFO: ['BTC-USDT', 'ETH-USDT']},
               callbacks={ORDER_INFO: order})
    f.add_feed(BEQUANT,
               timeout=-1,
               channels=[BALANCES],
               symbols=['XLM-USDT'],
               callbacks={BALANCES: BalancesCallback(balances)})
    f.add_feed(HITBTC,
               timeout=-1,
               channels=[BALANCES],
               symbols=['ADA-USDT'],
               callbacks={BALANCES: BalancesCallback(balances)})
    f.add_feed(BEQUANT,
               timeout=-1,
               channels=[TRANSACTIONS],
               symbols=['ADA-USDT'],
               callbacks={TRANSACTIONS: TransactionsCallback(transactions)})
    f.add_feed(HITBTC,
               timeout=-1,
               channels=[TRANSACTIONS],
               symbols=['ADA-USDT'],
               callbacks={TRANSACTIONS: TransactionsCallback(transactions)})
    f.run()
Esempio n. 12
0
kraken = requests.get("https://futures.kraken.com/derivatives/api/v3/tickers").json()

for market in kraken['tickers']:
    if 'tag' in market:
        kcontracts.append(market['symbol'].upper())
#print(kcontracts)
config = {TICKER: kcontracts}
fh.add_feed(KrakenFutures(config=config, callbacks={TICKER: TickerCallback(ticker)}))
"""
fcontracts = []
ftxmarkets = requests.get("https://ftx.com/api/futures").json()['result']
for market in ftxmarkets:
    if 'MOVE' not in market['name'] and 'HASH' not in market['name']:
        fcontracts.append(market['name'])
config = {TICKER: fcontracts}
fh.add_feed(FTX(config=config, callbacks={TICKER: TickerCallback(ticker)}))
#loop = asyncio.get_event_loop()

t = threading.Thread(target=loop_in_thread, args=())
t.start()

#t = threading.Thread(target=loop_in_thread2, args=())
#t.start()
print(expis)

import random, string
import requests
import math

funding = {}
exchanges = ['binance']  #['binance', 'kraken', 'ftx', 'phemex', 'okex']
Esempio n. 13
0
def main():
    f = FeedHandler()
    f.add_feed(Coinbase(symbols=['BTC-USD'], channels=[TICKER], callbacks={TICKER: TickerCallback(ticker)}))

    f.run()