def transforming_user_dic(self, dic, inter, update, context): user_dic = copy.deepcopy(dict(dic)) for exch in inter: try: exchange_bin = ccxt.binance() exchange_exm = ccxt.exmo() exchange_bifin = ccxt.bitfinex() exchanges = {'Exmo': exchange_exm.fetchTickers(), 'Binance': exchange_bin.fetchTickers(), 'Bitfinex': exchange_bifin.fetchTickers()} api_pairs = exchanges[exch] user_pairs = user_dic[exch] except: print('проблемы с вызовом api') self.checking_and_activate(user_dic, update, context) intersection = list(set(api_pairs.keys()) & set(user_pairs.keys())) for key in intersection: t = list(user_pairs[key]) if len(t) < 3: t.append(api_pairs[key]['bid']) t.append(api_pairs[key]['ask']) else: t[2] == api_pairs[key]['bid'] t[3] == api_pairs[key]['ask'] user_pairs[key] = t user_dic[exch] = user_pairs try: self.compare_bid_ask(user_dic, update, context) except: print('something wrong with compare bid_ask function')
def test8(): symbol = 'ETH/USDT' t1 = Exchange.Exchange(ccxt.exmo()) t1.add_book(t1.Ex.fetch_order_book(symbol), symbol) t2 = Exchange.Exchange(ccxt.ethfinex()) t2.add_book(t2.Ex.fetch_order_book(symbol), symbol) pair = Pair.Pair(t1, t2, 'ETH/USDT')
def results(request): output = "" if request.method == 'POST': form = SimulationForm(request.POST) if form.is_valid(): amount = form.cleaned_data['amount'] base_currency = form.cleaned_data['base_currency'] quote_currency = form.cleaned_data['quote_currency'] duration = form.cleaned_data['duration'] use_fees = form.cleaned_data['include_fees'] sim = simulation.ArbitrageSimulation( ccxt.exmo(), ccxt.gdax(), amount, base_currency + "/" + quote_currency) old_stdout = sys.stdout result = StringIO() sys.stdout = result sim.start_simulation(duration, include_fees=use_fees) sim.create_trade_visuals() sys.stdout = old_stdout result_list = result.getvalue().split("\n") result_string = [] for s in result_list: if s is not "": result_string.append(s) output = result_string context = { 'form': form, 'duration': duration, 'amount': amount, 'output': output } return render(request, "crypto2/results.html", context) else: form = SimulationForm() return render(request, "crypto2/index.html", {'form': form})
def api_by_name(exchange_name): if exchange_name == 'exmo': return ccxt.exmo() elif exchange_name == 'yobit': return ccxt.yobit() elif exchange_name == 'hitbtc': return ccxt.hitbtc() elif exchange_name == 'livecoin': return ccxt.livecoin() else: raise Exception("Unknown exchange")
def test_get_common_symbols(): print("Testing get_common_symbols()...") a = ccxt.exmo() b = ccxt.hitbtc() c = ccxt.kraken() d = ccxt.binance() e = ccxt.huobi() f = "myMadeUpExchangeName" g = "binance" s0 = "BTC/USDT" s1 = "LTC/BTC" s3 = "Not real" assert get_common_symbols(a, b) is not None, "Should have some in common" assert s0 in get_common_symbols(a, b), s0 + " is in both of these." assert get_common_symbols(a, f) is None, "Made up exchange" assert len(get_common_symbols(a, b)) == 14, "Should have consistent length." print("Passed get_common_symbols() test...")
def simple_simulate(exchange0=ccxt.exmo(), exchange1=ccxt.hitbtc(),\ symbol="BTC/USDT", duration=5.0): """Run the simple simulation.""" start_time = time.time() rate_limit = max(exchange0.rateLimit, exchange1.rateLimit) exchange0.load_markets() exchange1.load_markets() profits = 0.0 while (time.time() - start_time) < duration * 60.0: cost = get_buy_price(exchange0, exchange1, symbol) revenue = get_sell_price(exchange0, exchange1, symbol) profits += make_trade(revenue, cost) time.sleep(rate_limit / 1000.0) print("Total profits made trading on " + exchange0.name + " and "\ + exchange1.name + " in the market of " + symbol + " over "\ + str(duration) + " minutes were:") print(profits) return profits
def test_smoke_cctx(self): print("yup test_cctx") hitbtc = ccxt.hitbtc({'verbose': True}) bitmex = ccxt.bitmex() huobi = ccxt.huobi() exmo = ccxt.exmo({ 'apiKey': 'YOUR_PUBLIC_API_KEY', 'secret': 'YOUR_SECRET_PRIVATE_KEY', }) hitbtc_markets = hitbtc.load_markets() print(hitbtc.id, hitbtc_markets) print(bitmex.id, bitmex.load_markets()) print(huobi.id, huobi.load_markets()) print(hitbtc.fetch_order_book(hitbtc.symbols[0])) print(bitmex.fetch_ticker('BTC/USD')) print(huobi.fetch_trades('LTC/CNY'))
def test_get_spread(): print("Testing get_spread()...") a = ccxt.exmo() b = ccxt.hitbtc() c = ccxt.kraken() d = ccxt.binance() e = ccxt.huobi() f = "myMadeUpExchangeName" g = "binance" s0 = "BTC/USDT" s1 = "LTC/BTC" s3 = "Not real" assert get_spread(a, b, s0)[0] is not None, "Example of valid comparison" assert get_spread(a, b, s1)[0] is not None, "Example of valid comparison" assert get_spread(d, c, s0)[0] is None, "Example of market without sym" assert get_spread(a, f, s0)[0] is None, "Example of invalid exchange" assert get_spread(a, b, s3)[0] is None, "Example of invalid symbol" assert get_spread(a, b, s0, True)[0] <= 1, "Percent should be less than 1" assert get_spread(a, b, s0, True)[0] >= 0, "Spread cannot be less than 1" assert get_spread(a, b, s0)[0] >= 0, "Spread cannot be less than 1" assert len(get_spread(a, b, s0)) == 3, "Tuple length should be 3." assert len(get_spread(a, f, s0)) == 3, "Tuple length should be 3." assert len(get_spread(a, b, s3)) == 3, "Tuple length should be 3." print("Passed get_spreads() test...")
# coding=utf-8 import ccxt import time hitbtc = ccxt.hitbtc({'verbose': True}) bitmex = ccxt.bitmex() huobi = ccxt.huobi() exmo = ccxt.exmo({ 'apiKey': 'YOUR_PUBLIC_API_KEY', 'secret': 'YOUR_SECRET_PRIVATE_KEY', }) t1 = time.time() gateio = ccxt.gateio() t2 = time.time() # print gateio.load_markets() print gateio.fetch_ticker('DAI/USDT') t3 = time.time() print t3 - t2, t2 - t1 # print gateio.market_id('DAI/USDT') # print gateio.fetch_balance() def test(): hitbtc_markets = hitbtc.load_markets() print(hitbtc.id, hitbtc_markets) print(bitmex.id, bitmex.load_markets()) print(huobi.id, huobi.load_markets()) print(hitbtc.fetch_order_book(hitbtc.symbols[0]))
book = self.exchange.fetch_order_book(pair) convert = 2/(book['bids'][0][0] + book['asks'][0][0]) self.convert_table[from_][into] = convert self.convert_table[into][from_] = 1/convert return convert @staticmethod def shorter_path(left_add, right_add, comp): if left_add is None or right_add is None: return comp elif comp is None: assert left_add[-1] == right_add[0] return left_add + right_add[1:] elif len(comp) > len(left_add) + len(right_add): assert left_add[-1] == right_add[0] return left_add + right_add[1:] else: return comp def all_currencies(markets): res = set() for m in markets: res.add(m['base']) res.add(m['quote']) return list(res) if __name__ == '__main__': PairGraph(ccxt.exmo()).convert_currency("WAVES", "HBZ", 1)
profit_cumulative = [] profit_cumulative.append(self.profit[0]) for i in range(1, len(self.profit)): profit_cumulative.append(self.profit[i]\ + profit_cumulative[i - 1]) plt.plot(range(len(profit_cumulative)), profit_cumulative) plt.suptitle("Cumulative Profit over Time") plt.ylabel("Cumulative Profit (" + self.quote_currency + ")") plt.xlabel("Time (number of trades since start)") plt.savefig("crypto/static/graphs/output_profit.png") plt.clf() if __name__ == "__main__": CHOICES = [ ArbitrageSimulation(ccxt.bittrex(), ccxt.hitbtc(), "BTC/USDT"), ArbitrageSimulation(ccxt.exmo(), ccxt.gdax(), "BTC/USD"), ArbitrageSimulation(ccxt.exmo(), ccxt.kraken(), "BTC/EUR"), ArbitrageSimulation(ccxt.bitfinex(), ccxt.exmo(), "ETH/USD"), ] if len(sys.argv) > 1: # can provide commandline args to run simulation PARSER = argparse.ArgumentParser(description="Produces visual output"\ + " from simulator with the given parameters.") PARSER.add_argument("simulation_type", help="whether to simulate a"\ + " duration (0) or for to time a profit (1).", type=int,\ choices=[0, 1]) PARSER.add_argument("limit_value",\ help="If duration, the time in minutes if timing a profit,"\ + " the amount of profit.", type=float) PARSER.add_argument("simulation_choice",\ help="Which default simulation to use.", type=int,\ choices=range(len(CHOICES)))
def exchangeObject(exchange_in): exchanges = [ ccxt.acx(), ccxt.bitbay(), ccxt.bitfinex(), ccxt.bitflyer(), ccxt.bithumb(), ccxt.bitlish(), ccxt.bitmarket(), ccxt.bitmex(), ccxt.bitso(), ccxt.bitstamp(), ccxt.bitstamp1(), ccxt.bittrex(), ccxt.bl3p(), ccxt.bleutrade(), ccxt.btcbox(), ccxt.btcchina(), ccxt.btcexchange(), ccxt.btcmarkets(), ccxt.btctradeua(), ccxt.btcturk(), ccxt.bxinth(), ccxt.ccex(), ccxt.cex(), ccxt.chbtc(), ccxt.chilebit(), ccxt.coincheck(), ccxt.coinfloor(), ccxt.coingi(), ccxt.coinmarketcap(), ccxt.coinmate(), ccxt.coinspot(), ccxt.cryptopia(), ccxt.dsx(), ccxt.exmo(), ccxt.flowbtc(), ccxt.foxbit(), ccxt.fybse(), ccxt.fybsg(), ccxt.gatecoin(), ccxt.gateio(), ccxt.gdax(), ccxt.gemini(), ccxt.getbtc(), ccxt.hitbtc(), ccxt.independentreserve(), ccxt.itbit(), ccxt.jubi(), ccxt.kraken(), ccxt.kucoin(), ccxt.kuna(), ccxt.lakebtc(), ccxt.liqui(), ccxt.livecoin(), ccxt.luno(), ccxt.mercado(), ccxt.mixcoins(), ccxt.nova(), ccxt.okcoincny(), ccxt.okcoinusd(), ccxt.okex(), ccxt.paymium(), ccxt.poloniex(), ccxt.qryptos(), ccxt.quadrigacx(), ccxt.southxchange(), ccxt.surbitcoin(), ccxt.therock(), ccxt.tidex(), ccxt.urdubit(), ccxt.vaultoro(), ccxt.vbtc(), ccxt.virwox(), ccxt.wex(), ccxt.xbtce(), ccxt.yobit(), ccxt.yunbi(), ccxt.zaif(), ccxt.zb() ] for count, exchange in enumerate([str(x) for x in exchanges]): if exchange_in.lower() in exchange: return exchanges[count] break
def init_supported_exchanges(): objects = { "acx": ccxt.acx(), "aofex": ccxt.aofex(), "bequant": ccxt.bequant(), "bibox": ccxt.bibox(), "bigone": ccxt.bigone(), "binance": ccxt.binance(), "bitbank": ccxt.bitbank(), "bitbay": ccxt.bitbay(), "bitfinex": ccxt.bitfinex(), "bitflyer": ccxt.bitflyer(), "bitforex": ccxt.bitforex(), "bithumb": ccxt.bithumb(), "bitkk": ccxt.bitkk(), "bitmax": ccxt.bitmax(), "bitstamp": ccxt.bitstamp(), "bittrex": ccxt.bittrex(), "bitz": ccxt.bitz(), "bl3p": ccxt.bl3p(), "bleutrade": ccxt.bleutrade(), "braziliex": ccxt.braziliex(), "btcalpha": ccxt.btcalpha(), "btcbox": ccxt.btcbox(), "btcmarkets": ccxt.btcmarkets(), "btctradeua": ccxt.btctradeua(), "bw": ccxt.bw(), "bybit": ccxt.bybit(), "bytetrade": ccxt.bytetrade(), "cex": ccxt.cex(), "chilebit": ccxt.chilebit(), "coinbase": ccxt.coinbase(), "coinbasepro": ccxt.coinbasepro(), "coincheck": ccxt.coincheck(), "coinegg": ccxt.coinegg(), "coinex": ccxt.coinex(), "coinfalcon": ccxt.coinfalcon(), "coinfloor": ccxt.coinfloor(), "coinmate": ccxt.coinmate(), "coinone": ccxt.coinone(), "crex24": ccxt.crex24(), "currencycom": ccxt.currencycom(), "digifinex": ccxt.digifinex(), "dsx": ccxt.dsx(), "eterbase": ccxt.eterbase(), "exmo": ccxt.exmo(), "exx": ccxt.exx(), "foxbit": ccxt.foxbit(), "ftx": ccxt.ftx(), "gateio": ccxt.gateio(), "gemini": ccxt.gemini(), "hbtc": ccxt.hbtc(), "hitbtc": ccxt.hitbtc(), "hollaex": ccxt.hollaex(), "huobipro": ccxt.huobipro(), "ice3x": ccxt.ice3x(), "independentreserve": ccxt.independentreserve(), "indodax": ccxt.indodax(), "itbit": ccxt.itbit(), "kraken": ccxt.kraken(), "kucoin": ccxt.kucoin(), "lakebtc": ccxt.lakebtc(), "latoken": ccxt.latoken(), "lbank": ccxt.lbank(), "liquid": ccxt.liquid(), "livecoin": ccxt.livecoin(), "luno": ccxt.luno(), "lykke": ccxt.lykke(), "mercado": ccxt.mercado(), "oceanex": ccxt.oceanex(), "okcoin": ccxt.okcoin(), "okex": ccxt.okex(), "paymium": ccxt.paymium(), "poloniex": ccxt.poloniex(), "probit": ccxt.probit(), "southxchange": ccxt.southxchange(), "stex": ccxt.stex(), "surbitcoin": ccxt.surbitcoin(), "therock": ccxt.therock(), "tidebit": ccxt.tidebit(), "tidex": ccxt.tidex(), "upbit": ccxt.upbit(), "vbtc": ccxt.vbtc(), "wavesexchange": ccxt.wavesexchange(), "whitebit": ccxt.whitebit(), "yobit": ccxt.yobit(), "zaif": ccxt.zaif(), "zb": ccxt.zb() } return objects
import sys import ccxt import numpy as np import time import datetime from pytz import timezone import cry_arb_evaluator import json dash = '-' * 25 space = ' ' * 2 tz = timezone('EST') kraken = ccxt.kraken({'enableRateLimit': True}) exmo = ccxt.exmo({'enableRateLimit': True}) binance = ccxt.binance({'enableRateLimit': True}) hitbtc = ccxt.hitbtc2({'enableRateLimit': True}) coinbasepro = ccxt.coinbasepro({ 'enableRateLimit': True, }) gemini = ccxt.gemini({ 'enableRateLimit': True, }) bitfinex = ccxt.bitfinex({ 'enableRateLimit': True, }) livecoin = ccxt.livecoin({ 'enableRateLimit': True, }) kucoin = ccxt.kucoin({ 'enableRateLimit': True, })
ccxt.coinegg(), ccxt.coinex(), ccxt.coinexchange(), ccxt.coinfloor(), ccxt.coingi(), ccxt.coinmarketcap(), ccxt.coinmate(), ccxt.coinnest(), ccxt.coinone(), ccxt.coinsecure(), ccxt.coinspot(), ccxt.coolcoin(), ccxt.cryptopia(), ccxt.dsx(), ccxt.ethfinex(), ccxt.exmo(), ccxt.exx(), ccxt.flowbtc(), ccxt.foxbit(), ccxt.fybse(), ccxt.fybsg(), ccxt.gatecoin(), ccxt.gateio(), ccxt.gdax(), ccxt.gemini(), ccxt.getbtc(), ccxt.hadax(), ccxt.hitbtc(), ccxt.hitbtc2(), ccxt.huobi(), ccxt.huobicny(),
def create_market_api(self): self.exchange = ccxt.exmo({ 'apiKey': self.api_key, 'secret': self.secret })