def exchangeobj(apikeys): if apikeys['exchange'] == 'bitmex': bitmex = ccxt.bitmex({'apiKey': apikeys['apikey'], 'secret': apikeys['secret']}) bitmex.urls['api'] = bitmex.urls['test'] return bitmex if apikeys['exchange'] == 'bithumb': # bithumb = ccxt.bithumb({'apiKey': apikeys['apikey'], 'secret': apikeys['secret']}) bithumb = Bithumb(apikeys['apikey'], apikeys['secret']) return bithumb if apikeys['exchange'] == 'upbit': upbit = ccxt.upbit({'apiKey': apikeys['apikey'], 'secret': apikeys['secret']}) return upbit
def kimp(): c = CurrencyConverter('http://www.ecb.europa.eu/stats/eurofxref/eurofxref.zip') exchange_rate = round(c.convert(1, 'USD', 'KRW'),2) #환율 #print(exchange_rate) binance = ccxt.binance() markets_binance = binance.fetch_tickers() #print(markets_binance.keys()) binance_BTC = binance.fetch_ticker('BTC/USDT') binance_BTC_close = binance_BTC['close'] #print(binance_BTC_close) upbit = ccxt.upbit() markets_upbit = upbit.fetch_tickers() #print(markets_upbit.keys()) upbit_BTC = upbit.fetch_ticker('BTC/KRW') upbit_BTC_close = upbit_BTC['close'] #print(upbit_BTC_close) kimp_BTC = round(((upbit_BTC_close/(binance_BTC_close*exchange_rate) - 1) * 100),2) binance_ETH = binance.fetch_ticker('ETH/USDT') binance_XRP = binance.fetch_ticker('XRP/USDT') binance_ADA = binance.fetch_ticker('ADA/USDT') binance_ETH_close = binance_ETH['close'] binance_XRP_close = binance_XRP['close'] binance_ADA_close = binance_ADA['close'] upbit_ETH = upbit.fetch_ticker('ETH/KRW') upbit_XRP = upbit.fetch_ticker('XRP/KRW') upbit_ADA = upbit.fetch_ticker('ADA/KRW') upbit_ETH_close = upbit_ETH['close'] upbit_XRP_close = upbit_XRP['close'] upbit_ADA_close = upbit_ADA['close'] kimp_ETH = round(((upbit_ETH_close / (binance_ETH_close * exchange_rate) - 1) * 100)) kimp_XRP = round(((upbit_XRP_close / (binance_XRP_close * exchange_rate) - 1) * 100)) kimp_ADA = round(((upbit_ADA_close / (binance_ADA_close * exchange_rate) - 1) * 100)) format_upbit_BTC_close = format(upbit_BTC_close, ",")[:-2] format_upbit_ETH_close = format(upbit_ETH_close, ",")[:-2] format_upbit_XRP_close = format(upbit_XRP_close, ",")[:-2] format_upbit_ADA_close = format(upbit_ADA_close, ",")[:-2] # now = datetime.datetime.now().time() now = time.strftime('%y-%m-%d %H:%M:%S') s = f"현재시간 : {now} <br><br>\n" \ f"BTC : {format_upbit_BTC_close} ({kimp_BTC}%) <p> \n" \ f"ETH : {format_upbit_ETH_close} ({kimp_ETH}%) <p> \n" \ f"XRP : {format_upbit_XRP_close} ({kimp_XRP}%) <p> \n" \ f"ADA : {format_upbit_ADA_close} ({kimp_ADA}%)" return s
def fetch_exchange_data(exchange_name): bitstamp = ccxt.bitstamp() bitmex = ccxt.bitmex() bitfinex = ccxt.bitfinex2() bittrex = ccxt.bittrex() okcoin = ccxt.okcoinusd() kraken = ccxt.kraken() binance = ccxt.binance() coss = ccxt.coss() kucoin = ccxt.kucoin2() poloniex = ccxt.poloniex() # theocean = ccxt.theocean() upbit = ccxt.upbit() dict_of_exchanges = { 'kraken': kraken, 'bitmex': bitmex, 'bittrex': bittrex, 'bitstamp': bitstamp, 'bitfinex': bitfinex, 'okcoin': okcoin, 'binance': binance, 'coss': coss, 'kucoin': kucoin, 'poloniex': poloniex, # 'theocean': theocean, 'upbit': upbit } try: return dict( dict_of_exchanges[exchange_name].fetch_order_book('BTC/USD')) # return dict(dict_of_exchanges[exchange_name].fetch_order_book('XRP/USD')) # return dict(dict_of_exchanges[exchange_name].fetch_order_book('LTC/USD')) # add BitcoinCash # return dict(dict_of_exchanges[exchange_name].fetch_order_book('ETH/USD')) except Exception as ex: print('%s - erro: %s' % (exchange_name, ex)) return {}
write = csv.writer(file, dialect='excel') for i in range(len(data)): write.writerow(data.iloc[i]) file.close() time.sleep(1) if __name__ == '__main__': obj_list = [ ccxt.okex(), ccxt.huobipro(), ccxt.binance(), ccxt.bitmax(), ccxt.fcoin(), ccxt.upbit() ] file = open('config.txt', 'r') config = json.loads(file.read()) file.close() mkdir(config['name_list']) time_info = get_time_info(config['name_list'], config['symbol_list']) info_queue = Queue() for obj, name in zip(obj_list, config['name_list']): crawl = CrawlInfo(obj, info_queue, name, config['symbol_list']) crawl.start() for i in range(3): Parse_thread = Parse(info_queue) Parse_thread.start() Update_thread = Update() Update_thread.start()
import ccxt from environs import Env env = Env() env.read_env() UPBIT_ACCESS_KEY = env('UPBIT_ACCESS_KEY') UPBIT_SECRET_KEY = env('UPBIT_SECRET_KEY') config = { 'apiKey': UPBIT_ACCESS_KEY, 'secret': UPBIT_SECRET_KEY, } # CCXT Example, https://github.com/ccxt/ccxt/tree/master/examples/py upbit = ccxt.upbit(config=config) # 1000원 단위 주문 가능 binance = ccxt.binance() BTCKRW = 'BTC/KRW' BTCUSDT = 'BTC/USDT' def test(): # print(upbit.load_markets()) print(upbit.fetch_ticker(BTCKRW)) print(upbit.fetch_balance()) upbit_order_book = upbit.fetch_order_book(BTCKRW) symbol = BTCKRW expected_trades_base_amount = int(
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 logging import datetime import math import telegram logger = logging.getLogger() logger.setLevel(logging.ERROR) file_handler = logging.FileHandler(filename="error.log") logger.addHandler(file_handler) telegm_token = '' bot = telegram.Bot(token=telegm_token) coin_list = [] exchange = ccxt.upbit({'apiKey': '', 'secret': '', 'enableRateLimit': True}) ''' exchange = ccxt.bithumb({'apiKey':'', 'secret':'', 'enableRateLimit': True }) ''' def run(): now = datetime.datetime.now() mid = datetime.datetime(now.year, now.month, now.day) + datetime.timedelta( 1) # 익일 자정 nextDay = mid + datetime.timedelta(hours=9) #익일 자정 + 9시간 --> 익일 오전 9시 coin_list = getCoinData() # 거래할 코인 리스트 불러옴 coin_list_dic = {}
def __init__(self, *args, **kwargs): self.api = ccxt.upbit() super().__init__(*args, **kwargs) self.__account()
except: escape = len(line) if line: key_list.append(line[0:escape].split(':')[1].strip()) else: break file.close con_key = key_list[0] sec_key = key_list[1] target_volatility = float(key_list[2]) # 수용가능한 변동성은 2% exchange = ccxt.upbit({ 'apiKey': con_key, 'secret': sec_key, 'enableRateLimit': False #변동성 돌파는 시장가로 매매, 시장가가 싫으면 True로. }) ready_trading = False class CryptoTrader(QThread): finished = pyqtSignal(dict) def run(self): now = datetime.datetime.now() # 2019-12-09 00:02 mid = datetime.datetime(now.year, now.month, now.day) + datetime.timedelta(1) global ready_trading