itsjafer / schwab-api

A python library for placing trades on Charles Schwab
MIT License
201 stars 64 forks source link

Can't place order - This account currently holds %1% shares of %SYMBOL%. (AC109) #17

Closed gyias closed 8 months ago

gyias commented 10 months ago

I've been getting this error message when placing orders recently.

'message not found', 'This account currently holds %1% shares of %SYMBOL%. (AC109)'

I tried logging the responses, and the above message seemed to be coming from the verification response.

The confirmation response looked like this:

{'Messages': [{'ApplicationCode': 'DO', 'Id': 9008, 'ShortName': '', 'SequenceNumber': 0, 'TypeCode': 4, 'OccuranceNumber': 0, 'SubstitutionParam1': 'OrderId', 'SubstitutionParam2': '0', 'Message': 'STOP: A problem was detected which may have affected your order placement. <B>Please check the Order Status screen to confirm that your order has been received.</B> If your order appears, the transaction was successful. If you do not see your trade, please contact customer support for assistance.  (DO9008)'}], 'MessageCounts': {'BusinessReject': 1}, 'ReturnCode': 4, 'EtfMsgCode': ''}

I checked the order status just in case, but there were no orders placed.

gyias commented 10 months ago

It seems that this only happens to the accounts that were originally opened with TD Ameritrade and have been migrated to Schwab recently. I can place orders without issues on my other Schwab account that was opened with Schwab.

Is there anyway I can debug this from my end? I'd really love to keep using this API to automate my trading.

itsjafer commented 9 months ago

It's difficult for me to debug this, because I don't have a TD ameritrade-opened account

gyias commented 9 months ago

Is there any way I can help you debug? Like posting sample request and response bodies?

Or I can try to fix it myself if you let me know how you usually handle this kind of problem. I don't even know where to start looking, but with some help, I may be able to debug it. I write programs for a living.

itsjafer commented 9 months ago

Quick update, I reverse engineered the "new" API for trading by persisting the authentication token obtained through playwright. I don't actively trade on Schwab anymore so I'll have to move some money in and test it over the next few days, but I'm optimistic this will solve the issue (and perhaps make the debugging process less opaque for anyone who wants to contribute in the future)

gyias commented 9 months ago

Awesome! Looking forward to the fix. Thank you so much!

itsjafer commented 9 months ago

Hi @gyias, I just pushed version 0.3.0, which features a trade_v2 function using the new API. I haven't fully tested it (which is why it's not a replacement of the old trade function), but I did get it to place orders on my regular Schwab brokerage account.

Could you try it out and let me know if it solves your problem?

gyias commented 9 months ago

Sure, will do. Thanks a lot!

gyias commented 9 months ago

Looking good so far. :) The orders didn't go through because the market was closed, but they appeared as pending orders. I'll try to make a real order tomorrow and report back. Thanks!

itsjafer commented 9 months ago

I was able to test buying but not selling, so I suspect selling might be a problem. Glad to hear the orders went through though, keep me posted!

gyias commented 8 months ago

Confirming both buy and sell orders can be placed and filled without any issue now. Thank you very much!


BTW, the new API supports MOC (Market on close) orders. In case other users of this library want to take advantage of the new order type, the order type number is 53. It might be a good idea to add an order type parameter to the new API? Probably with a default value of "49" for the backward compatibility?

Thanks again for creating this super helpful API and addressing this issue! With the repeated delays of the official Schwab API launch, this is literally a life saver for those like me who were using the TDA API but were forced to migrate to Schwab.