¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io
Date

Re: Cannot transmit order (main order and stop loss orders)

 

On Tue, Jan 10, 2023 at 06:17 PM, GreenGreen wrote:

I just checked log files and it shows:

T4-2-51-321-Error validating request.-'bN' : cause - Invalid order type was entered--

Do you think that could be because it saw a transmit on an individual order that wasn't part of a parent order?


Re: Cannot transmit order (main order and stop loss orders)

 

I just checked log files and it shows:?

T4-2-51-321-Error validating request.-'bN' : cause - Invalid order type was entered--


Re: Cannot transmit order (main order and stop loss orders)

 

Do what you think is best.


Re: Cannot transmit order (main order and stop loss orders)

 

Thank you, I saw it. I can make it look the way they showed, but I do not think it matters. They simply have two functions. One creates three orders and puts them into list. The other routine simply loops through the list and places orders.?


Re: Cannot transmit order (main order and stop loss orders)

 

On Tue, Jan 10, 2023 at 05:37 PM, GreenGreen wrote:

You are probably looking at C#, I am using Python.

Ok, so I'm a polyglot :-P If you go to the docs and click the Python button at the top it will translate for you...

   38         bracketOrder = [parent, takeProfit, stopLoss]
   39         return bracketOrder

Let us know if this helps :-)


Re: Cannot transmit order (main order and stop loss orders)

 

You are probably looking at C#, I am using Python.


Re: Cannot transmit order (main order and stop loss orders)

 

How come the code you posted is missing this stuff that's mentioned in the docs?

            List<Order> bracketOrder = new List<Order>();
            bracketOrder.Add(parent);
            bracketOrder.Add(takeProfit);
            bracketOrder.Add(stopLoss);
            return bracketOrder;


Re: Cannot transmit order (main order and stop loss orders)

 

No errors. Here is console output:

NextValidId: 39
Error:? -1? ?2104? ?Market data farm connection is OK:usfuture.nj??
Error:? -1? ?2104? ?Market data farm connection is OK:usfarm.nj??
Error:? -1? ?2104? ?Market data farm connection is OK:usfarm??
Error:? -1? ?2106? ?HMDS data farm connection is OK:euhmds??
Error:? -1? ?2106? ?HMDS data farm connection is OK:ushmds.nj??
Error:? -1? ?2106? ?HMDS data farm connection is OK:cashhmds??
Error:? -1? ?2106? ?HMDS data farm connection is OK:fundfarm??
Error:? -1? ?2106? ?HMDS data farm connection is OK:ushmds??
Error:? -1? ?2158? ?Sec-def data farm connection is OK:secdefil


I do not know what precautions I can check. Everything worked find a day ago.


Re: Cannot transmit order (main order and stop loss orders)

 

IDK... no errors? You check precautions?

TWS precautions can be bypassed by navigating to File/Edit ¡ú Global Configuration ¡ú API ¡ú Precautions, and check the box "Bypass Order Precautions for API Orders". Once this is done, API orders placed from a third party software will not be checked by TWS precautions.


Cannot transmit order (main order and stop loss orders)

 

I am trying to submit two orders, one main order (parent order) and the other is stop loss order. I am following TWS API documentation?
But for some reason my main order does not show in TWS as submitted. It only show us with "Transmit" option. I am expecting both order to be transmitted without any problems. Here is my Python code:

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.ticktype import TickTypeEnum
import time
import datetime
import threading
from ibapi.contract import Contract
from ibapi.order import Order
?
class TestApp(EWrapper, EClient):
? ? def __init__(self):
? ? ? ? EClient.__init__(self, self)
? ? ? ? self.nextValidOrderId = None
? ? ? ??
? ? # this is getting called upon establishing connection? ??
? ? def nextValidId(self, orderId: int):
? ? ? ? super().nextValidId(orderId)
? ? ? ? self.nextValidOrderId = orderId
? ? ? ? print("NextValidId:", orderId)
? ? ? ??
? ? def error(self, reqId, errorCode, errorString, advancedOrderRejectJson):
? ? ? ? print("Error: ", reqId, " ", errorCode, " ", errorString, "", advancedOrderRejectJson)

