itsjafer / schwab-api

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

order confirmation to buy or sell a symbol that's traded before today #43

Closed john8988 closed 6 months ago

john8988 commented 7 months ago

The order confirmation doesn't work if I place an order to buy, say AAPL again the second time. It produces this message in the order verification

'Please Note: This account shows trading activity today for %SYMBOL%. Please ' 'review Order Status to prevent a duplication of orders. (OE254)']

The order_confirmation produced this response: {'Messages': [{'ApplicationCode': 'DO', 'Id': 309, 'ShortName': 'DO0309', 'SequenceNumber': 0, 'TypeCode': 4, 'OccuranceNumber': 0, 'SubstitutionParam1': 'Tradability', 'SubstitutionParam2': '', 'Message': 'Order Affirmation required. (DO309)'}], 'MessageCounts': {'BusinessReject': 1}, 'ReturnCode': 4, 'EtfMsgCode': ''}

Somehow, I believe url.order_confirmation has to be modified in schwab.py.

Edit: I also tested trade_v2: if you have held some stocks, say, USFR, in your account and you are trying to issue a new market order to buy more, it'll result in the following verification message (unsuccessful):

Placing a market order trade for USFR stock unsuccessful The order verification produced the following messages: ['Your dividend instructions for this order differ from those of your existing ' 'position in this security. Placing this order will change existing ' 'instructions from "Yes" to "No" for your position - even if this order does ' 'not fill. (OE585)', 'This account currently holds 40 shares of USFR. (AC109)', 'You are purchasing an Exchange Traded Fund which tracks an index, a ' 'commodity or a basket of assets, but trades like a stock on an exchange. ' 'Please read the prospectus carefully before investing. (DO856)', '*It is your responsibility to choose the cost basis method appropriate to ' 'your tax situation. Failure to select the proper cost basis method may cause ' 'you to pay more tax than necessary. Schwab does not provide tax advice and ' 'encourages you to consult with your tax professional. View <A ' 'href="javascript:open(\'https://client.schwab.com/secure/cc/help/trade/stocks/tradestocks_verification?cmsid=P-2522495&lvl1=help&lvl2=trade#cost_basis\',682,520,\'YES\')">Cost ' 'Basis Reporting for additional information on <A ' 'href="javascript:open(\'https://client.schwab.com/secure/cc/help/trade/stocks/tradestocks_verification?cmsid=P-2522495&lvl1=help&lvl2=trade#cost_basis\',682,520,\'YES\')">cost ' 'basis method choices and how Schwab reports adjusted cost basis ' 'information to the IRS. (OE917)', 'Quote at the time of order verification: $50.25 Ask']

itsjafer commented 6 months ago

Hi, you likely need to pass in affirm_order=True to the trade_v2 function to get past this. Could you give that a try?