async def main(): exchange = ccxtpro.binance({ # 'options': { # 'OHLCVLimit': 1000, # how many candles to store in memory by default # }, }) symbol = 'ETH/USDT' # or BNB/USDT, etc... 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 = 100000 # 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')
async def main(): exchange = ccxtpro.binance({ 'apiKey': 'YOUR_API_KEY', 'secret': 'YOUR_SECRET', }) await watch_balance(exchange) await exchange.close()
async def main(): exchange = ccxtpro.binance({ "apiKey": "", "secret": "", 'emableRateLimit': True, 'newUpdates': True, }) # you must make a an order a transfer first to the websocket to send updates asyncio.ensure_future(print_balance(exchange, 'future')) asyncio.ensure_future(print_balance(exchange, 'delivery')) # inverse futures settled in BTC asyncio.ensure_future(print_balance(exchange, 'spot'))
async def main(): exchange = ccxtpro.binance() await exchange.load_markets() # exchange.verbose = True symbol = 'BTC/USDT' delay = 60000 # every minute = 60 seconds = 60000 milliseconds loops = [ watch_order_book(exchange, symbol), reload_markets(exchange, delay) ] await gather(*loops) await exchange.close()
async def main(): exchange = ccxtpro.binance({ 'options': { 'defaultType': 'future', }, }) symbol = 'BTC/USDT' while True: try: orderbook = await exchange.watch_order_book(symbol) print(orderbook['bids'][0], orderbook['asks'][0]) except Exception as e: print(type(e).__name__, str(e)) await exchange.close()
async def main(): exchange = ccxtpro.binance({ 'apiKey': 'YOUR_API_KEY', 'secret': 'YOUR_SECRET', }) await exchange.load_markets() symbol = 'BTC/USDT' while True: try: loops = [ watch_order_book(exchange, symbol), watch_balance(exchange, symbol) ] await gather(*loops) except Exception as e: print(type(e).__name__, str(e)) break await exchange.close()
async def main(loop): exchange = ccxtpro.binance({ 'asyncio_loop': loop, 'enableRateLimit': True, 'options': { 'defaultType': 'future', # spot, margin, future, delivery }, }) symbol = 'BTC/USDT' while True: try: orderbook = await exchange.watch_order_book(symbol) print(exchange.iso8601(exchange.milliseconds()), exchange.id, symbol, 'ask:', orderbook['asks'][0], 'bid:', orderbook['bids'][0]) except Exception as e: print(type(e).__name__, str(e)) break await exchange.close()
async def main(): exchange = ccxtpro.binance({ 'apiKey': 'YOUR_API_KEY', 'secret': 'YOUR_SECRET', }) markets = await exchange.load_markets() # exchange.verbose = True # uncomment for debugging purposes if necessary symbol = 'ETH/BTC' type = 'limit' # or 'market' side = 'sell' # or 'buy' amount = 1.0 price = 0.060154 # or None order = await exchange.create_order(symbol, type, side, amount, price) canceled = await exchange.cancel_order(order['id'], order['symbol']) pprint(canceled) await exchange.close()
async def main(): exchange = ccxt.binance({ 'apiKey': 'YOUR_API_KEY', 'secret': 'YOUR_SECRET', 'options': { 'defaultType': 'margin', }, # comment it out if you don't want debug output # this is for the demo purpose only (to show the communication) 'verbose': True, }) while True: try: balance = await exchange.watch_balance() # it will print the balance update when the balance changes # if the balance remains unchanged the exchange will not send it pprint(balance) except Exception as e: print('watch_balance() failed') print(e) break await exchange.close()
async def main(): exchange_spot = ccxtpro.binance() await exchange_spot.load_markets() await watch_some_orderbooks( exchange_spot, ['ZEN/USDT', 'RUNE/USDT', 'AAVE/USDT', 'SNX/USDT']) await exchange_spot.close()