def get_tickers(self): logger.info('Ready to fetch tickers tasks....\n' + date_utils.current(Y_M_D_H_M_S)) exchanges = [ ccxt.bitfinex2({'userAgent': USER_AGENT}), ccxt.bittrex({'userAgent': USER_AGENT}), ccxt.poloniex({'userAgent': USER_AGENT}), ccxt.hitbtc2({'userAgent': USER_AGENT}), ccxt.cryptopia({'userAgent': USER_AGENT}), ccxt.livecoin({'userAgent': USER_AGENT}), ccxt.kucoin({'userAgent': USER_AGENT}), ccxt.okex({'userAgent': USER_AGENT}), ccxt.coinexchange({'userAgent': USER_AGENT}), ccxt.binance({'userAgent': USER_AGENT}), ccxt.bithumb({'userAgent': USER_AGENT}), ccxt.kraken({'userAgent': USER_AGENT}) ] tasks = [] for i in range(len(exchanges)): task = self.fetch_tickers_task(exchanges[i]) tasks.append(asyncio.ensure_future(task)) loop = asyncio.get_event_loop() loop.run_until_complete(asyncio.wait(tasks)) loop.close() self.spider_repository.close()
def background_job(self): 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.ccxt_in_queue = self.config['in_queue'] self.ccxt_out_queue = self.config['out_queue'] 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]) loop = asyncio.new_event_loop() 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()
}) itbit = ccxt.itbit({ 'enableRateLimit': True, 'rateLimit': 1000, }) jubi = ccxt.jubi({ 'enableRateLimit': True, 'rateLimit': 1000, }) kraken = ccxt.kraken({ 'enableRateLimit': True, 'rateLimit': 1000, }) kucoin = ccxt.kucoin({ 'enableRateLimit': True, 'rateLimit': 1000, "apiKey": "5a92a5e003d644701f1a9c56", "secret": "400e8874-e3cf-43f1-8765-63e4b7f535a5", }) kuna = ccxt.kuna({ 'enableRateLimit': True, 'rateLimit': 1000, }) lakebtc = ccxt.lakebtc({ 'enableRateLimit': True, 'rateLimit': 1000, }) liqui = ccxt.liqui({ 'enableRateLimit': True, 'rateLimit': 1000, }) livecoin = ccxt.livecoin({
async def print_complex_arbs_task(self): while True: self.print_arbs(self.complex_arbs()) await asyncio.sleep(1) async def populate_task(self, exchange): while True: try: await self.exchange_rates.populate( exchange, blacklisted=self.blacklisted) except (TimeoutError, RequestTimeout, ExchangeError) as e: logging.error(e) await asyncio.sleep(5) if __name__ == "__main__": EXCHANGES = { ccxt.bittrex({'enableRateLimit': True}), ccxt.gdax({'enableRateLimit': True}), ccxt.kraken({'enableRateLimit': True}), ccxt.poloniex({'enableRateLimit': True}), FastCryptopia({'enableRateLimit': True}), ccxt.gemini({'enableRateLimit': True}), ccxt.kucoin({'enableRateLimit': True}), ccxt.binance({'enableRateLimit': True}) } logging.basicConfig(level=logging.INFO) start_with = ("ETH", 10) arbs = Sharpshooter(EXCHANGES, start_with).run_once() Sharpshooter.print_arbs(arbs)
def main_loop(): kucoin = ccxt.kucoin() threads = {} counter = 0 while True: try: kcmarkets = kucoin.load_markets(True) pairings = [] ethbuy = 0.0 ethsell = 0.0 valset = False for key, value in kcmarkets.items(): base = value['base'] quote = value['quote'] if base == 'ETH' or quote == 'ETH': if base != 'ETH': tocheck = base else: tocheck = quote if not tocheck in pairings and tocheck != 'BTC': pairings.append(tocheck) if not valset and base == 'BTC' and quote == 'ETH': ethbuy = value['info']['buy'] ethsell = value['info']['sell'] valset = True elif not valset and base == 'ETH' and quote == 'BTC': ethbuy = value['info']['buy'] ethsell = value['info']['sell'] valset = True btc = {} eth = {} for key, value in kcmarkets.items(): base = value['base'] quote = value['quote'] proceed = False isbase = False if base == 'BTC' or base == 'ETH': proceed = True isbase = True elif quote == 'BTC' or quote == 'ETH': proceed = True isbase = False if base == 'ETH' and quote == 'BTC' or base == 'BTC' and quote == 'ETH': continue if proceed and quote in pairings or base in pairings: if isbase: if base == 'BTC': btc[quote] = {} btc[quote]['symbol'] = value['symbol'] btc[quote]['buy'] = value['info']['buy'] btc[quote]['sell'] = value['info']['sell'] elif base == 'ETH': eth[quote] = {} eth[quote]['symbol'] = value['symbol'] eth[quote]['buy'] = value['info']['buy'] eth[quote]['sell'] = value['info']['sell'] else: if quote == 'BTC': btc[base] = {} btc[base]['symbol'] = value['symbol'] btc[base]['buy'] = value['info']['buy'] btc[base]['sell'] = value['info']['sell'] elif quote == 'ETH': eth[base] = {} eth[base]['symbol'] = value['symbol'] eth[base]['buy'] = value['info']['buy'] eth[base]['sell'] = value['info']['sell'] totaleth = 5 totalbtc = totaleth * ethsell stroutput = "" #stroutput += 'Total BTC {:8f}'.format(totalbtc) for pair in pairings: try: btcpair = btc[pair]['sell'] firstval = 0 if pair == 'USDT': firstval = totalbtc * btcpair else: firstval = totalbtc / btcpair firstval *= 0.999 secondval = 0 ethpair = eth[pair]['buy'] if pair == 'USDT': secondval = firstval / ethpair else: secondval = firstval * ethpair secondval *= 0.999 thirdval = secondval * ethbuy thirdval *= 0.999 if thirdval > totalbtc: s1 = "\nProfitable Pair BTC/{} Difference {:.8f} Percentage {:.2f}".format( pair, thirdval - totalbtc, (1 - (totalbtc / thirdval)) * 100) stroutput += s1 if not pair + '/BTC' in threads: t1 = threading.Thread( target=currencymonitor, args=[pair, 'BTC', 1 - (totalbtc / thirdval)]) threads[pair + '/BTC'] = t1 t1.start() firstval = totalbtc / ethsell firstval *= 0.999 ethval = eth[pair]['sell'] if pair == 'USDT': secondval = firstval * ethval else: secondval = firstval / ethval secondval *= 0.999 btcval = btc[pair]['buy'] if pair == 'USDT': thirdval = secondval / btcval else: thirdval = secondval * btcval if thirdval > totalbtc: s1 = "\nProfitable Pair ETH/{} Difference {:.8f} Percentage {:.2f}".format( pair, thirdval - totalbtc, (1 - (totalbtc / thirdval)) * 100) stroutput += s1 if not pair + '/ETH' in threads: t1 = threading.Thread( target=currencymonitor, args=[pair, 'ETH', 1 - (totalbtc / thirdval)]) threads[pair + '/ETH'] = t1 t1.start() except KeyError: if pair != "CFD": screen_lock.acquire() #print(pair, " doesn't exist") screen_lock.release() #screen_lock.acquire() #print(stroutput) #screen_lock.release() counter += 1 if counter > 500: screen_lock.acquire() print('Still alive..') screen_lock.release() counter = 0 for k, v in list(threads.items()): if not v.isAlive(): del threads[k] except Exception as ex: template = "An exception of type {0} occurred. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) screen_lock.acquire() #print(message) screen_lock.release()
def currencymonitor(pair, direction, profper): kucoinage = ccxt.kucoin() profitable = True deathcounter = 5 if pair != 'USDT': while profitable: try: pairbtc = kucoinage.fetch_order_book(pair + "/BTC", 1) paireth = kucoinage.fetch_order_book(pair + "/ETH", 1) ethbtc = kucoinage.fetch_order_book("ETH/BTC", 1) if direction == 'BTC': if pair != 'USDT': try: volavail = ethbtc['bids'][0][1] / paireth['bids'][ 0][0] if volavail > paireth['bids'][0][1]: volavail = paireth['bids'][0][1] if volavail > pairbtc['asks'][0][1]: volavail = pairbtc['asks'][0][1] startbtc = volavail * pairbtc['asks'][0][0] startbtc *= 1.001 #calculate profitability firstval = startbtc / pairbtc['asks'][0][0] firstval *= 0.999 secondval = firstval * paireth['bids'][0][0] secondval *= 0.999 thirdval = secondval * ethbtc['bids'][0][0] thirdval *= 0.999 #screen_lock.acquire() #prstring = "Pair {}/BTC Start {:.8f} End {:8f} Profit {:.8f}".format(pair, startbtc, thirdval, # thirdval - startbtc) #print(prstring) #screen_lock.release() if thirdval > startbtc and thirdval - startbtc > 0.0001: screen_lock.acquire() prstring = "Pair {}/BTC Start {:.8f} End {:8f} Profit {:.8f}".format( pair, startbtc, thirdval, thirdval - startbtc) print(prstring) screen_lock.release() deathcounter = 5 else: deathcounter -= 1 if deathcounter == 0: profitable = False except IndexError: screen_lock.acquire() print('Issue with ' + pair + '/BTC Stuff') profitable = False screen_lock.release() #todo:figure out how to tell potential profit by examining trades on both sides, should be rather simple as it's the same calculation as above.. else: break else: if pair != 'USDT': try: volavail = pairbtc['bids'][0][1] if volavail > paireth['asks'][0][1]: volavail = paireth['asks'][0][1] volavail = volavail * paireth['asks'][0][0] if ethbtc['asks'][0][0] < volavail: volavail = ethbtc['asks'][0][1] startbtc = volavail * ethbtc['asks'][0][0] startbtc *= 1.001 # calculate profitability firstval = startbtc / ethbtc['asks'][0][0] firstval *= 0.999 secondval = firstval / paireth['asks'][0][0] secondval *= 0.999 thirdval = secondval * pairbtc['bids'][0][0] thirdval *= 0.999 if thirdval > startbtc and thirdval - startbtc > 0.0001: screen_lock.acquire() prstring = "Pair {}/ETH Start {:.8f} End {:8f} Profit {:.8f}".format( pair, startbtc, thirdval, thirdval - startbtc) print(prstring) screen_lock.release() deathcounter = 5 else: deathcounter -= 1 if deathcounter == 0: profitable = False except IndexError: screen_lock.acquire() #print('Issue with ' + pair + '/ETH Stuff') profitable = False screen_lock.release() else: break except Exception as ex: profitable = False print('Yeah if you could fix that thatd be great')
savedir = '/home/gemini/CryptoArb/data/' logdir = '/home/gemini/CryptoArb/logs/' # Logger for this module log = logging.getLogger(__name__) log_format = '%(asctime)s %(levelname)-5.5s [%(name)s-%(funcName)s:%(lineno)d][%(threadName)s] %(message)s' log_filename = datetime.now().strftime('SpreadFinder.%Y%m%d-%H%M%S.log') logfile = logdir + log_filename logging.basicConfig(format='%(asctime)s %(levelname)s:%(message)s', filename=logfile, level=logging.INFO) starttime = time.time() hitbtc = ccxt.hitbtc({'apiKey': '', 'secret': ''}) kucoin = ccxt.kucoin({'apiKey': '', 'secret': ''}) binance = ccxt.binance({'apiKey': '', 'secret': ''}) poloniex = ccxt.poloniex({'apiKey': '', 'secret': ''}) okex = ccxt.okex() okex.name = 'okex' huobi = ccxt.huobi() symbol = 'NEO/ETH' exchanges = [hitbtc, binance, kucoin, okex] ioloop = asyncio.get_event_loop() bids_df = pd.DataFrame() asks_df = pd.DataFrame()
def main_loop(): kucoin = ccxt.kucoin() while True: kcmarkets = kucoin.load_markets(True) pairings = [] kcsbuy = 0.0 kcssell = 0.0 valset = False for key, value in kcmarkets.items(): base = value['base'] quote = value['quote'] if base == 'KCS' or quote == 'KCS': if base != 'KCS': tocheck = base else: tocheck = quote if not tocheck in pairings and tocheck != 'BTC': pairings.append(tocheck) if not valset and base == 'BTC' and quote == 'KCS': kcsbuy = value['info']['buy'] kcssell = value['info']['sell'] valset = True elif not valset and base == 'KCS' and quote == 'BTC': kcsbuy = value['info']['buy'] kcssell = value['info']['sell'] valset = True btc = {} kcs = {} for key, value in kcmarkets.items(): base = value['base'] quote = value['quote'] proceed = False isbase = False if base == 'BTC' or base == 'KCS': proceed = True isbase = True elif quote == 'BTC' or quote == 'KCS': proceed = True isbase = False if base == 'KCS' and quote == 'BTC' or base == 'BTC' and quote == 'KCS': continue if proceed and quote in pairings or base in pairings: if isbase: if base == 'BTC': btc[quote] = {} btc[quote]['symbol'] = value['symbol'] btc[quote]['buy'] = value['info']['buy']; btc[quote]['sell'] = value['info']['sell']; elif base == 'KCS': kcs[quote] = {} kcs[quote]['symbol'] = value['symbol'] kcs[quote]['buy'] = value['info']['buy']; kcs[quote]['sell'] = value['info']['sell']; else: if quote == 'BTC': btc[base] = {} btc[base]['symbol'] = value['symbol'] btc[base]['buy'] = value['info']['buy']; btc[base]['sell'] = value['info']['sell']; elif quote == 'KCS': kcs[base] = {} kcs[base]['symbol'] = value['symbol'] kcs[base]['buy'] = value['info']['buy']; kcs[base]['sell'] = value['info']['sell']; totalkcs = 5 totalbtc = totalkcs * kcssell print('Total BTC ', totalbtc) for pair in pairings: try: btcpair = btc[pair]['sell'] firstval = 0 if pair == 'USDT': firstval = totalbtc * btcpair else: firstval = totalbtc / btcpair firstval *= 0.999 secondval = 0 kcspair = kcs[pair]['buy'] if pair == 'ETH' or pair == 'USDT': secondval = firstval / kcspair else: secondval = firstval * kcspair secondval *= 0.999 thirdval = secondval * kcsbuy thirdval *= 0.999 if thirdval > totalbtc: s1 = "Profitable Pair BTC/{} Difference {:.8f} Percentage {:.2f}".format(pair, thirdval - totalbtc, (1-(totalbtc / thirdval)) * 100) print(s1) firstval = totalbtc / kcssell firstval *= 0.999 kcsval = kcs[pair]['sell'] if pair == 'ETH' or pair == 'USDT': secondval = firstval * kcsval else: secondval = firstval / kcsval secondval *= 0.999 btcval = btc[pair]['buy'] if pair == 'USDT': thirdval = secondval / btcval else: thirdval = secondval * btcval if thirdval > totalbtc: if pair == 'BCH': print('BCH KCS ', kcsval, ' BTC ', btcval) s1 = "Profitable Pair KCS/{} Difference {:.8f} Percentage {:.2f}".format(pair, thirdval - totalbtc, (1-(totalbtc / thirdval)) * 100) print(s1) except KeyError: print(pair, " doesn't exist")
def __init__(self, exchange_id, config): threading.Thread.__init__(self) 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.exhange = exchange_id 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_in_queue = self.config['in_queue'] self.ccxt_out_queue = self.config['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]) loop = asyncio.new_event_loop() 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()