node-ib icon indicating copy to clipboard operation
node-ib copied to clipboard

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

Open hydrosquall opened this issue 5 years ago • 7 comments

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

  • action
  • quantity
  • trailStopPrice
  • lmtPriceOffset
  • auxPrice

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

hydrosquall avatar Aug 10 '19 00:08 hydrosquall

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

hydrosquall avatar Aug 10 '19 01:08 hydrosquall

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.

nemozny avatar Aug 19 '19 16:08 nemozny

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 [email protected] 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 avatar Aug 19 '19 22:08 hydrosquall

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)

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

(to what the JS code implements)

  • https://github.com/pilwon/node-ib/blob/9a4dc7b268eafede355c44115e40103e16c07367/lib/constants.js#L1
  • https://github.com/pilwon/node-ib/blob/9a4dc7b268eafede355c44115e40103e16c07367/lib/constants.js#L8

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

  • https://github.com/pilwon/node-ib/issues/130
  • #131
  • #111

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.

hydrosquall avatar Aug 31 '19 18:08 hydrosquall

@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.

tredondo avatar Aug 18 '21 00:08 tredondo

@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

ceddybi avatar Aug 20 '21 16:08 ceddybi

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 [email protected]

GithubJaimeLee avatar Nov 30 '23 20:11 GithubJaimeLee