将Bittrex API结果从循环添加到数据框

时间:2019-10-07 01:25:29

标签: python json api dataframe

我是python的新手。通过遵循其他人的代码,我将以下代码组合在一起。该代码通过循环__name/main__部分下列表中每个“对”的代码来提供“ GetLatestTick”的输出。我什至可以在正在处理的行上执行计算。如何将输出组织成DataFrame进行排序和其他操作?

from multiprocessing import Process, Lock
import requests, json
from tabulate import tabulate

def bittrex(lock, pair):
    lock.acquire()
    #print(pair)
    get_request_link = ('https://bittrex.com/Api/v2.0/pub/market/GetLatestTick?marketName='
                        + pair + '&tickInterval=thirtyMin')
    api = requests.get(get_request_link)
    data = json.loads(api.text)

    for i in data:
        if i == 'result':
            for h in data[i]:
                print(pair,h['O'],h['H'],h['L'],h['C'],h['V'],h['BV'],
                      (((h['O'])/(h['H']))-1),h['T'])

            lock.release()
            return data

def main():
    bitt_all = bittrex(lock, pair)  # This still required

if __name__ == '__main__':

    lock = Lock()
    pair = ['BTC-MUE','USD-ETH','USDT-TRX','USDT-BTC']

    for pair in pair:
        Process(target=bittrex, args=(lock, pair)).start()

0 个答案:

没有答案