python Flask应用程序双webhook执行问题

64jmpszr  于 2023-05-27  发布在  Python
关注(0)|答案(1)|浏览(159)

我已经创建了一个python flask应用程序,它可以从交易视图接收网络钩子警报,并在经纪人帐户上执行它们。问题是,如果止损是在进入交易视图后触发的,它会同时发送两个止损订单,并且语法相同,因为我使用部分利润退出。问题是当我收到两个警报在同一时间由于 flask 并发它执行两个订单,我得到额外的立场在我的经纪人帐户。下面的代码可以让你更好的理解

@app.route('/webhook_pivot', methods=[ 'POST'])
def webhook():
    # Get the data from the request
    data = json.loads(request.data)
    data_str = json.dumps(data, sort_keys=True)
    #print("Incoming webhook data:", data)
    side = data['side']
    qty = int(data['qty'] ) * int(lot)

    if side == "BUY" :

        #buy  execution code here.....

    elif side == "FULL_EXIT_BUY" and check_symbol_and_position(sym):

        with lock:
            if data_str in cache:

                # If the data is in the cache, it's a duplicate and should be ignored
                print("Double msg ignore")
                return "Duplicate data, ignoring"

            else:
                time.sleep(0.7)
                # BUY EXIT order ...but it send this part twice ..!!! the problem
vngu2lb8

vngu2lb81#

在这里没有人给我任何答案后,我知道我是自己的,但我终于解决了这个问题,使用sqlite3 db存储警报。当我得到购买退出所有警报它处理警报和存储在数据库中的警报ID与唯一的ID和当相同的警报来在同一时间其忽略它作为一个重复。

相关问题