예제 #1
0
파일: main.py 프로젝트: MioNok/Stock-algo
def get_active_trades(apis):
    current_positions = apis.alpacaApi.list_positions()
    active_trades = []
    
    for pos in current_positions:
        #Currently "buy" is lingo for long, and "sell" is lingo for short.
        #This makes creating and flatteing orders easier.
        #Unfortunately the api does not currently allow shorts but it is ready here when it come available.
        side = "buy" if pos.side == "long" else "sell"
        
        old_trade = Trade(ticker = pos.symbol,
                          posSize = pos.qty,
                          orderSide = side,
                          timeStamp = "old",
                          strategy = "unknown")

                          
        #TODO move these to the model
        old_trade.entryPrice = pos.avg_entry_price
        old_trade.unrealPL = pos.unrealized_pl
        
        active_trades.append(old_trade)
    
    return active_trades