【问题标题】:Taking the minute from the JSON time index pulled, to compare with current time.从提取的 JSON 时间索引中获取分钟,与当前时间进行比较。
【发布时间】:2019-04-09 03:43:33
【问题描述】:
import time
import pandas as pd
import datetime as dt
from time import strftime


df = pd.read_json('https://forex.1forge.com/1.0.3/quotes?pairs=EURUSD,USDJPY,AUDUSD,&api_key=KEY')
df = df.pivot_table('price', 'timestamp', 'symbol')

min = int(time.strftime("%M"))
minpull= df.index[0]

print(min)
print(minpull) 

    while min <= minpull:
    print(df)

如何将分钟作为单数与当前实际时间进行比较?

该代码以 JSON 格式从 URL 中提取数据并放入 pandas 数据帧。我想将设置在索引(pullmin)处的时间与当前时间(min)进行比较。这样,当下一分钟到来时,代码将提取下一组数据,我将获得一分钟一分钟的数据。最终,它将添加相同的 pandas df 但我也没有弄清楚。

【问题讨论】:

  • 请向我们展示您的数据框的外观。
  • 当我输入时:while min

标签: python json pandas indexing time-series


【解决方案1】:

获取一个数据帧,等待 60 秒追加下一个:

import time
import pandas as pd
import datetime as dt
from time import strftime, sleep

def get_data(): 
    df = pd.read_json('https://forex.1forge.com/1.0.3/quotes?pairs=EURUSD,USDJPY,AUDUSD,&api_key=KEY')
    return df.pivot_table('price', 'timestamp', 'symbol')

df = get_data()
for k in range(5): # takes 5 minutes ...
    sleep(60)
    df2 = get_data()
    df.append(df2)

未经测试,没有钥匙。

【讨论】:

  • 这不起作用。我这样做是为了让我在每分钟而不是每分钟准确地从 url 中提取数据。我也使用了计划模块,但由于某种原因,它并不是每 60 秒一次
  • 你不会准确无误的。无论如何,你会漂移一些。如果您想获得时间关键数据,这将不起作用,我同意-但是当其他人在同一数据中心的同一机架中租用空间时,使用这种数据进行交易,因此延迟最小以自动拍摄最佳价格-您将失去使用在那场比赛中的蟒蛇。阅读 f.e. cryptodisrupt.com/what-is-latency-and-why-is-it-so-important
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多