itsjafer / schwab-api

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

`get_account_info_v2` KeyError: costDetail #31

Closed NelsonDane closed 8 months ago

NelsonDane commented 8 months ago

When getting account info using get_account_info_v2, sometimes the returned stock info has no costDetail fields (for example, the stock NXU for some reason). This causes an error when trying to build the position object.

For example, this is the position data for NXU when printed: { "quantity": 1, "quantityBeforeSplit": 1, "marginRequirement": 0, "percentageOfAccount": 0.63, "symbolDetail": { "symbol": "NXU", "cusip": "62956D204", "description": "NXU INC CLASS A", "quoteSymbol": "NXU", "defaultSymbol": "NXU", "schwabSecurityId": 95217935, "underlyingSchwabSecurityId": 0, "isLink": True, "isMarginable": True, "securityGroupCode": "COMNEQTY", "ruleSetSuffix": 0, "accountingRuleCode": 1, "positionType": 0, "securityType": 1, "symbolForDetailedQuotes": "NXU", }, "priceDetail": { "price": 2.66, "priceChange": 0, "priceChangePercent": 0, "priceDate": "12/28/2023", "isPriceRealTime": True, "marketValue": 2.66, "dayChange": 0, "dayChangePercent": 0, }, "reinvestDetail": {}, "marginDetail": { "pegAmount": 0, "nakedQuantity": 0, "nakedRequirementAmount": 0, "spreadQuantity": 0, "spreadRequirementAmount": 0, "strangleQuantity": 0, "strangleRequirementAmount": 0, "coverQuantity": 0, }, }

Which causes the below error:

Screenshot 2023-12-28 at 6 48 21 PM

This isn't happening with every stock, but if an account holds the problematic stock then it crashes

itsjafer commented 8 months ago

The latest version should address this, but please feel free to make a PR or re-open this issue if it's not working as expected