dchrostowski / investopedia_simulator_api

A simple Python API for Investopedia's stock simulator games. This programmatically logs into Investopedia and can retrieve portfolio summary, get stock quotes & option chain lookups, execute trades - buy & sell shares, puts, calls, sell short, etc.
MIT License
33 stars 12 forks source link

Cancelling an order #23

Closed musicderp closed 3 years ago

musicderp commented 3 years ago

Is there any way to cancel an order through this api once it has been placed? For example, because of the delay on orders going through, some of them I may want to cancel because the price is too high

dchrostowski commented 3 years ago

It's been a while since I worked on this - but I don't think there are any methods for cancelling a trade. I'll add that as a feature request and hopefully have it done shortly.

dchrostowski commented 3 years ago

So there is a way to cancel orders. I just didn't document this very well. client.open_orders will give you an array of OpenOrder objects which are pending trades. Here's an example where I cancel all of my pending trades

open_orders = client.open_orders
for order in open_orders:
    # print the order details
    print(order.__dict__)
    # cancel it
    order.cancel()
# Refresh the portfolio
client.refresh_portfolio()
# Should return an empty array
print(client.open_orders)

I'll be working on documenting this better.

dchrostowski commented 3 years ago

Reopening issue because the refresh_portfolio() method is broken. Will close once I merge the fix in.