kieran-mackle / AutoTrader

A Python-based development platform for automated trading systems - from backtesting to optimisation to livetrading.
https://kieran-mackle.github.io/AutoTrader/
GNU General Public License v3.0
937 stars 216 forks source link

Add Support for Partially and Canceled order callback functions #106

Open Crypto7816 opened 3 months ago

Crypto7816 commented 3 months ago

Is your feature request related to a problem? Please describe. A trading robot requires functionality to manage order statuses effectively. Specifically, there is a need for callback functions that can respond to changes in order status, such as identifying orders that are partially filled, fully filled, or canceled.

Describe the solution you'd like To address this, I propose the implementation of specific callback functions within the trading robot's framework. For instance, when an order is partially filled, the def on_partially_filled_order() function would be triggered. Similarly, if an order is canceled, the def on_canceled_order() should be called. We can refer to the Lumibot framework for implementation.

Simple Framework demo

async def watch_order_loop(exchange: ccxt.pro.Exchange, symbol: str):
    your_delay = 1
    await exchange.throttle(your_delay)
    while True:
        try:
            orders = await exchange.watch_orders(symbol)
            for order in orders:
                if order['status'] == 'open' and order['filled'] == 0:
                    print('---------------------------Open Order NEW---------------------------')
                    # strategy.on_new_order(order)
                elif order['status'] == 'open' and order['filled'] == 0:
                    print('---------------------------Open Order PARTIALLY FILLED---------------------------')
                    # strategy.on_partially_filled_order(order)
                elif order['status'] == 'closed':
                    print('---------------------------Close Order---------------------------')
                    # strategy.on_close_order(order)
                elif order['status'] == 'canceled':
                    print('---------------------------Cancel Order---------------------------')
                   # strategy.on_cancel_order(order)
            # print(exchange.iso8601(exchange.milliseconds()), 'watch_orders_loop', len(orders), ' last orders cached')
            print('---------------------------------------------------------------')
        except Exception as e:
            # break
            print(e)