gpt4 book ai didi

python - 如何找出我的流数据停止的原因?

转载 作者:太空宇宙 更新时间:2023-11-04 03:50:12 25 4
gpt4 key购买 nike

这是一道关于我如何在一个复杂的过程中找到失败点的问题。 (如果你能弄清楚到底出了什么问题......哇。)

我正在使用 QuickFixPython 2.7 连接到 future 市场,我正在使用 pandas 处理数据并将其放入数据帧等。过程是这样的:

  1. 连接到提供交换访问的 TT FIX 适配器。

  2. 提交 MarketDataIncrementalRefreshRequest,这会产生流数据(每次进行交易时都会报告)。因此,繁忙期间传入消息之间的时间间隔可能约为 10 毫秒。

  3. 每条消息都经过解析、转换为 pandas 数据帧,并与该市场的现有数据帧连接。代码:

    #df is dataframe of trades with 10 columns
    df.index = pd.to_datetime(df.TIME)
    #concatenate with prior data
    #TS_DIC is a dictionary holding trade data for various markets
    try:
    df_prev = TS_DIC[market_key]
    TS_DIC[market_key] = pd.concat([df_prev,df])

    except:
    #in the case this is the first message received:
    TS_DIC[market_key] = df

    #now write to disk
    try:
    #if file exists just write
    to_file = open('path/for/data', 'a+')
    df.to_csv(mode='a+', path_or_buf= to_file, header=False, index=False)
    to_file.close()
    except:
    #create the file with headers and write
    to_file = open(path+name, 'wb')
    df.to_csv( path_or_buf= to_file, index=False)
    to_file.close()

此过程运行良好,有时持续数小时,有时持续数分钟,然后停止运行。从来没有任何错误,它只是停止。结果是有差距的数据。我可以通过再次执行第 2 步使流程重新开始。

如果有人习惯于高通量数据甚至这些软件包,我将不胜感激。

这可能是什么问题?我如何弄清楚出了什么问题?

最佳答案

我想我会让遇到这个问题的任何人都知道我是如何解决这个问题的:

按照上面的评论打印错误实际上并没有帮助解决问题。数据仍然会停止而不会出现打印错误。原因是有时 QuickFix 会出于某种原因脱机启动,然后自动重新登录。显然这是 FIX 应用程序必须处理的事情。

发生了什么:因为我是手动启动数据下载,所以每次我离线启动时,数据都会停止。因此,通过将数据请求放入 QuickFix 的 OnLogon 函数中,我能够在程序登录时自动重复下载请求。

这解决了我的问题。感谢 CasualDemon 和 cpburnz。

关于python - 如何找出我的流数据停止的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21640477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com