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

Addition of Interactive Brokers Algorithmic orders #1203

Closed
wants to merge 5 commits into from
Closed

Addition of Interactive Brokers Algorithmic orders #1203

wants to merge 5 commits into from

Conversation

sicsix
Copy link

@sicsix sicsix commented Oct 12, 2017

I have added optional parameters to the orders to allow setting an IB Algorithm via enum OrderAlgorithm to MarketOrder(), LimitOrder() and SetHoldings(). Settings for the algorithm are stored in class AlgoParams.

The OrderAlgorithm and List[AlgoParams] are passed all the way through to the IB ordering API where the OrderAlgorithm enum is decoded into a string corresponding to the IB Algorithm API requirements, eg. OrderAlgorithm.ArrivalPrice becomes "ArrivalPx". List[AlgoParams] is recast(???) into List[TagValue] and sent off to IB with the order. (I used [ instead of < because it doesn't seem to work here)

SetHoldings() functions by design as synchronous, so allowing IB algos to be used might be a bad idea, as the IB algos can often take a lot longer than a normal market order to resolve.

Backtest results are not changed by setting an IB algo, a market order is a market order IB algo or not.

I'm very new to C#, a novice at programming and this is my first time on GitHub so I hope I haven't made too many mistakes.

…etholdings is synchronous by design and may work poorly with IB Algos however.
Copy link
Contributor

@mchandschuh mchandschuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this requires some thought/design/input by others on the QC team. @StefanoRaggi - perhaps this is another use case for the order parameters stuff you did for FA accounts?

List<AlgoParams> AlgoParams = new List<AlgoParams>();
AlgoParams.Add(new AlgoParams("adaptivePriority", "Normal"));
SetHoldings(_spy, 1, false, "", OrderAlgorithm.AdaptiveAlgo, AlgoParams);
//MarketOrder(_spy, 100, true, "", OrderAlgorithm.AdaptiveAlgo, AlgoParams);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert changes to this file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, this wasn't supposed to be committed.

/// <summary>
/// Interactive Brokers algorithm selection
/// </summary>
public enum OrderAlgorithm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are specific to interactive brokers and should be under the QuantConnect.Brokerages.InteractiveBrokers namespace -- still located in the Common project -- but we may want a more generalized way of handling brokerage specific order parameters rather than having to define special types for every brokerage -- so not sure how I feel about this yet

@sicsix
Copy link
Author

sicsix commented Oct 12, 2017

I had an idea this morning to pass a single class through the ordering system instead of the two IB specific variables in this pull. Something like OrderExtra contained in it's own file. Inside that would be special parameters for every broker that are individual to that broker.

So for example I could set OrderExtra.IB.Algorithm.AdaptiveAlgo and pass the parameters through in the same way.

This would be cleaner and broker agnostic, and any extra order options could be added to the OrderExtra class for any broker.

Thoughts?

…ngs(). Setholdings is synchronous by design and may work poorly with IB Algos however."

This reverts commit b885c86.
@sicsix
Copy link
Author

sicsix commented Oct 13, 2017

Added a different solution. The new class in OrderExtras.cs is a bit of a mess but the general idea is there.
EDIT: I don't know where BenchmarkAlgorithm.cs came from, it doesn't even exist in my IDE. Ignore that diff.

@sicsix
Copy link
Author

sicsix commented Oct 13, 2017

@mchandschuh has a good point. After looking at @StefanoRaggi Financial Adviser pull request, I've basically ended up duplicating his work for passing more order properties through. This algorithm selection stuff would fit perfectly into his new OrderProperties class.

@jaredbroad
Copy link
Member

Thank you @sic, tidy PR overall! We'll review and squish this into the FA PR and see if we can add the advanced orders quickly after.

@StefanoRaggi - Perhaps the default OrderProperties should be empty & have Brokerage Specific implementations? i.e. "InteractiveBrokersOrderProperties"

Then users could set the order default properties for their fav brokerage?

//In initialize:
DefaultOrderProperties = new InteractiveBrokersOrderProperties() {
      FaGroup = "",
      OrderAlgorithm = InteractiveBrokers.OrderAlgorithm.DarkIce
}

StefanoRaggi added a commit that referenced this pull request Oct 16, 2017
This change will make it easier to add other planned brokerage features:
for Interactive Brokers, besides Financial Advisor support, we will be adding IB algorithmic orders soon (PR #1203).
StefanoRaggi added a commit that referenced this pull request Oct 26, 2017
This change will make it easier to add other planned brokerage features:
for Interactive Brokers, besides Financial Advisor support, we will be adding IB algorithmic orders soon (PR #1203).
@mchandschuh
Copy link
Contributor

@sic8 - We've added a new type, InteractiveBrokersOrderProperties which implements IOrderProperties. This allows for brokerages to define properties specific to their api. You could try reworking what you've done by using the order properties.

  • Start clean from a fresh QuantConnect/Lean/master
  • Add Algorithm specific parameters to InteractiveBrokersOrderProperties
  • In InteractiveBrokersBrokerage check for the algorithm parameters via the order.Properties

@jaredbroad
Copy link
Member

Closing for now but this isn't too far off; lets do a new PR and leverage Stefano's work =)

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

Successfully merging this pull request may close these issues.

4 participants