Esempio n. 1
0
    def load_exchange(self):
        self.exchange = ccxt.bitmex({
            'apiKey': self.key,
            'secret': self.secret,
            'timeout': 30000,
            'enableRateLimit': True,
        })

        if self.test_mode:
            if 'test' in self.exchange.urls:
                self.exchange.urls['api'] = self.exchange.urls['test']
        self.exchange.open()
Esempio n. 2
0
async def test():
    bitmex = ccxt.bitmex({
        'apiKey': "9NTAdyDunRjHCuCEOEiK5rMI",
        'secret': "gXtFv11oGkvQ4XtpE-xXM-oigVClwEZ2XMHKKlmpGt0kHXRq",
        'verbose': True,  # switch it to False if you don't want the HTTP log
    })
    markets = await bitmex.load_markets()
    open(__DIR__ + '/symbols.txt', 'w').close()

    for symbol in bitmex.symbols:
        add_to_symbols(symbol)

    await bitmex.close()
            orderbook['asks_volume'] = orderbook.asks.apply(lambda x: x[1])
            orderbook.drop(['bids', 'asks', 'datetime', 'nonce'],
                           axis=1,
                           inplace=True)
            orderbook.to_csv('order_book-{}.csv'.format(
                (datetime.now()).strftime('%Y %m %d %H %M %S')),
                             index=False)

            print(exchange.iso8601(exchange.milliseconds()), 'stored', symbol,
                  'ticker from', exchange.name)

    except KeyboardInterrupt:
        exchange.close()
        print('interrupted!')


# you can set enableRateLimit = True to enable the built-in rate limiter
# this way you request rate will never hit the limit of an exchange
# the library will throttle your requests to avoid that

exchange = ccxt.bitmex({
    'enableRateLimit': True,  # this option enables the built-in rate limiter
})

try:
    asyncio.get_event_loop().run_until_complete(main(exchange, 'BTC/USD'))

except KeyboardInterrupt:
    exchange.close()
    print('interrupted!')
Esempio n. 4
0
    def __init__(self, loop, config):

        self.ob_constant = OD_TICK_TIMER
        self.bl_constant = BALANCE_TICK_TIMER
        self.trade_constant = TRADE_TICK_TIMER

        self.stop_tick_time = datetime.datetime.now() + datetime.timedelta(
            seconds=TICK_TIMER)
        self.orderbook_tick_time = datetime.datetime.now(
        ) + datetime.timedelta(seconds=self.ob_constant)
        self.balance_tick_time = datetime.datetime.now() + datetime.timedelta(
            seconds=self.bl_constant)
        self.trade_tick_time = datetime.datetime.now() + datetime.timedelta(
            seconds=self.trade_constant)
        self.info_tick_time = datetime.datetime.now() + datetime.timedelta(
            seconds=INFO_TIMER)

        self.config = config
        self.orderbook_count = 0
        self.pair_info = dict()
        self.logger = None
        if 'logger' in self.config.keys():
            self.logger = self.config['logger']

        self.exhange = config['exchange']
        self.is_auth = False
        self.name = '[ccxt %s]' % self.exhange
        self.pair_list = set()

        if self.exhange == 'liqui':
            self.ob_constant = 30
            self.bl_constant = 60

        self.ccxt_it_queue = self.config['ccxt_in_queue']
        self.ccxt_out_queue = self.config['ccxt_out_queue']

        self.pair_list = self.config['pairs']

        # for i in self.config['pairs']:
        #     i['balance_tick'] = True
        #     self.pair_list.add( i['name'] )

        auth = {}
        if 'auth' in self.config.keys():
            auth = self.config['auth']
            self.is_auth = True
            self.name = '[ccxt %s %s*]' % (self.exhange, auth['apiKey'][:4])

        asyncio.set_event_loop(loop)

        if self.exhange == 'hitbtc':
            loop.create_task(self.run_loop(ccxt.hitbtc(auth)))
        elif self.exhange == 'coinmarketcap':
            loop.create_task(self.run_loop(ccxt.coinmarketcap()))
        elif self.exhange == 'binance':
            loop.create_task(self.run_loop(ccxt.binance(auth)))
        elif self.exhange == 'bitmex':
            loop.create_task(self.run_loop(ccxt.bitmex(auth)))
        elif self.exhange == 'huobipro':
            loop.create_task(self.run_loop(ccxt.huobipro()))
        elif self.exhange == 'liqui':
            loop.create_task(self.run_loop(ccxt.liqui(auth)))
        elif self.exhange == 'bitfinex2':
            loop.create_task(self.run_loop(ccxt.bitfinex2(auth)))
        elif self.exhange == 'bitfinex':
            loop.create_task(self.run_loop(ccxt.bitfinex(auth)))
        elif self.exhange == 'okex':
            loop.create_task(self.run_loop(ccxt.okex(auth)))
        elif self.exhange == 'kucoin':
            loop.create_task(self.run_loop(ccxt.kucoin(auth)))
        elif self.exhange == 'bittrex':
            loop.create_task(self.run_loop(ccxt.bittrex(auth)))
        elif self.exhange == 'qryptos':
            loop.create_task(self.run_loop(ccxt.qryptos(auth)))
        elif self.exhange == 'kraken':
            loop.create_task(self.run_loop(ccxt.kraken(auth)))

        loop.run_forever()