예제 #1
0
async def main(symbol: str, future: bool):
    market_type = "future" if future else "spot"
    print(f'Started Collecting Tick Data of {symbol}...({market_type} market)')
    client = await AsyncClient.create()
    bsm = BinanceSocketManager(client)

    if future:
        async with bsm.aggtrade_futures_socket(symbol) as socket:
            while True:
                res = await socket.recv()
                process_message(res['data'], future)
    else:
        async with bsm.trade_socket(symbol) as socket:
            while True:
                res = await socket.recv()
                process_message(res, future)
예제 #2
0
async def main():
    client = await AsyncClient.create()
    bm = BinanceSocketManager(client)
    # start any sockets here, i.e a trade socket
    ts = bm.trade_socket("BTCUSDT")
    # then start receiving messages
    start = None
    async with ts as tscm:
        while True:
            res = await tscm.recv()
            res_time = float(res['T'])/1000
            if not start:
                start = res_time
            elif res_time-start > 3:
                break
            print(start, res_time, res_time - start)
    await client.close_connection()