itsjafer / schwab-api

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

Shorting? #61

Open mboop127 opened 2 months ago

mboop127 commented 2 months ago

Hello - I see there is support for shorting in the API itself, but I cannot see any information on how to short here. Is it possible?

mboop127 commented 2 months ago

I was able to resolve by adding "BuyToCover" and "SellShort" under tradev2's instruction parser.

itsjafer commented 2 months ago

Hi @mboop127, if the changes are straightforward, I'd love for you to create a pull request!

mboop127 commented 2 months ago

Frustratingly it is not longer working, I am unsure why. Below is the code I changed in TradeV2; perhaps @itsjafer you could explain why you use integers rather than the instruction codes listed in the documentation, and where I might find the integer codes? Flailing, but hoping that could be the explanation.

    if side == "Buy":
        buySellCode = "BUY"
    elif side == "Sell":
        buySellCode = "SELL"
    elif side == "Short":
        buySellCode = "SELL_SHORT"
    elif side == "Cover":
        buySellCode = "BUY_TO_COVER"
    else:
        raise Exception("side must be either Buy or Sell or short, see instruction type on dev portal")