blankly icon indicating copy to clipboard operation
blankly copied to clipboard

Closing orders by id

Open SamTov opened this issue 9 months ago • 2 comments

I want to be able to close an order by an id, something like this:

def close_position_by_id(symbol, order_id, state):
    print(f"Before: {state.interface.paper_trade_orders}")
    print(order_id)
    print(symbol)
    state.interface.cancel_order(symbol, str(order_id))
    print(f"After: {state.interface.paper_trade_orders}")

Where before should be my standard list of open orders and after should be empty if I only have one active order. While this exists for pending orders, I don't see how I can deliberately close a done order in Blankly. I can open a sell position and by default, reduce the amount of money I have in an instrument, but those two things aren't the same. One can think of opening a buy and sell position simultaneously. Not saying it is a great idea, but it is surely something I should be able to do in a backtesting framework. Is this already possible within blankly?

SamTov avatar May 20 '24 17:05 SamTov