Back

Lean Market Order Mode (Quantity vs Funds)

I have been digging around the Lean engine, and I wanted to verify my findings to be certain that I have not missed somethign with regards to Market Orders.

From my understanding, the default Lean implementation of creating a market order (whether through Buy/Sell/Order/MarketOrder methods) creates a Market Order by Quantity.  When it sends off the order it is stating, to the brokerage, buy X amount of this security at the market price.

At least one exchange (maybe others that I have not looked at), GDAX (cryptocurrency), allows market orders to be placed in two manners via the API:

  1. Size: Specify X quantity at market price (default for sells on their GUI)
  2. Funds: Specify Y funds at market price (default for buys on their GUI)

In both cases the brokerage does show an estimate at current market price, but that's just what it is - a rough (and typically inaccurate) estimate due to volatility.

This is done through the /orders endpoint (https://docs.gdax.com/#place-a-new-order) by specifying (example given in the BTCUSD market:

market order parameters
Param Description
size [optional]* Desired amount in BTC
funds [optional]* Desired amount of quote currency to use

* One of size or funds is required.

The end result (pros and cons of both, aside from the pros and cons in general of market orders):

Size: (PRO) You will obtain the quantity desired (unless insufficient funds due to slippage) (CON) You have no control over the amount spent (due to slippage)
Funds: (PRO) You have control over the amount spent (CON) You have no control over the quantity obtained (due to slippage)

Of course, there are the Calculate methods that can calculate quantity based upon price and funds, but again, that's really just an estimate a current market price.  Obviously a limit order can restrict how much funds are used, but at the risk of it not executing at all.

I dug through through codebase identifying where quantity and funds could be made optional arguments (where an order is rejected if neither exists), but it appears quite a bit relies on quantity not being zero (including several checks).

Am I correct in this assessment, or am I missing another manner in which to set the amount of funds to spend vs quantity for a market order on brokerages that support that mechanism?

The engine is pretty impressive, and I don't mean for this to be any kind of takeaway - merely just double checking.  Also, this is really just a technical question.  I'll leave the implications of using market orders (either method above or even at all) to each responsible individual.

Thanks, and great job on the engine :-)

Update Backtest








Just in case, as a stop gap, a possible workaround that can be placed per brokerage is the addition of a new property in the appropriate exchange's IOrderProperties class that would swap quantity to funds before placing the order (in exchanges that support that behavior).  Logic in tyhe appropriate Brokerage would place the order accordingly.

The downside of this is the quantity in the Order would not represent the actual quantity of the holding with regards to the engine/analysis.

0

Thank you Kevin - great analysis and you're right thats the appropriate solution given current demands. If we find later there are at least 2 other brokerages with fund-based ordering we can extend the base order class / LEAN foundation to support fund-based ordering. 

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Thanks for the comment Jared. 

I'm testing out some changes, and once I come up with some stable solutions I'll post something up on the github repo for people to look at.  I'm able to keep most of the changes to the GDAX brokerage namespace without affecting any other brokerages.  There may be an issue with the manner in which it calculates fees for each fill (since that uses the original order quantity), but everything else appears doable.  Of course, any analysis tools that use the original quantity of the order would not operate properly.

Thanks for the answer I was looking for.  I just wanted to be sure there wasn't a manner of doing so that I was missing. 

 

thanks,

  -=[Kevin]=-

0

The fees might be "close enough" using a calculated quantity.
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed