Skip to content

Commit

Permalink
feat: add methods to get schwab net worth and cash to buy stocks and …
Browse files Browse the repository at this point in the history
…options
  • Loading branch information
daneisburgh committed Feb 4, 2024
1 parent cf56534 commit 223bc08
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions invaas/schwab/schwab_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ async def setup_api(self):
await self.schwab_api.setup()
await self.schwab_api.login(username=username, password=password)
await self.schwab_api.close_api_session()
self.logger.info(f"Net worth: {self.__get_net_worth()}")
self.logger.info(f"Available cash to buy stocks: {self.__get_available_cash_to_buy_stocks()}")
self.logger.info(f"Available cash to buy options: {self.__get_available_cash_to_buy_options()}")

def __get_fear_greed_index_data(self):
historical_periods = 14
Expand Down Expand Up @@ -147,9 +150,15 @@ def __sell_product(self, product_id: str, asset_class: str, quantity: float):
if not success:
raise Exception(f"Error selling {product_id}: {str(messages)}")

def __get_available_cash(self):
def __get_net_worth(self):
return self.schwab_api.get_balance_positions()["balanceDetails"]["availableToTradeBalances"]["netWorth"]

def __get_available_cash_to_buy_stocks(self):
return self.schwab_api.get_balance_positions()["balanceDetails"]["availableToTradeBalances"]["cash"]

def __get_available_cash_to_buy_options(self):
return self.schwab_api.get_balance_positions()["balanceDetails"]["optionsBalances"]["longOptions"]

def create_options_orders(self):
ticker = "SPY"
self.logger.info(f"Trading options for {ticker}")
Expand Down Expand Up @@ -233,9 +242,7 @@ def get_sell_dte(owned_option, current_dte, expire_date, transaction_history):

time.sleep(10)

available_cash = self.__get_available_cash()
self.logger.info(f"Available cash: {available_cash}")

available_cash = self.__get_available_cash_to_buy_options()
df_options_chain = self.__get_df_options_chain(ticker=ticker)
owned_call_options, owned_put_options = self.__get_owned_options()

Expand Down

0 comments on commit 223bc08

Please sign in to comment.