def main(): # noqa: E302 global marketTable if (len(sys.argv) > 1): with open(sys.argv[1]) as f: config = BaseExchange.extend({}, baseConfig, json.load(f)) else: config = BaseExchange.extend({}, baseConfig) marketTable = MarketTable(config['marketTable']) for id in config['exchanges'].keys(): exchange = config['exchanges'][id] exConf = BaseExchange.extend( {}, config['exchangeDefaults'], exchange['options'] if 'options' in exchange else {}) ex = getattr(ccxt, id)({ 'apiKey': exConf['apiKey'] if 'apiKey' in exConf else '', 'secret': exConf['apiSecret'] if 'apiSecret' in exConf else '', 'enableRateLimit': True, 'verbose': exConf['verbose'] if 'verbose' in exConf else False, }) for symbol in exchange['symbols'].keys(): marketTable.addMarket(ex.id, symbol) asyncio.ensure_future(subscribe(ex, exchange['symbols'], config['symbolDefaults']), loop=loop)
async def subscribe(exchange, symbols, defaultConfig): # noqa: E302 @exchange.on('err') def websocket_error(err, conxid): # pylint: disable=W0612 print(err) try: exchange.websocketClose(conxid) except ccxt.BaseError: pass for symbol in symbols.keys(): marketTable.marketError(exchange.id, symbol, err) marketTable.print() @exchange.on('ob') def websocket_ob(market, ob): # pylint: disable=W0612 marketTable.updateMarket(exchange.id, market, ob) marketTable.print() try: await exchange.load_markets() for symbol in symbols.keys(): sys.stdout.flush() config = BaseExchange.extend({}, defaultConfig, symbols[symbol]) try: await exchange.websocket_subscribe('ob', symbol, config) except Exception as ex: print(ex) sys.stdout.flush() marketTable.marketError(exchange.id, symbol, ex) marketTable.print() except Exception as ex: print(ex) sys.stdout.flush() for symbol in symbols.keys(): marketTable.marketError(exchange.id, symbol, ex) marketTable.print()
def __init__(self, options): self.options = BaseExchange.extend({}, { "marketsByRow": 2, "maxLimit": 10, "marketColumnWidth": 50, }, options) self.markets = {} self.grid = [] self.newEmptyLine = ' ' * (self.options['marketColumnWidth'] * self.options['marketsByRow']) self.hr = "-" * (self.options['marketColumnWidth']) self.bidsAdksSeparator = "." * (self.options['marketColumnWidth']) self.emptyCell = " " * (self.options['marketColumnWidth']) self.amountColumn = self.options['marketColumnWidth'] // 2 self.height = 2 + self.options['maxLimit'] + 1 + self.options[ 'maxLimit'] + 1