def test_position_is_open(): p = Position(exchanges.SANDBOX, 'BTC-USD', { 'entry_price': 50, 'current_price': 60, 'qty': 2, }) assert p.is_open is True p.qty = 0 assert p.is_open is False
def test_position_is_close(): p = Position(exchanges.SANDBOX, 'BTC-USD', { 'entry_price': 50, 'current_price': 60, 'qty': 0, }) assert p.is_close is True p.qty = 2 assert p.is_close is False
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