def test_position_roi(): set_up() p = Position(exchanges.SANDBOX, 'BTC-USDT') p._open(3, 100) p.current_price = 110 assert p.value == 330 assert p.total_cost == 300 assert p.roi == 10
def test_position_pnl_percentage(): p = Position(exchanges.SANDBOX, 'BTC-USD', { 'entry_price': 50, 'current_price': 60, 'qty': 2, }) # long position assert p.pnl_percentage == 20 p.current_price -= 20 assert p.pnl_percentage == -20 # short position p.entry_price = 50 p.qty = -2 p.current_price = 40 assert p.pnl_percentage == 20