contract = Contract()
contract.symbol = "SPY"
contract.secType = "STK"
contract.exchange = "SMART"
contract.currency = "USD"
contract.primaryExchange = "ARCA"
?
order = Order()
order.OrderType = "LMT";
order.action = 'BUY'
order.totalQuantity = 3
order.orderType = 'LMT'
order.lmtPrice = '21'
order.transmit = False
?
stopLossOrder = Order()
stopLossOrder.OrderType = 'STP'
stopLossOrder.action = 'SELL'
stopLossOrder.totalQuantity = 3
stopLossOrder.auxPrice = 18
stopLossOrder.transmit = True

app = TestApp()
app.connect("127.0.0.1", 7497, 1)
?
api_thread = threading.Thread(target=app.run)
api_thread.start()
time.sleep(2)
?
order.orderId = app.nextValidOrderId
stopLossOrder.orderId = app.nextValidOrderId + 1
stopLossOrder.parentId = app.nextValidOrderId
?
app.placeOrder(app.nextValidOrderId, contract, order)
app.placeOrder(app.nextValidOrderId+1, contract, stopLossOrder)
?
?
app.disconnect()

What am I doing wrong?
?
?


Re: How is auction price calculated?

 

¿ªÔÆÌåÓý

Not sure as I don¡¯t typically trade US stocks but I¡¯d be interested to hear the answer if someone else knows.


On 10 Jan 2023, at 6:00 am, JZcgQR2N <wingnut293@...> wrote:

?Thanks. For NYSE, what is the difference between "NYSE MKT Order Imbalances" and "NYSE Order Imbalances" IB data feeds??
?


Re: How is auction price calculated?

 

Thanks. For NYSE, what is the difference between "NYSE MKT Order Imbalances" and "NYSE Order Imbalances" IB data feeds??
?


Re: TWS API Linux - Segmentation fault - __bid64_to_string

 

I won't directly blame the machine, look very similar to same issue on Mac and Windows if using the wrong Decimal lib.
I guesstimate it around the selection of method (or a lack of)? used by linker on Decimal type. 2 mode exists: by reference/by value.

It's an old story for me now but I think I remember that libbidgcc000.a is by reference while libbidgcc100.a is by value. I use By value
Try linking with
libbidgcc100.a


Re: TWS API Linux - Segmentation fault - __bid64_to_string

 

On Mon, Jan 9, 2023 at 04:40 AM, bannerman1985@... wrote:

dangerous relocation: collect2: fatal error

Ok, I just managed to recreate this problem and (I think this may have been mentioned) but it seems to be a platform issue. The library provided by IB is built for x86_64, not i686. You can determine what your system is based on by running uname -m. If it says i686 you're going to have to go through whatever extra machinations to get things working (i.e. rebuild libbid.a, change makefile, etc).

I'm not sure why anyone would need to run their trading software on an i686 in this day and age. But, I'll freely admit I have a very old thinkpad I still like to use sometimes (just not for trading).

Anyway, that's my story and I'm sticking to it until conflicting information comes to light.


Re: TWS API Linux - Segmentation fault - __bid64_to_string

 

On Mon, Jan 9, 2023 at 05:14 AM, bannerman1985@... wrote:

hopefully this solves others issues with this

Hopefully it doesn't hurt them either though... because I just built the Cpp sample from api ver. 1019.01 and 1020.01 on...

  • bare metal running Ubuntu 16.04.7 LTS
  • kvm running Debian 11 bullseye
  • lxc container running Debian 10 bullseye
  • bare metal running Debian 11 bullseye

All of the builds succeeded and I didn't see the "dangerous relocation".

But I remember a while back someone else had that problem too. So, I can't help but wonder if somehow your environment and theirs share some kind of aberration. Was this on a fresh install?


Re: TWS API Linux - Segmentation fault - __bid64_to_string

 

also works on WSL ubuntu.


Re: TWS API Linux - Segmentation fault - __bid64_to_string

 

Ok finally got it working by locating where the intel floating point math library was located, named:?libintelrdfpmath-dev :?

