# https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#trade-streams # https://github.com/sammchardy/python-binance/blob/c66695a785e8d3cf0975d09b624f79772dac4115/binance/websockets.py#L254 bm.start_trade_socket(va.symbol, process_message) bm.start() if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('-t', '--ticker', help='Ticker', default='BTCUSDT') args = parser.parse_args() client = Client( "DdEn5fpqEAekNJCVYmflOY9pLfIozLTjU4qXm5HqB9vyFh9PAB7LNdBWPjrkHf43", "c5NjpuJPGYgQZ60ZUXE3z6FQTV3YVOTNVz5JZ5aW2ST3uTJM65mykaFjCDMhPa1D") exinfo = client.get_exchange_info() symbol_hashes = {} for s in exinfo['symbols']: symbol_hashes[s['symbol']] = { 'symbol': s['symbol'], 'base_asset': s['baseAsset'], 'quote_asset': s['quoteAsset'], } if args.ticker not in symbol_hashes: raise SystemExit(args.ticker + ' is an invalid binance ticker') global va va = VolumeAnalyser('Binance') va.set_symbol_info(symbol_hashes[args.ticker]) main()
#!/usr/bin/env python import sys import json import signal from websocket import create_connection from volumne_analyser import VolumeAnalyser from pprint import pprint from datetime import datetime if __name__ == "__main__": #validates volume on Kraken's XBT/EUR pair global dabestbid, dabestask, last_book_update, va va = VolumeAnalyser('Kraken', output_print=True) dabestbid = dabestask = last_book_update = 0 def dicttofloat(keyvalue): return float(keyvalue[0]) def get_last_book_update(): return last_book_update def best_bid(): bid = sorted(api_book["bid"].items(), key=dicttofloat, reverse=True) return bid[0][0] def best_ask(): ask = sorted(api_book["ask"].items(), key=dicttofloat) return ask[0][0]
#!/usr/bin/env python import sys import json import signal from websocket import create_connection from volumne_analyser import VolumeAnalyser from pprint import pprint from datetime import datetime if __name__ == "__main__": va = VolumeAnalyser('FTX') va.set_symbol_info({ 'symbol': 'BTC-PERP', 'base_asset': 'BTC', 'quote_asset': 'USD' }) bestbid = bestask = legitvol = fakevol = num_fake_trades = num_legit_trades = 0 bidsd = {} asksd = {} api_domain = "wss://ftx.com/ws/" try: ws = create_connection(api_domain) except Exception as error: print("WebSocket connection failed (%s)" % error) sys.exit(1) ws.send( json.dumps({
#!/usr/bin/env python import sys import json import signal from websocket import create_connection from volumne_analyser import VolumeAnalyser from pprint import pprint if __name__ == "__main__": va = VolumeAnalyser('Bitstamp', output_print=True) bestbid = bestask = legitvol = fakevol = num_fake_trades = num_legit_trades = 0 bidsd = {} asksd = {} last_update = 0 api_domain = "wss://ws.bitstamp.net" try: ws = create_connection(api_domain) except Exception as error: print("WebSocket connection failed (%s)" % error) sys.exit(1) ws.send( json.dumps({ "event": "bts:subscribe", "data": { "channel": "order_book_btcusd" } }))
def __init__(self, exchange, output_print=True): VolumeAnalyser.__init__(self, exchange, output_print)
ts = datetime.strptime(message['time'], "%Y-%m-%dT%H:%M:%S.%fZ") ts_milis = (ts - datetime.utcfromtimestamp(0)).total_seconds() * 1000 data = { 'ts': ts_milis, 'price': float(message['price']), 'qty': float(message['size']), } va.process_trade_entry(data) va.print_summary() if __name__ == "__main__": va = VolumeAnalyser('Coinbase') va.set_symbol_info({ 'symbol': 'BTCUSD', 'base_asset': 'BTC', 'quote_asset': 'USD' }) product_id = "BTC-USD" loop = asyncio.get_event_loop() channelt = Channel('level2', product_id) channelm = Channel('matches', product_id) ticker = Ticker(loop, channelt) ticker = Ticker(loop, channelm)
ts = datetime.strptime(message['time'], "%Y-%m-%dT%H:%M:%S.%fZ") ts_milis = (ts - datetime.utcfromtimestamp(0)).total_seconds() * 1000 data = { 'ts': ts_milis, 'price': float(message['price']), 'qty': float(message['size']), } va.process_trade_entry(data) va.print_summary() if __name__ == "__main__": va = VolumeAnalyser('Coinbase', output_print=True) product_id = "BTC-USD" loop = asyncio.get_event_loop() channelt = Channel('level2', product_id) channelm = Channel('matches', product_id) ticker = Ticker(loop, channelt) ticker = Ticker(loop, channelm) try: loop.run_forever() except KeyboardInterrupt: loop.run_until_complete(ticker.close()) loop.close()