Skip to content

Commit

Permalink
fixed a miss from refactor from v2-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
AxelGard committed Jun 13, 2024
1 parent 72e94d7 commit c154fec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
7 changes: 4 additions & 3 deletions cira/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"""
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit c154fec

Please sign in to comment.