def difference_xrp_btc(self): """取引所間でのxrp差額を求めるメソッド (bitbank,binance,coinex)""" while True: try: bitbanks = ccxt.bitbank() bitbank_btc_jpy = bitbanks.fetch_ticker('BTC/JPY') bitbank_xrp_jpy = bitbanks.fetch_ticker('XRP/JPY') bitbank_xrp_btc_bid = bitbank_xrp_jpy.get( "bid") / bitbank_btc_jpy.get("ask") bitbank_xrp_btc_ask = bitbank_xrp_jpy.get( "ask") / bitbank_btc_jpy.get("bid") # binanceからXRP/BTC通貨情報取得 binances = ccxt.binance() binance_xrp_btc = binances.fetch_ticker('XRP/BTC') # coinexからXRP/BTC通貨情報取得 coinex = ccxt.coinex() coinex_xrp_btc = coinex.fetch_ticker('XRP/BTC') # bitbankとbinance間の差額 profit_bitbank_binance = ( (binance_xrp_btc.get("bid") - bitbank_xrp_btc_ask) * self) * bitbank_btc_jpy.get("bid") profit_binance_bitbank = ( (bitbank_xrp_btc_bid - binance_xrp_btc.get("ask")) * self) * bitbank_btc_jpy.get("bid") # bitbankとcoinex間の差額 profit_bitbank_coinex = ( (coinex_xrp_btc.get("bid") - bitbank_xrp_btc_ask) * self) * bitbank_btc_jpy.get("bid") profit_coinex_bitbank = ( (bitbank_xrp_btc_bid - coinex_xrp_btc.get("ask")) * self) * bitbank_btc_jpy.get("bid") # binanceとcoinex間の差額 profit_binance_coinex = ( (coinex_xrp_btc.get("bid") - binance_xrp_btc.get("ask")) * self) * bitbank_btc_jpy.get("bid") profit_coinex_binance = ( (binance_xrp_btc.get("bid") - coinex_xrp_btc.get("ask")) * self) * bitbank_btc_jpy.get("bid") #'XRPを取引した場合の最大利益(jpy):' maxvalue = max([ profit_bitbank_binance, profit_binance_bitbank, profit_bitbank_coinex, profit_coinex_bitbank, profit_binance_coinex, profit_coinex_binance ]) #'XRPを取引した場合の最低利益(jpy):' minvalue = min([ profit_bitbank_binance, profit_binance_bitbank, profit_bitbank_coinex, profit_coinex_bitbank, profit_binance_coinex, profit_coinex_binance ]) resultsample = { 'bitbank_binance': profit_bitbank_binance, 'binance_bitbank': profit_binance_bitbank, 'bitbank_coinex': profit_bitbank_coinex, 'coinex_bitbank': profit_coinex_bitbank, 'binance_coinex': profit_binance_coinex, 'coinex_binance': profit_coinex_binance } max_k = max(resultsample, key=resultsample.get) print(max_k) min_k = min(resultsample, key=resultsample.get) print(min_k) # 最大利益が出る取引所からいくら購入したのか if max_k.startswith('bitbank'): price_buy = bitbank_xrp_btc_ask elif max_k.startswith('binance'): price_buy = binance_xrp_btc.get("ask") * self elif max_k.startswith('coinex'): price_buy = coinex_xrp_btc.get("ask") * self else: price_buy = 0 # 最大利益が出る取引所からいくら売ったのか if max_k.endswith('bitbank'): price_sale = bitbank_xrp_btc_bid elif max_k.endswith('binans'): price_sale = binance_xrp_btc.get("bid") * self elif max_k.endswith('coinex'): \ price_sale = coinex_xrp_btc.get("bid") * self else: price_sale = 0 resultarray = { 'bitbank_binance': round(profit_bitbank_binance, 3), 'binance_bitbank': round(profit_binance_bitbank, 3), 'bitbank_coinex': round(profit_bitbank_coinex, 3), 'coinex_bitbank': round(profit_coinex_bitbank, 3), 'binance_coinex': round(profit_binance_coinex, 3), 'coinex_binance': round(profit_coinex_binance, 3), 'max': max_k, 'min': min_k, 'maxvalue': round(maxvalue, 3), 'minvalue': round(minvalue, 3), 'max_buy': price_buy, 'min_sale': price_sale } return resultarray except ccxt.BaseError: print("取引所から取引データを取得できません。") print("10秒待機してやり直します") time.sleep(10)
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
chazhi * 100)) return True else: logger.info("%s机会没出现,等一下吧!!!!" % crypoName) return False logging.basicConfig( level=logging.INFO, format= '%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='%Y/%m/%d %H:%M:%S', filename='myapp.log', filemode='w') logger = logging.getLogger(__name__) coinEX = ccxt.coinex() zb = ccxt.zb() okex = ccxt.okex() bibox = ccxt.bibox({ 'apiKey': 'e115769a73f5e0d26e646da98ced53d5282e2646', 'secret': '7c0d8b2769d952ed8a5ff5c9fd45721f6fdee76f', }) while True: try: orderbookCoinEx_BCH = coinEX.fetch_order_book("BCH/USDT", 5) orderbookZB_BCH = zb.fetch_order_book("BCH/USDT", 5) orderbookOkEx_BCH = okex.fetch_order_book("BCH/USDT", 5) orderbookBibox_BCH = bibox.fetch_order_book("BCH/USDT", 5) orderbookCoinEx_BCH['exchangeID'] = 'CoinEx' orderbookZB_BCH['exchangeID'] = 'ZB' orderbookOkEx_BCH['exchangeID'] = 'OkEx'
ccxt.btcchina(), ccxt.btcexchange(), ccxt.btcmarkets(), ccxt.btctradeim(), ccxt.btctradeua(), ccxt.btcturk(), ccxt.btcx(), ccxt.bxinth(), ccxt.ccex(), ccxt.cex(), ccxt.chbtc(), ccxt.chilebit(), ccxt.cobinhood(), ccxt.coincheck(), 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(),
for diff_index in range(len(diff_ema)): diff_data = diff_ema[diff_index] dea_data = dea_result[diff_index] macd_result.append(2 * (diff_data - dea_data)) return macd_result def is_macd_buy_signal(macd_value): if -DEFAULT_SHAKE_LIMIT_VALUE > macd_value: return False elif DEFAULT_SHAKE_LIMIT_VALUE < macd_value: return True return None exchange_api = ccxt.coinex() exchange_api.load_markets() if __name__ == '__main__': data = get_k_line_data(exchange_api, 'ETH/USDT', '5m') if data: print get_macd(data) else: print 'Get K-Line Error'
#!/home/nextgen/venv/bin/python3 import sqlite3 import ccxt from math import floor from time import sleep coinex = ccxt.coinex({ 'apiKey': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'secret': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) def rounddown(x, n): #x should be float return floor(x * 10**n) / 10**n def nextround(): conn = sqlite3.connect('Data.db') c = conn.cursor() c.execute('''INSERT INTO Round DEFAULT VALUES''') conn.commit() conn.close() def getround(): conn = sqlite3.connect('Data.db') c = conn.cursor() round = c.execute( '''SELECT id, start_time FROM Round ORDER BY id DESC LIMIT 1''')