Untitled

mail@pastecode.io avatar
unknown
python
a year ago
436 B
1
Indexable
Never
def order_target_amount(account: Account, dt: datetime.date,
                        ticker: str, target_amount: int) -> Optional[Order]:
    positions = {asset_position.ticker: asset_position.position for asset_position in account.portfolio}
    position = positions.get(ticker, 0)
    amount = target_amount - position
    if amount != 0:
        return Order(dt=dt, ticker=ticker, amount=amount)
    else:
        return None