Skip to content

Setting up cancel order as a child order #27

@brw59

Description

@brw59

I am looking to do this, but I don't know if it is possible.

  1. build a buy order with a stop
  2. create a sell order higher than being bought with the stop order
  3. attach a child cancel order to the sell order ... The idea here is to auto cancel the 'stop' part of the stop order if the 'sell' order goes through first
  4. attach a child cancel order to the buy stop order ... similarly, the idea is to cancel the 'sell' order if the stop was executed due to the price dropping

Here's what I came up with so far, but it won't work because the 'cancel_order' doesn't return an 'order' object, it just executes. Is there a way to make this happen?

    stop_build_order = execute.SimpleOrderBuilder.Equity.Stop.Build(stock, quantity, True, True, stop_price)
    sell_order = execute.SimpleOrderBuilder.Equity.Build(stock, quantity, False, False, sell_price)

    ################
    # can I do this? --- no this won't work because cancel_order either returns 'true' or throws, it doesn't return an order object
    cancel_stop_order = execute.cancel_order(creds, account_id, stop_builder_oid)
    sell_order.add_child(cancel_stop_order)

    cancel_sell_order = execute.cancel_order(creds, account_id, sell_oid)
    stop_build_order.add_child(cancel_sell_order)
    ###############

    stop_builder_oid = execute.send_order(creds, account_id, stop_build_order)
    sell_oid = execute.send_order(creds, account_id, sell_order)

Note: I do realize that I have to run the 'send_order' of the 'sell' or 'stop_builder' first in order to obtain the oid used in the 'cancel_order', but I don't think this would be the case if there was a way to build the cancel order before executing it. Or at the very least, I'd have the choice to choose 1 to tie to the other (opposed to tying them both to each other)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions