1

I'm trying to use a Go port of the ib API to connect to my Interactive Brokers Trader Workstation.

I can connect and read data from the API but when I try to place an order on a paper trading account I get the following error:

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

But I do not believe I set a VOL attribute in the request. A minimal program that reproduces the error is:

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)
}

And the output from the program is:

$ 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.}

Note especially the dump from the ib engine 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--. Maybe someone familiar with the IB API can tell me what I'm doing wrong here?

Dave C
  • 7,729
  • 4
  • 49
  • 65
Johan Wikström
  • 4,033
  • 4
  • 28
  • 31

2 Answers2

1

It looks like the order object constructor is setting the volatility and volatilityType attributes to 0. In this case since the order is not a volatility order (type VOL), these attributes should be unset. In the IB API, 'unset' is designated by the maximum value for that primitive data type. So in the Order class,

volatilityType would need to be = math.MaxInt32 or 2147483647 and

volatility set as math.MaxFloat64 = 1.7976931348623157e+308

ejderuby
  • 710
  • 5
  • 21
Josh
  • 706
  • 3
  • 8
0

Instead of ib.Order{...}, try order := ib.NewOrder()

Stephen
  • 3,341
  • 1
  • 22
  • 21