bittrex 的 ccxt 格式提取器

问题描述

我可以执行以下操作来检索我在 Bittrex 上的资产并将其写入文件,以便我可以在另一个程序中使用它:

import ccxt
exchange_id = 'bittrex'
exchange_class = getattr(ccxt,exchange_id)
exchange = exchange_class({
    'apiKey': config.BITTREX_API_KEY,'secret': config.BITTREX_API_SECRET,'timeout': 30000,'enableRateLimit': True,})

account = exchange.fetch_balance()

fieldnames = ['currencySymbol','total','available','updatedAt']
balances = account['info']

fname = 'bittrex_holdings.txt'

# open the file in the write mode
with open(os.path.join(dirname,subfolder,fname),'w',encoding='UTF8',newline='') as f:
    writer = csv.DictWriter(f,fieldnames=fieldnames)
    writer.writerows(balances)

这给出了一个看起来像这样的文件

AKRO,0.00000000,2021-02-09T14:59:54.81Z
ALGO,1000.00000000,2021-01-03T10:14:22.29Z

现在我想对 fetch_tickers 做同样的事情,但我只得到一个带有一个转储的文件。到目前为止我做了什么:

fname = 'bittrex_prices.txt'

prices = exchange.fetch_tickers()
with open(os.path.join(dirname,newline='') as f:
    print(prices,file=f)

这给了我一个看起来像这样的文件

{'4ART/BTC': {'symbol': '4ART/BTC','timestamp': None,'datetime': None,'high': None,'low': None,'bid': 1.98e-06,'bidVolume': None,'ask': 2.01e-06,'askVolume': None,'vwap': None,'open': None,'close': 2e-06,'last': 2e-06,'prevIoUsClose': None,'change': None,'percentage': None,'average': None,'baseVolume': None,'quoteVolume': None,'info': {'symbol': '4ART-BTC','lastTradeRate': '0.00000200','bidrate': '0.00000198','askRate': '0.00000201'}},'4ART/USDT': {'symbol': '4ART/USDT','bid': 0.119,'ask': 0.12059,'close': 0.1206,'last': 0.1206,'info': {'symbol': '4ART-USDT','lastTradeRate': '0.12060000','bidrate': '0.11900000','askRate': '0.12059000'}},

有谁知道我如何在不同的行上获取所有代码?应该没那么难,但我对 python 不太熟悉。

  • 编辑 *

我试过了,但出现错误

account = exchange.fetch_tickers()

fieldnames = ['symbol','lastTradeRate','bidrate','askRate']
prices = account['info']

fname = 'bittrex_prices.txt'

# open the file in the write mode
with open(os.path.join(dirname,fieldnames=fieldnames)
    writer.writerows(prices)

    prices = account['info']
KeyError: 'info'

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)