当我在 pyq 中运行以下代码时...
from bittrex.bittrex import Bittrex, API_V2_0
import time, json
from pyq import q, K
get_bittrex = Bittrex(None, None)
starttime = time.time()
market_result = get_bittrex.get_market_summaries()['result']
while True:
for res in market_result:
market_name = res['MarketName']
ask = str(res['Ask'])
bid = str(res['Bid'])
last = str(res['Last'])
timeStamp = str(res['TimeStamp'])
if market_name in ['USDT-BTC', 'USDT-ETH', 'USDT-LTC']:
mkt = {"Name": market_name,"Bid": bid,"Ask": ask,"Time":timeStamp}
q.set(':alpha', [mkt])
q.upsert(':alpha', mkt)
q.get(':alpha').show()
time.sleep(10.0)
它每 10 秒返回一次控制台...
Name Bid Ask Time
--------------------------------------------------------------
USDT-BTC 15475.00000001 15530.99999999 2017-12-09T02:46:52.547
USDT-BTC 15475.00000001 15530.99999999 2017-12-09T02:46:52.547
Name Bid Ask Time
------------------------------------------------------
USDT-ETH 454.00000001 454.9999 2017-12-09T02:46:52.017
USDT-ETH 454.00000001 454.9999 2017-12-09T02:46:52.017
Name Bid Ask Time
----------------------------------------------------------
USDT-LTC 133.76999998 133.98999999 2017-12-09T02:46:49.703
USDT-LTC 133.76999998 133.98999999 2017-12-09T02:46:49.703
Name Bid Ask Time
--------------------------------------------------------------
USDT-BTC 15475.00000001 15530.99999999 2017-12-09T02:46:52.547
USDT-BTC 15475.00000001 15530.99999999 2017-12-09T02:46:52.547
Name Bid Ask Time
------------------------------------------------------
USDT-ETH 454.00000001 454.9999 2017-12-09T02:46:52.017
USDT-ETH 454.00000001 454.9999 2017-12-09T02:46:52.017
Name Bid Ask Time
----------------------------------------------------------
USDT-LTC 133.76999998 133.98999999 2017-12-09T02:46:49.703
USDT-LTC 133.76999998 133.98999999 2017-12-09T02:46:49.703
为什么每行打印 2 次?另外,我如何修改它以便将每个market_name
都添加到同一个表中,即,它当前正在将每个打印market_name
到它自己的表中,而不是附加到现有表中。
理想的输出如下...
Name Bid Ask Time
--------------------------------------------------------------
USDT-BTC 15475.00000001 15530.99999999 2017-12-09T02:46:52.547
USDT-ETH 454.00000001 454.9999 2017-12-09T02:46:52.017
USDT-LTC 133.76999998 133.98999999 2017-12-09T02:46:49.703