我正在尝试使用ib API的a Go port连接到我的盈透证券交易平台。

我可以从API连接并读取数据,但是当我尝试在纸币交易帐户上下订单时,出现以下错误:

&{1 321 Error validating request:-'bB' : cause - Cannot set VOL attribute on non-VOL order.}

但是我不相信我在请求中设置了VOL属性。产生此错误的最小程序是:
package main

import (
    "fmt"
    "math"
    "time"

    "github.com/gofinance/ib"
)

func main() {
    eng, err := ib.NewEngine(ib.EngineOptions{
        DumpConversation: true,
        Gateway:          "127.0.0.1:1122",
    })
    if err != nil {
        fmt.Printf("Connection error: %v", err)
    }
    // Note: you have to make sure the connection has been fully established
    // before attempting to do any requests to the TWS. Failure to do so will
    // result in the TWS closing the connection. Typically this can be done by
    // waiting for a callback from an event and the end of the initial connection
    // handshake, such as IBApi.EWrapper.nextValidId or IBApi.EWrapper.managedAccounts
    // https://interactivebrokers.github.io/tws-api/connection.html
    // TODO take apart engine.go and make it wait properly.
    time.Sleep(1 * time.Second)
    defer eng.Stop()
    // printInstrument(eng)
    reqID := eng.NextRequestID()
    o := make(chan ib.Reply)
    eng.Subscribe(o, reqID)
    order := ib.Order{
        Action:     "BUY",
        OrderType:  "LMT",
        TotalQty:   100,
        LimitPrice: 95.94,
    }
    contract := ib.Contract{
        SecurityType:    "STK",
        Symbol:          "MSFT",
        Exchange:        "SMART",
        PrimaryExchange: "NASDAQ",
        Currency:        "USD",
    }
    req := &ib.PlaceOrder{
        Order:    order,
        Contract: contract,
    }
    req.SetID(reqID)
    if err := eng.Send(req); err != nil {
        fmt.Printf("Send error: %v", err)
    }
    fmt.Println("Waiting for reply...")
    reply := <-o
    fmt.Println(reply)
}

该程序的输出为:
$ go run main.go
2> '71-1-2-'
2< &{15 1} &{[DU1029297]}
2< &{9 1} &{1}
2< &{4 2} &{-1 2104 Market data farm connection is OK:usfuture}
2< &{4 2} &{-1 2104 Market data farm connection is OK:cashfarm}
2< &{4 2} &{-1 2104 Market data farm connection is OK:usfarm.us}
2< &{4 2} &{-1 2104 Market data farm connection is OK:usfarm}
2< &{4 2} &{-1 2106 HMDS data farm connection is OK:ilhmds}
2< &{4 2} &{-1 2106 HMDS data farm connection is OK:euhmds}
2< &{4 2} &{-1 2106 HMDS data farm connection is OK:fundfarm}
2< &{4 2} &{-1 2106 HMDS data farm connection is OK:ushmds}
2> '3-42-1-0-MSFT-STK--0---SMART-NASDAQ-USD-----BUY-100-LMT-95.94-0-----0--0-0-0-0-0-0-0-0--0-------0--0-0---0-0-0-0-0-0-0-0-0-0-0-0-0-0-0--0-0-0-0-0-0-0-0-----0---0-0--0--'
Waiting for reply...
2< &{4 2} &{1 321 Error validating request:-'bB' : cause - Cannot set VOL attribute on...
&{1 321 Error validating request:-'bB' : cause - Cannot set VOL attribute on non-VOL order.}

特别要注意来自ib引擎3-42-1-0-MSFT-STK--0---SMART-NASDAQ-USD-----BUY-100-LMT-95.94-0-----0--0-0-0-0-0-0-0-0--0-------0--0-0---0-0-0-0-0-0-0-0-0-0-0-0-0-0-0--0-0-0-0-0-0-0-0-----0---0-0--0--的转储。也许熟悉IB API的人可以告诉我我在做什么错?

最佳答案

代替ib.Order{...},尝试order := ib.NewOrder()

关于go - IB API订单放置错误:无法在非成交量定单上设置VOL属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49971796/

10-15 23:25