Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hydrosquall opened this issue Aug 10, 2019 · 7 comments

Comments

@hydrosquall
Copy link

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
Copy link
Author

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.

// send orderMiscOptions parameter
if(m_serverVersion >= MIN_SERVER_VER_LINKING) {
StringBuilder orderMiscOptionsStr = new StringBuilder();
List<TagValue> orderMiscOptions = order.orderMiscOptions();
int orderMiscOptionsCount = orderMiscOptions == null ? 0 : orderMiscOptions.size();
if( orderMiscOptionsCount > 0) {
for( TagValue tagValue : orderMiscOptions ) {
orderMiscOptionsStr.append(tagValue.m_tag).append("=").append(tagValue.m_value).append(";");
}
}
b.send( orderMiscOptionsStr.toString());
}
if (m_serverVersion >= MIN_SERVER_VER_ORDER_SOLICITED) {
b.send(order.solicited());
}
if (m_serverVersion >= MIN_SERVER_VER_RANDOMIZE_SIZE_AND_PRICE) {
b.send(order.randomizeSize());
b.send(order.randomizePrice());
}
if (m_serverVersion >= MIN_SERVER_VER_PEGGED_TO_BENCHMARK) {
if (order.orderType() == OrderType.PEG_BENCH) {
b.send(order.referenceContractId());
b.send(order.isPeggedChangeAmountDecrease());
b.send(order.peggedChangeAmount());
b.send(order.referenceChangeAmount());
b.send(order.referenceExchangeId());
}
b.send(order.conditions().size());
if (order.conditions().size() > 0) {
for (OrderCondition item : order.conditions()) {
b.send(item.type().val());
item.writeTo(b);
}
b.send(order.conditionsIgnoreRth());
b.send(order.conditionsCancelOrder());
}
b.send(order.adjustedOrderType());
b.send(order.triggerPrice());
b.send(order.lmtPriceOffset());
b.send(order.adjustedStopPrice());
b.send(order.adjustedStopLimitPrice());
b.send(order.adjustedTrailingAmount());
b.send(order.adjustableTrailingUnit());
}

@nemozny
Copy link

nemozny commented Aug 19, 2019

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
Copy link
Author

hydrosquall commented Aug 19, 2019 via email

@hydrosquall hydrosquall changed the title [feature request] Add support for Trailing Stop Limit Order [feature request] Add support for Trailing Stop Limit Order via CLIENT_VERSION Upgrade Aug 31, 2019
@hydrosquall
Copy link
Author

hydrosquall commented Aug 31, 2019

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
Copy link
Contributor

tredondo commented Aug 18, 2021

@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
Copy link

ceddybi commented Aug 20, 2021

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants