pilwon / node-ib

Interactive Brokers TWS API client library for Node.js
382 stars 134 forks source link

[feature request] Add support for Trailing Stop Limit Order via CLIENT_VERSION Upgrade #145

Open hydrosquall opened 5 years ago

hydrosquall commented 5 years ago

This is the order type documented under the Trailing Stop Limit heading here, with the code of TRAIL LIMIT. It would have fields for

I imagine this would be added as a new file inside of ./lib/order with a name like trailLimit.js.

hydrosquall commented 5 years ago

From looking at the code further, the primary in-depth change needed to make this work is to support the lmtPriceOffset field, which is currently not handled in the outgoing.js file. Specifically, this section of the EClient.java file would need to be ported for this to work correctly.

https://github.com/pilwon/node-ib/blob/85305c753ad3f69b3e9e3cc54f50b628892da9bb/ref/client/EClient.java#L1829-L1879

nemozny commented 5 years ago

You don't need to use /lib/orders, those are just for your convenience. You can construct the order by yourself, which is what I do.

const parent = orderId++
ib.placeOrder(parent, contract, {
                action : "BUY",
                orderType : "MKT",
                transmit : false
            })
ib.placeOrder(orderId++, contract, {
                action : "SELL",
                orderType : "TRAIL",
                auxPrice : 10,
                                parentId : parent,
                transmit : true
            })

The important here is the transmit and parentId keys. Similarly you can build your TRAIL LIMIT.

hydrosquall commented 5 years ago

Thanks for the suggestion @nemozny. I tried manually building the order as well before, and was able to send other types of order that way. The issue is that the “lmtPriceOffset” field doesn’t get transmitted since outgoing.js doesn’t have code to handle it.

On Mon, Aug 19, 2019 at 12:16 PM nemozny notifications@github.com wrote:

You don't need to use /lib/orders, those are just for your convenience. You can construct the order by yourself, which is what I do.

const parent = orderId++ ib.placeOrder(parent, contract, { action : "BUY", orderType : "MKT", transmit : false }) ib.placeOrder(orderId++, contract, { action : "SELL", orderType : "TRAIL", auxPrice : 10, parentId : parent, transmit : true })

The important here is the transmit and parentId keys. Similarly you can build your TRAIL LIMIT.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pilwon/node-ib/issues/145?email_source=notifications&email_token=ACE2MM6N4FUUM55P3TEYOOTQFLBNJA5CNFSM4IKYFK62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4TPVJQ#issuecomment-522648230, or mute the thread https://github.com/notifications/unsubscribe-auth/ACE2MMYK7XYGJBBDWC5K3FDQFLBNJANCNFSM4IKYFK6Q .

hydrosquall commented 5 years ago

Update:

Upon closer inspection, it appears that adding these fields was probably part of the jump from API version 9.70.01 from 9.73

(Compare what the Java client supports)

(to what the JS code implements)

Adding support for newer versions of the client would address these sibling issues:

I have a hunch about how to adjust this part of the code with outgoing.js, but am unsure about the extent of the other API changes needed for deserializing incoming payloads.

tredondo commented 3 years ago

@pilwon: how can we add fields to the code that deserializes them from the server?

For example, in placeOrder, orderState misses many of the newer fields like initMarginChange.

I tried adding orderState.foo = this.dequeue() after the last assignment (to .warningText) but that caused the client to time out.

ceddybi commented 3 years ago

@tredondo @hydrosquall - you are late to the party, we have everything here https://github.com/stoqey/ib,

@pilwon you must update the readme and point to this new version, clearly, this node-ib is very outdated and you barely merge changes, which is very misleading to other developers

GithubJaimeLee commented 11 months ago

This is such a genius project, I want to join in!! I'm currently using your program and if I find any bugs, I will provide feedback on the open-source platform!!! The author is incredible!!! Please give me the PayPal of the owner, I want to make a donation!!!! My email is 18038163520@163.com