nautechsystems / nautilus_trader

A high-performance algorithmic trading platform and event-driven backtester
https://nautilustrader.io
GNU Lesser General Public License v3.0
2.02k stars 461 forks source link

Make price in increments #1026

Open rsmb7z opened 1 year ago

rsmb7z commented 1 year ago

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

limx0 commented 1 year ago

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

rsmb7z commented 1 year ago

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

rsmb7z commented 1 year ago

Hi @limx0 Can you please register following tick schemas.

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.

limx0 commented 1 year ago

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.