【问题标题】:Order doesn't get submitted on Interactive Brokers using ib_insync使用 ib_insync 无法在 Interactive Brokers 上提交订单
【发布时间】:2022-11-28 10:47:48
【问题描述】:

我正在尝试使用 TradingView 警报在 Interactive Brokers 上提交订单。我关注了this guide。它基本上使用 ngrok 来转发警报。

ngrok 似乎在线,当我运行代码时它显示GET /webhook 200 OK

然而,当我尝试下订单(例如,“SPY”)时,ngrok 总是返回消息400 Bad Request,并且订单未在交易者工作站上提交。您对可能出现的问题有什么想法吗?

这是我的代码:

# Imports
from datetime import datetime
from sanic import Sanic
from sanic import response
from ib_insync import *

# Create Sanic object called app
app = Sanic(name)
app.ib = None


# Create root / homepage
@app.route('/')
async def root(request):
    return response.text('online')

 
# Listen for signals and submit orders
@app.route('/webhook', methods=['POST'])
async def webhook(request):
    if request.method == 'POST':
        # Check if we need to reconnect
        await checkIfReconnect()
        # Parse the signal data
        data = request.json 
        order = MarketOrder('BUY', 1, account=app.ib.wrapper.accounts[0]) # Submit a marker order to default or primary account
        contract = Stock('SPY', 'SMART', 'USD')
        app.ib.placeOrder(contract, order) 


# Reconnect to IB if needed
async def checkIfReconnect():
    if not app.ib.isConnected() or not app.ib.client.isConnected():
        app.ib.disconnect()
        app.ib = IB()
        app.ib.connect('127.0.0.1', 7497, clientId=1)


# Run app
if name == 'main':
    # Connect to IB
    app.ib = IB()
    app.ib.connect('127.0.0.1', 7497, clientId=1)
    app.run(port=5000)

【问题讨论】:

    标签: python ngrok tradingview-api interactive-brokers


    【解决方案1】:

    这段代码似乎无法在最新版本的 Sonic 上运行。各种错误。有人可以更新吗?

    【讨论】:

      猜你喜欢
      • 2022-08-24
      • 1970-01-01
      • 1970-01-01
      • 2020-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多