Skip to content

Closing orders by id #259

@SamTov

Description

@SamTov

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions