nautilus_trader icon indicating copy to clipboard operation
nautilus_trader copied to clipboard

Make price in increments

Open rsmb7z opened this issue 2 years ago • 4 comments

Feature Request

There are situation where Exchange have requirement for the Order price to be in increments (as per instrument) even though the Tick, Bar etc prices may not be in increments that increments. So in such situations Order will be rejected. It would be good to add helper function something like below in Instrument base class to allow use of this instead of make_price when placing Order.

def make_price_increment(instrument: Instrument, value: float) -> Price:
    return instrument.make_price(
        instrument.price_increment.as_double() * round(value / instrument.price_increment.as_double())
    )

For instance for InteractiveBrokers EUR/USD price_precision=5 and price_increment=0..00005

  • Input: 1.05522 > Expected: Price('1.05520')
  • Input: 1.05528 > Expected: Price('1.05530')

rsmb7z avatar Feb 25 '23 06:02 rsmb7z

Hey @rsmb7z, I agree we should have some helper functions like this.

I started working on something like this here

https://github.com/nautechsystems/nautilus_trader/blob/master/nautilus_trader/model/tick_scheme/implementations/tiered.pyx

It looks like we did start to implement this for Forex pairs, so if you pass a tick scheme name when creating the instrument you can use instrument.tick_scheme.next_ask_price

limx0 avatar Feb 25 '23 06:02 limx0

Sounds goods. I will check for other securites how we can take advantage of this and register more schemas.

rsmb7z avatar Feb 25 '23 07:02 rsmb7z

Hi @limx0 Can you please register following tick schemas.

  • {'marketRuleId': 67, 'priceIncrements': [{LowEdge: 0, Increment: 0.25}]} << CME Futures
  • {'marketRuleId': 109, 'priceIncrements': [{LowEdge: 0, Increment: 0.01}, {LowEdge: 3, Increment: 0.05}]} << Options
  • {'marketRuleId': 633, 'priceIncrements': [{LowEdge: 0, Increment: 0.0001}]} << CME Forex
  • {'marketRuleId': 26, 'priceIncrements': [{LowEdge: 0, Increment: 0.01}]} << Mostly Stocks, Options (some exchanges), Futures

Just FYI to give up the additional possible scenario, these marketRuleId are dependent on Exchange and not with instrument though available in ContractDetails under validExchanges and marketRuleIds. For example one Option which may have multiple ValidExchanges for trading, may have rule Id 26 for one exchange and 109 for other which would apply to the relevant exchanges when placing the order.

rsmb7z avatar Feb 27 '23 21:02 rsmb7z

Hey @rsmb7z, sure thing! Thanks for doing some research here. I have a couple of questions I sent through to you on discord in the IB channel.

limx0 avatar Feb 27 '23 21:02 limx0