schwab-api icon indicating copy to clipboard operation
schwab-api copied to clipboard

Limit Orders/Stop-loss Support?

Open davidkrum opened this issue 2 years ago • 1 comments

This project is great! Was wondering if there is any plan to add support for limit orders and stop-loss settings. Unless I am missing something, I only see the the possibility of placing market orders.

davidkrum avatar Aug 18 '22 13:08 davidkrum

Hi David, there’s no active plans to implement any new features, though I’d be happy to review and approve pull requests from others!

itsjafer avatar Aug 18 '22 16:08 itsjafer

I don't think this would be hard to do, but it would help us save time if you gave us a clue how you obtained those api urls.

I don't see them used anywhere else, that I can see. I haven't been able to find them in either the web source code or by capturing the mobile app traffic.

alexandercommon avatar Sep 21 '23 13:09 alexandercommon

I am also very curious where these urls came from. It would help so much to be able to see some requests for different scenarios.

I figured out how to enter limit orders with some trial and error, but they fail if the limit is marketable (i.e. above ask for buy and below bid for sell). In the web interface, if the limit is marketable, it asks for a confirmation to be sure that's what you intended, so I presume the api also needs some verification key:value in the post to urls.order_confirmation(). I've tried a few things similar to the key:value that is passed in the browser trade interface ("OrderAffrmIn": True), but no luck.

Trades also fail if confirmation is needed for other reasons. For example, commodity related products (even basic ETFs like GLDM) require acknowledgement of the risks and therefore cannot be purchased with this package.

WinesProof avatar Nov 02 '23 18:11 WinesProof

From what I recall, the APIs that I call in this library were publicly available through sniffing network requests on the website. If these requests are no longer visible, my guess is that Schwab stopped using these APIs on the client-side web app (even though the APIs remain functional).

I don't quite have as much time anymore to work on this, but I imagine there must be some API that's being called on the website, even if its a new URL.

itsjafer avatar Nov 02 '23 19:11 itsjafer

Thanks for responding Jafer

The current web interface appears to be using ausgateway.schwab.com instead of client.schwab.com, and the requests look very different. I've tried replicating those requests, but haven't gotten anywhere (I'm remembering that everything was rejected by the server).

I was hoping you knew of some older url that was still accessible from a browser for entering orders with client.schwab.com, but thanks for clarifying that's not the case.

WinesProof avatar Nov 02 '23 19:11 WinesProof

An update on this, I've managed to replicate the "new" requests and get past authorization errors. At a cursory glance, I believe adding this feature support would be straightforward and I'll do my best to document the API request/response so that you all can contribute features going forward!

itsjafer avatar Dec 09 '23 08:12 itsjafer

Excellent! I look forward to seeing that, even if you only implement a few things. Assuming we just need to replicate what the web interface does, I should be able to add more to it.

WinesProof avatar Dec 12 '23 17:12 WinesProof

Hi! I pushed version 0.3.0, which features a trade_v2() function. For now, I've hard coded it as a day only market order, but if you take a look, it is very simple to add limit orders and stop loss.

Please feel free to send me a PR to add the functionality if you're open to testing it!

itsjafer avatar Dec 13 '23 05:12 itsjafer

Quick update, version 0.3.2 has Limit order and Stop loss order support, but will still require some investigation on your part to figure out the Schwab enum code mappings.

itsjafer avatar Dec 13 '23 21:12 itsjafer