nautechsystems / nautilus_trader

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

Implement submit multiple orders for Binance #1198

Open objectin opened 11 months ago

objectin commented 11 months ago

Feature Request

Description

Implement the functionality to support multiple orders execution for Binance as per their official API documentation:

Requirements

1. Placing Multiple Orders (TRADE)

2. Modifying Multiple Orders (TRADE)

cjdsellers commented 10 months ago

This issue is now being actively worked on. We're introducing enhancements to how orders are handled in the system, particularly focusing on batch commands. Here's a rundown of the changes and new features being implemented.

Batch submit The placing of multiple orders can be handled by the existing submit_order_list / OrderList (just needs implementing as such in the Binance client).

Batch modify and cancel A new batch_more flag is being added to modify_order and cancel_order (default False to retain current behavior). This will control whether subsequent calls are batched into BatchModifyOrders and BatchCancelOrders commands respectively.

Intended behavior is described in the initial version of the docstrings:

Excerpt from docstring:

        batch_more : bool, default False
            Indicates if this command should be batched (grouped) with subsequent modify order
            commands for the venue. When set to `True`, we expect more calls to `modify_order`
            which will add to the current batch. Final processing of the batch occurs on a call
            with `batch_more=False`. For proper behavior, maintain the correct call sequence.

        Warnings
        --------
        The `batch_more` flag is an advanced feature which may have unintended consequences if not
        called in the correct sequence. If a series of `batch_more=True` calls are not followed by
        a `batch_more=False`, then no command will be sent from the strategy.

@objectin any thoughts/feedback on the above?

objectin commented 10 months ago

Seems nice, it will extremely helpful for handling multiple orders in a batch. And also for ratelimit problems when handling a bunch of orders.

cjdsellers commented 9 months ago

So I decided to go a different way for the case of the batch cancel, simply call this from the strategy now (passing a list of orders):

self.cancel_orders(orders)

This will create a BatchCancelOrders command under the hood and send it to the ExecutionEngine.

Now implemented for backtesting and Binance Futures on develop branch. Tests OK for me live on the Binance Futures testnet, please let me know how it goes when you get a chance.

cjdsellers commented 9 months ago

Next up I'll implement the batch modify, which will probably follow the API which was first proposed ^.

cjdsellers commented 8 months ago

The batch modify involves larger changes to the core platform -- moving this to the backlog for now.