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 :-)