예제 #1
0
async def main():
    async with BinanceFutures() as exchange:
        streams = [CandleStream(exchange, 'btcusdt', '1h'), TradeStream(exchange, 'ltcusdt')]
        await exchange.persist_streams(streams)
        async with MixedStream(streams) as stream:
            for i in range(20):
                substream, data = await stream.read()
                log.info(f'{substream}: {data}')
예제 #2
0
async def main():
    async with BinanceFutures() as exchange:
        symbols = ['btcusdt', 'ethusdt']
        watch_market_tasks = [
            asyncio.get_event_loop().create_task(watch_market(
                exchange, symbol)) for symbol in symbols
        ]
        await asyncio.wait(watch_market_tasks)
예제 #3
0
async def main():
    async with BinanceFutures(API_KEY, API_SECRET) as exchange:
        order = Order(symbol='btcusdt', size=Decimal('0.001'), type='limit',  side='buy',  price=Decimal('1000'), post_only=True)
        await exchange.submit_order(order)
        async with OrderUpdateStream(exchange, order) as stream:
            log.info('** please cancel the order in your binance account and see the update here')
            update = await stream.read()
            log.info(update)
예제 #4
0
async def main():
    async with BinanceFutures(API_KEY, API_SECRET) as exchange:
        log.info('waiting for current candle to close')
        async with CandleStream(exchange, SYMBOL, '1m') as stream:
            while True:
                candle = await stream.read()
                log.info(f'candle: {candle}')
                if candle.closed:
                    break
        log.info('creating orders')
        orders = [
            Order(symbol=SYMBOL,
                  size=SIZE,
                  type='market',
                  side='sell',
                  stop_price=candle.low - STOP,
                  reduce_only=True),
            Order(symbol=SYMBOL,
                  size=SIZE,
                  type='market',
                  side='buy',
                  stop_price=candle.high + STOP,
                  reduce_only=True),
            Order(symbol=SYMBOL,
                  size=SIZE,
                  type='limit',
                  side='buy',
                  price=candle.low),
            Order(symbol=SYMBOL,
                  size=SIZE,
                  type='limit',
                  side='sell',
                  price=candle.high),
        ]
        for order in orders:
            await exchange.submit_order(order)
        log.info('watching updates from orders')
        async with MixedStream(
            [OrderUpdateStream(exchange, o) for o in orders]) as stream:
            while True:
                update = await stream.read()
                log.info(update)
예제 #5
0
async def main():
    async with BinanceFutures() as exchange:
        async with CandleStream(exchange, 'btcusdt', '3m') as stream:
            for i in range(10):
                candle = await stream.read()
                log.info(candle)
        log.info('*** there is an unnecessary stream reconnection here:')
        async with CandleStream(exchange, 'btcusdt', '3m') as stream:
            for i in range(10):
                candle = await stream.read()
                log.info(candle)
            log.info(
                '*** you can avoid the extra stream reconnection by persisting the stream:'
            )
            await exchange.persist_streams([stream])
        log.info('*** no annoying reconnection delays here:')
        async with CandleStream(exchange, 'btcusdt', '3m') as stream:
            for i in range(10):
                candle = await stream.read()
                log.info(candle)
예제 #6
0
async def main():
    async with BinanceFutures() as exchange:
        async with TradeStream(exchange, 'btcusdt') as stream:
            for i in range(10):
                trade = await stream.read()
                log.info(trade)
예제 #7
0
async def main():
    async with BinanceFutures() as exchange:
        async with CandleStream(exchange, 'btcusdt', '3m') as stream:
            for i in range(10):
                candle = await stream.read()
                log.info(candle)
예제 #8
0
async def main():
    async with BinanceFutures() as exchange:
        trades = await exchange.trade_history('btcusdt', datetime(2020, 1, 1),
                                              10)
        pretty = '\n'.join([str(t) for t in trades])
        log.info(pretty)
예제 #9
0
async def main():
    async with BinanceFutures() as exchange:
        candles = await exchange.candle_history('btcusdt', '1d', datetime(2021, 1, 1), 10)
        pretty = '\n'.join([str(c) for c in candles])
        log.info(pretty)