?root@Ubuntu-22:/bin# dpkg -L libintelrdfpmath-dev
/.
/usr
/usr/include
/usr/include/bid_conf.h
/usr/include/bid_functions.h
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libbidgcc000.a
/usr/lib/x86_64-linux-gnu/libbidgcc000b.a
/usr/lib/x86_64-linux-gnu/libbidgcc001.a
/usr/lib/x86_64-linux-gnu/libbidgcc001b.a
/usr/lib/x86_64-linux-gnu/libbidgcc010.a
/usr/lib/x86_64-linux-gnu/libbidgcc010b.a
/usr/lib/x86_64-linux-gnu/libbidgcc011.a
/usr/lib/x86_64-linux-gnu/libbidgcc011b.a
/usr/lib/x86_64-linux-gnu/libbidgcc100.a
/usr/lib/x86_64-linux-gnu/libbidgcc100b.a
/usr/lib/x86_64-linux-gnu/libbidgcc101.a
/usr/lib/x86_64-linux-gnu/libbidgcc101b.a
/usr/lib/x86_64-linux-gnu/libbidgcc110.a
/usr/lib/x86_64-linux-gnu/libbidgcc110b.a
/usr/lib/x86_64-linux-gnu/libbidgcc111.a
/usr/lib/x86_64-linux-gnu/libbidgcc111b.a
/usr/share
/usr/share/doc
/usr/share/doc/libintelrdfpmath-dev
/usr/share/doc/libintelrdfpmath-dev/README.gz
/usr/share/doc/libintelrdfpmath-dev/changelog.Debian.gz
/usr/share/doc/libintelrdfpmath-dev/copyright

I edited the makefile to include the path to these libraries, now which one???

I added?/usr/lib/x86_64-linux-gnu/libbidgcc000.a to my make file.

My make file looks like:?
CXX=g++
CXXFLAGS=-pthread -Wall -Wno-switch -Wpedantic -Wno-unused-function -std=c++11
ROOT_DIR=../../../source/cppclient
BASE_SRC_DIR=${ROOT_DIR}/client
INCLUDES=-I${BASE_SRC_DIR} -I${ROOT_DIR}
SHARED_LIB_DIRS=${BASE_SRC_DIR}
SHARD_LIBS=libTwsSocketClient.so
TARGET=TestCppClient

$(TARGET)Static:
$(CXX) $(CXXFLAGS) $(INCLUDES) $(BASE_SRC_DIR)/*.cpp ./*.cpp /usr/lib/x86_64-linux-gnu/libbidgcc000.a -o$(TARGET)Static

$(TARGET):
$(CXX) $(CXXFLAGS) $(INCLUDES) ./*.cpp $(BASE_SRC_DIR)/lib/libbid.so $(SHARED_LIB_DIRS)/$(SHARD_LIBS) -o$(TARGET)

clean:
rm -f $(TARGET) $(TARGET)Static *.o

requested real time bars, decimal places looks as intended

RealTimeBars. 3001 - Time: 1673241105, Open: 0.87948, High: 0.87951, Low: 0.87947, Close: 0.87951, Volume: -1, Count: -1, WAP: -1

hopefully this solves others issues with this.?

Thanks for those who took the time to look at this and give responses.?


Re: TWS API Linux - Segmentation fault - __bid64_to_string

 

well virtulbox and ubuntu?

lare9x@Ubuntu-22:~/IBJts/samples/Cpp/TestCppClient$ make
g++ -pthread -Wall -Wno-switch -Wpedantic -Wno-unused-function -std=c++11 -I../../../source/cppclient/client -I../../../source/cppclient ../../../source/cppclient/client/*.cpp ./*.cpp ../../../source/cppclient/client/lib/libbid.a -oTestCppClientStatic
/usr/bin/ld: BFD (GNU Binutils for Ubuntu) 2.38 assertion fail ../../bfd/reloc.c:8580
../../../source/cppclient/client/lib/libbid.a(bid64_string.o):bid64_string.c:(.pdata+0x0): dangerous relocation: collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
compilation terminated.
make: *** [makefile:11: TestCppClientStatic] Error 1

Well something going on with?libbid.a


Re: TWS API Linux - Segmentation fault - __bid64_to_string

 

I strongly recommend to use a containerized setup for tws/ib-gateway in wsl.
If you chose ubuntu as host for wsl, then lxd (sudo snap install lxd) should do it.

There is an automated setup for a trading-environment in a lxd-container:?
If needed, you can just copy the instance to a cloud-instance or a ?real? ubuntu-machine.

hartmut


Re: TWS API Linux - Segmentation fault - __bid64_to_string

 

Only reason really have windows installed on this machine is the wife and kids use it - however - running a few strategies on python / c++ - cpu usuage was about 8%. So using linux here on VM maybe wont slow too much BUT there is a whole GUI with ubuntu to the point i dont think my wife and kids would get lost for general browing of the internet. Dual boot maybe - lets see if i can get this whole thing up and running on linux.?