Python:使用对象调用包的函数

时间:2018-09-09 07:40:05

标签: python ccxt

我正在将ccxt模块用于python。 我可以将其初始化以进行交流。例如bittrex:

exchange = ccxt.bittrex({
    'enableRateLimit': True
})
return exchange

但是以下操作无效:

ex = 'bittrex'
print(ex)
exchange = ccxt.ex({
    'enableRateLimit': True
})
return exchange

错误:AttributeError: module 'ccxt' has no attribute 'ex' 我该如何工作?

1 个答案:

答案 0 :(得分:4)

import ccxt
ex = 'bittrex'
ex_obj = getattr(ccxt, ex)
exchange = ex_obj({
    'enableRateLimit': True
})
return exchange

ex 必须是以下受支持的交换列表之一

  
    
      

打印(ccxt.exchanges)       ['_1broker','_ 1btcxe','acx','allcoin','anxpro','anybits','bcex','bibox','bigone','binance','bit2c','bitbank',' bitbay”,“ bitfinex”,“ bitfinex2”,“ bitflyer”,“ bitforex”,“ bithumb”,“ bitkk”,“ bitlish”,“ bitmarket”,“ bitmex”,“ bitsane”,“ bitso”,“ bitstamp” ,'bitstamp1','bittrex','bitz','bl3p','bleutrade','braziliex','btcalpha','btcbox','btcchina','btcexchange','btcmarkets','btctradeim',' btctradeua','btcturk','btcx','bxinth','ccex','cex','chbtc','chilebit','cobinhood','coinbase','coinbaseprime','coinbasepro','coincheck' ,“ coinegg”,“ coinex”,“ coinexchange”,“ coinfalcon”,“ coinfloor”,“ coingi”,“ coinmarketcap”,“ coinmate”,“ coinnest”,“ coinone”,“ coinsecure”,“ coinspot”,“ cointiger”,“ coolcoin”,“ crypton”,“ cryptopia”,“ deribit”,“ dsx”,“ ethfinex”,“ exmo”,“ exx”,“ fcoin”,“ flowbtc”,“ foxbit”,“ fybse” ,“ fybsg”,“ gatecoin”,“ gateio”,“ gdax”,“ gemini”,“ getbtc”,“ hadax”,“ hitbtc”,“ hitbtc2”,“ huobi”,“ huobicny”,“ huobipro”,“ ice3x','independentreserve','ind odax”,“ itbit”,“ jubi”,“ kraken”,“ kucoin”,“ kuna”,“ lakebtc”,“ lbank”,“ liqui”,“ livecoin”,“ luno”,“ lykke”,“ mercado” ,“ mixcoins”,“ negociecoins”,“ nova”,“ okcoincny”,“ okcoinusd”,“ okex”,“ paymium”,“ poloniex”,“ qryptos”,“ quadrigacx”,“ quoinex”,“ rightbtc”,“ southxchange”,“ surbitcoin”,“ theocean”,“ therock”,“ tidebit”,“ tidex”,“ uex”,“ urdubit”,“ vaultoro”,“ vbtc”,“ virwox”,“ wex”,“ xbtce” ,“ yobit”,“ yunbi”,“ zaif”,“ zb”]