Exemplo n.º 1
0
from datetime import datetime

from cryptofeed import FeedHandler
from cryptofeed.defines import L2_BOOK
from cryptofeed.exchanges import BinanceDelivery

data_info = BinanceDelivery.info()


async def abook(feed, pair, book, timestamp, receipt_timestamp):
    print(
        f'BOOK lag: {receipt_timestamp - timestamp} Timestamp: {datetime.fromtimestamp(timestamp)} Receipt Timestamp: {datetime.fromtimestamp(receipt_timestamp)} Feed: {feed} Pair: {pair} Snapshot: {book}'
    )


async def delta(feed, pair, delta, timestamp, receipt_timestamp):
    print(
        f'DELTA lag: {receipt_timestamp - timestamp} Timestamp: {datetime.fromtimestamp(timestamp)} Receipt Timestamp: {datetime.fromtimestamp(receipt_timestamp)} Feed: {feed} Pair: {pair} Delta: {delta}'
    )


def main():
    f = FeedHandler()
    f.add_feed(
        BinanceDelivery(max_depth=3,
                        pairs=['BTC-USD_201225'],
                        channels=[L2_BOOK],
                        callbacks={L2_BOOK: abook}))
    f.run()

Exemplo n.º 2
0
import asyncio
from datetime import datetime
from collections import defaultdict
from multiprocessing import Process
import os
from pathlib import Path
import sys
from yapic import json

from cryptofeed import FeedHandler
from cryptofeed.backends.zmq import CandlesZMQ, FundingZMQ, FuturesIndexZMQ, TickerZMQ, TradeZMQ, VolumeZMQ, UserBalanceZMQ, UserPositionZMQ
from cryptofeed.defines import CANDLES, FUTURES_INDEX, L2_BOOK, FUNDING, TICKER, PERPETUAL, FUTURE, TRADES, VOLUME, USER_BALANCE, USER_POSITION
from cryptofeed.exchanges import BinanceFutures, BinanceDelivery, Binance

binance_delivery_data_info = BinanceDelivery.info()
# binance_futures_data_info = BinanceFutures.info()
binance_data_info = Binance.info()
print(binance_data_info)

import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

def receiver(port):
    async def listen():
        while True:
            data = await s.recv_string()
            print(data)
            key, msg = data.split(" ", 1)
            print(key)
            # print(json.loads(msg))
            msg = json.loads(msg)