ibapi icon indicating copy to clipboard operation
ibapi copied to clipboard

Can't place a order

Open kshv190 opened this issue 3 years ago • 18 comments

contract := new(ibapi.Contract) contract.Symbol = "MSFT" contract.Exchange = "SMART" contract.Currency = "USD" lmt := ibapi.NewLimitOrder("BUY", 244.26, 100) ic.PlaceOrder(newOrderId(), contract, lmt)

The order doesn't show on TWS nor get a openorder message

{"level":"info","ts":1670503751.6900978,"caller":"[email protected]/wrapper.go:656","msg":"<Error>","reqID":0,"errCode":10149,"errString":"Invalid order id: 0"}

kshv190 avatar Dec 08 '22 12:12 kshv190

The reason you can't is right there: invalid order id: 0. You have to start from 1 I think. And you have to increment by one each order you submit. @kshv190

JohnAllen avatar Dec 15 '22 08:12 JohnAllen

The valid order id would be returned via IbWrapper.NextValidID once the client handshaked with ib gateway successfully.

hadrianl avatar Mar 20 '23 03:03 hadrianl

Hi, I have the same issue. I'm trying to buy an AAPL stock but the operation does not show on the IBGateway log or TWS.

package main

import (
	"context"
	"fmt"
	"time"

	. "github.com/hadrianl/ibapi"
	"go.uber.org/zap"
)

func main() {
	var err error
	SetAPILogger(zap.NewDevelopmentConfig()) // log is default for production(json encode, info level), set to development(console encode, debug level) here
	log := GetLogger().Sugar()
	defer log.Sync()
	ibwrapper := &Wrapper{}

	ctx, _ := context.WithTimeout(context.Background(), time.Second*30)

	ic := NewIbClient(ibwrapper)
	ic.SetContext(ctx)
	err = ic.Connect("127.0.0.1", 7497, 0) // 7497 for TWS, 4002 for IB Gateway
	if err != nil {
		log.Panic("Connect failed:", err)
	}

	ic.SetConnectionOptions("+PACEAPI")

	err = ic.HandShake()
	if err != nil {
		log.Panic("HandShake failed:", err)
	}

	ic.Run() // start ibclient's message loop

	fmt.Println("Going to place order...")
	aapl := Contract{ContractID: 265598, Symbol: "AAPL", SecurityType: "STK", Exchange: "NYSE"}
	ic.ReqContractDetails(ic.GetReqID(), &aapl)
	lmtOrder := NewLimitOrder("BUY", 144, 1)
	ic.PlaceOrder(ibwrapper.GetNextOrderID(), &aapl, lmtOrder)

	err = ic.LoopUntilDone()

	log.Info(err)
}

Thanks in advance

francdoc avatar Aug 21 '23 17:08 francdoc

Franco, I may have a similar problem to you -- if you call ic.ReqOpenOrders(), does your order appear?

For me, it shows up in the (frustratingly under-documented) APIPending state with no indication of what might have caused that.

Further information: orders were working fine for me about a week before Franco's post (mid-August), but not when I came back from vacation last week (mid-September). My colleagues report that python library ibinsync continues to work as expected.

icecolbeveridge avatar Sep 14 '23 13:09 icecolbeveridge

Further to discussion on the TWS API list (hi Franco!), the problem seems to be that the highest server version available in ibapi is significantly behind the most up-to-date one. As I understand it, one difference is that IB currently requires Decimal types rather than float64s.

icecolbeveridge avatar Sep 15 '23 08:09 icecolbeveridge

I would try to catch up with the highest server version

hadrianl avatar Sep 25 '23 02:09 hadrianl

Hi everyone, I managed to execute MKT and LMT - BUY/SELL orders. I branched from master (stable version) for sharing purposes. Here is the link: https://github.com/francdoc/ibapi/tree/placeOrder_twsapi.10.19.01. This probably needs more work though.

Hope this helps.

francdoc avatar Sep 27 '23 04:09 francdoc

@francdoc Thanks!

hadrianl avatar Sep 27 '23 05:09 hadrianl

Your welcome, @hadrianl. Awesome work on your Go implementation by the way. If anyone is curious, to make the update to hadrianl's source code I used the twsapi.10.19.01 C++ source files. That is how I found the missing fields for the placeOrder function in Go.

francdoc avatar Sep 27 '23 05:09 francdoc

Franco, I may have a similar problem to you -- if you call ic.ReqOpenOrders(), does your order appear?

For me, it shows up in the (frustratingly under-documented) APIPending state with no indication of what might have caused that.

Further information: orders were working fine for me about a week before Franco's post (mid-August), but not when I came back from vacation last week (mid-September). My colleagues report that python library ibinsync continues to work as expected.

Hi @icecolbeveridge, yes. The order appears now. Check out the link I posted here, hope it helps.

francdoc avatar Sep 27 '23 06:09 francdoc

Nice work, Franco! Thanks :-)

On Wed, 27 Sept 2023 at 07:07, francdoc @.***> wrote:

Franco, I may have a similar problem to you -- if you call ic.ReqOpenOrders(), does your order appear?

For me, it shows up in the (frustratingly under-documented) APIPending state with no indication of what might have caused that.

Further information: orders were working fine for me about a week before Franco's post (mid-August), but not when I came back from vacation last week (mid-September). My colleagues report that python library ibinsync continues to work as expected.

Hi @icecolbeveridge https://github.com/icecolbeveridge, yes. The order appears now. Check out the link I posted below, hope it helps.

— Reply to this email directly, view it on GitHub https://github.com/hadrianl/ibapi/issues/36#issuecomment-1736759386, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJGYIUOPAJRQEAQ4ZF4WTLX4O7B5ANCNFSM6AAAAAASYCZ22Y . You are receiving this because you were mentioned.Message ID: @.***>

icecolbeveridge avatar Sep 27 '23 09:09 icecolbeveridge

Your welcome Colin!

francdoc avatar Sep 27 '23 17:09 francdoc

Hey @hadrianl, if you want I'd like to create a dedicated branch to make your source code fully compatible with the current stable twsapi (version 10.19.01). Do you think it's best to branch from 'master' or 'dev'? Or create a new github repo with a link to the original one as reference? Personally, I've been working more with 'master' lately, so I feel more comfortable working from there. Let me know what you think.

francdoc avatar Sep 28 '23 20:09 francdoc

I think master is just fine

hadrianl avatar Oct 01 '23 02:10 hadrianl

It seem that I`m missing the production release of tws api from 10.10 to 10.22

hadrianl avatar Oct 01 '23 03:10 hadrianl

Hi @hadrianl, ok. I’ll keep on working on a feature branch from master. When it becomes a stable release I will submit a pull request to your repo (master) so you can check it. Thanks.

francdoc avatar Oct 01 '23 15:10 francdoc

Hi, does it work for you with latest IBGW? I have same issue as was mentioned above. No errors, orders are not processed silently. @francdoc how did you debug it? Thanks

parakr avatar Mar 10 '25 19:03 parakr

Hi @parakr, sorry I could answer sooner. I'll check this out and try to finish the PR.

francdoc avatar Sep 09 '25 18:09 francdoc