Exemplo n.º 1
0
async def main():
    exchange = ccxtpro.bitmex({
        'enableRateLimit': True,
        # 'options': {
        #     'OHLCVLimit': 1000, # how many candles to store in memory by default
        # },
    })
    symbol = 'BTC/USD'
    timeframe = '1m'  # 5m, 1h, 1d
    limit = 10  # how many candles to return max
    method = 'watchOHLCV'
    if (method in exchange.has) and exchange.has[method]:
        max_iterations = 100  # how many times to repeat the loop before exiting
        for i in range(0, max_iterations):
            try:
                ohlcvs = await exchange.watch_ohlcv(symbol, timeframe, None,
                                                    limit)
                now = exchange.milliseconds()
                print(
                    '\n==============================================================================='
                )
                print('Loop iteration:', i, 'current time:',
                      exchange.iso8601(now), symbol, timeframe)
                print(
                    '-------------------------------------------------------------------------------'
                )
                print(table([[exchange.iso8601(o[0])] + o[1:]
                             for o in ohlcvs]))
            except Exception as e:
                print(type(e).__name__, str(e))
                break
        await exchange.close()
    else:
        print(exchange.id, method, 'is not supported or not implemented yet')
Exemplo n.º 2
0
async def main():
    exchange = ccxtpro.bitmex()
    await exchange.load_markets()
    duration = 1200000  # run 20 minutes = 1200000 milliseconds
    symbol = 'BTC/USD'
    limit = 10
    loops = [
        watch_ticker('\033[35m', duration, exchange, symbol),              # magenta
        watch_ohlcv('\x1b[33m', duration, exchange, symbol, '1m', limit),  # yellow
        watch_ohlcv('\x1b[32m', duration, exchange, symbol, '5m', limit),  # green
    ]
    await gather(*loops)
    await exchange.close()
Exemplo n.º 3
0
import ccxtpro
from asyncio import get_event_loop


async def consume_all_trades(exchange, symbol):
    await exchange.load_markets()
    while True:
        try:
            trades = await exchange.watch_trades(symbol)
            print('----------------------------------------------------------------------')
            print(exchange.iso8601(exchange.milliseconds()), 'received', len(trades), 'new', symbol, 'trades:')
            for trade in trades:
                print(exchange.id, symbol, trade['id'], trade['datetime'], trade['amount'], trade['price'])
            exchange.trades[symbol].clear()
        except Exception as e:
            print(type(e).__name__, str(e))
    await exchange.close()


loop = get_event_loop()
exchange = ccxtpro.bitmex({
    'enableRateLimit': True,
    'asyncio_loop': loop,
})

symbol = 'BTC/USD'

loop.run_until_complete(consume_all_trades(exchange, symbol))
Exemplo n.º 4
0
import ccxtpro
from asyncio import run


async def consume_all_trades(exchange, symbol):
    await exchange.load_markets()
    while True:
        try:
            trades = await exchange.watch_trades(symbol)
            print(
                '----------------------------------------------------------------------'
            )
            print(exchange.iso8601(exchange.milliseconds()), 'received',
                  len(trades), 'new', symbol, 'trades:')
            for trade in trades:
                print(exchange.id, symbol, trade['id'], trade['datetime'],
                      trade['amount'], trade['price'])
            exchange.trades[symbol].clear()
        except Exception as e:
            print(type(e).__name__, str(e))
    await exchange.close()


exchange = ccxtpro.bitmex()
symbol = 'BTC/USD'
run(consume_all_trades(exchange, symbol))