def huobiAgg(symbols): ##3Problem fetch ticker result = [] try: huobi = ccxt.huobi({ 'apiKey': 'apiKey', 'secret': 'secret', 'options': { 'adjustForTimeDifference': True } }) totalBalance = huobi.fetch_balance()["free"] # totalBalance= [x+"/CNY" for x in totalBalance if x!="CNY"] totalExBalance = sum(list(totalBalance.values())) checkSymbols = huobi.symbols for s in symbols: if s in checkSymbols: try: dataSymbols = huobi.fetch_ticker(s) coinBalance = totalBalance[s.split("/")[0]] result.append([ "huobi", s, coinBalance, dataSymbols["ask"], dataSymbols["bid"], dataSymbols["baseVolume"] ]) except: print("Huobi couldn`t get " + s) continue except Exception as e: print(str(e)[:150]) return (result)
def get_huobi_info(self, symbol): huobi = ccxt.huobi() print huobi.fetch_markets() print 'line 80' # print huobi.fetch_tickers() print 'line 83' result = huobi.fetch_ticker(symbol) print result
def __init__(self, channels=[]): self.channels = channels self.check_tradepair() # Disabbling logging. logger = logging.getLogger() logger.disabled = True self.huobi = ccxt.huobi() self.huobi.load_products() self.pub = Publisher(channels)
def huobiData(): huobi = ccxt.huobi() coindata = list(huobi.fetch_tickers().values()) columns = ['ask', 'bid', 'close', 'high', 'low', 'last', 'symbol', 'average', 'baseVolume', 'timestamp'] df = pd.DataFrame(coindata) df = df[columns] df['exchange'] = 'huobi' df['createtime'] = starttime df['baseCurrency'] = list(i.split('/')[0] for i in df['symbol']) df['quotCurrency'] = list(i.split('/')[1] for i in df['symbol']) engine = create_engine("mysql+pymysql://quziyou:0739#[email protected]:5389/coinData?charset=utf8") df.to_sql('coindata_tickers', con=engine, if_exists='append', index=False)
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.btcx(),ccxt.bxinth(),ccxt.ccex(),ccxt.cex(),ccxt.chbtc(),ccxt.chilebit(),ccxt.coincheck(),ccxt.coinfloor(),ccxt.coingi(),ccxt.coinmarketcap(),ccxt.coinmate(), ccxt.coinsecure(),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.huobi(),ccxt.huobicny(),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 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 live_ticker(tradepair): global listOfTradingPairs print("Ticker of Currency Pair", tradepair) if tradepair in listOfTradingPairs.keys(): huobi = ccxt.huobi() huobi.load_products() tradepair = listOfTradingPairs.get(tradepair) temp = huobi.fetch_ticker(tradepair) while True: if (huobi.fetch_ticker(tradepair) == temp): pass else: temp = huobi.fetch_ticker(tradepair) print(temp) else: print("Currency Pair is not from the below list \n", listOfTradingPairs.keys())
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_ccxt(self): #print(ccxt.markets) # print a list of all available market classes hitbtc = ccxt.hitbtc({'verbose': True}) bitmex = ccxt.bitmex() huobi = ccxt.huobi() bitfinex = ccxt.bitfinex({ 'apiKey': 'YOUR-API-KEY', 'secret': 'YOUR-API-KEY', }) okcoinusd = ccxt.okcoinusd({ 'apiKey': 'YOUR-API-KEY', 'secret': 'YOUR-API-KEY', }) trade_amount = 0.1 market = 'ETH_USD' ticker = okcoinusd.fetch_ticker(market) print(ticker) print('debug %s' % okcoinusd.create_limit_buy_order( market, trade_amount, ticker['ask'] + 1))
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...")
import os from random import randint import sys root = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(root + '/python') import ccxt # noqa: E402 print('CCXT Version:', ccxt.__version__) exchange = ccxt.huobi({ 'apiKey': 'YOUR_API_KEY', 'secret': 'YOUR_API_SECRET', 'options': { 'defaultType': 'spot', }, }) markets = exchange.load_markets() # exchange.verbose = True # uncomment for debugging purposes if necessary # creating and canceling a stop-limit buy order symbol = 'ADA/USDT' order_type = 'limit' side = 'buy' offset = 'open' amount = 10 price = 0.5
# 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]))
from random import randint import sys from pprint import pprint root = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(root + '/python') import ccxt # noqa: E402 print('CCXT Version:', ccxt.__version__) exchange = ccxt.huobi({ 'apiKey': 'YOUR_API_KEY', 'secret': 'YOUR_SECRET', 'options': { 'defaultType': 'swap', 'marginType': 'cross' }, }) markets = exchange.load_markets() exchange.verbose = True # uncomment for debugging purposes if necessary # Example: creating and closing a contract symbol = 'ADA/USDT:USDT' order_type = 'limit' # market positions for contracts not available side = 'buy' offset = 'open' leverage = 1 amount = 1
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(), ccxt.huobipro(), ccxt.ice3x(), ccxt.independentreserve(), ccxt.indodax(), ccxt.itbit(), ccxt.jubi(), ccxt.kraken(), ccxt.kucoin(), ccxt.kuna(), ccxt.lakebtc(), ccxt.lbank(), ccxt.liqui(), ccxt.livecoin(), ccxt.luno(),