diff --git a/README.md b/README.md index b657918..d9b089e 100644 --- a/README.md +++ b/README.md @@ -119,9 +119,9 @@ exchange = cira.Exchange() qty = 1 # choose how many stocks should be handled in one session while True: while exchange.is_open: - for stock in random.choices(exchange.stocks, k=qty): + for stock in random.choices(exchange.get_all_stocks(), k=qty): stock.buy(1) - for stock in random.choices(portfolio.owned_stocks, k=qty): + for stock in random.choices(portfolio.owned_stocks(), k=qty): stock.sell(1) time.sleep(60*30) # 30 min timer ``` diff --git a/cira/exchange.py b/cira/exchange.py index a466a2c..1d65c5f 100644 --- a/cira/exchange.py +++ b/cira/exchange.py @@ -11,6 +11,7 @@ from alpaca.data import CryptoHistoricalDataClient, StockHistoricalDataClient from alpaca.trading.enums import AssetClass from alpaca.trading.models import Clock +from .asset_stock import Stock import alpaca import warnings import datetime @@ -21,7 +22,7 @@ def __init__(self) -> None: APCA_ID, APCA_SECRET = auth.get_api_keys() self.alpc_client = TradingClient(APCA_ID, APCA_SECRET) self.alpc_historical = StockHistoricalDataClient(APCA_ID, APCA_SECRET) - self.stock_cache: List[asset.Stock] = [] + self.stock_cache: List[Stock] = [] def is_open(self) -> bool: """Checks if the exchange is open and able to trade""" @@ -35,7 +36,7 @@ def to_assets(self, symbols: List[str]) -> List[asset.Asset]: def to_asset(self, symbol: str) -> asset.Asset: """Takes a symbols and returns it as a cira Assets objects""" - return asset.Stock(symbol) + return Stock(symbol) def get_all_stocks( self, is_tradeable: bool = True, force_reload: bool = False @@ -47,7 +48,7 @@ def get_all_stocks( search_params = GetAssetsRequest(asset_class=AssetClass.US_EQUITY) alpc_assets = self.alpc_client.get_all_assets(search_params) self.stock_cache = [ - asset.Stock(a.symbol) for a in alpc_assets if a.tradable == is_tradeable + Stock(a.symbol) for a in alpc_assets if a.tradable == is_tradeable ] return self.stock_cache