Esempio n. 1
0
def test_order_filled_volume(fx_buy_order: Order, fx_session: Session):
    fx_buy_order.volume = decimal.Decimal('2000')
    fx_buy_order.remaining_volume = decimal.Decimal('1000')

    assert fx_buy_order.filled_volume == decimal.Decimal('1000')
    assert fx_session.query(Order.filled_volume).filter(
        Order.id == fx_buy_order.id, ).scalar() == decimal.Decimal('1000')
Esempio n. 2
0
def test_order_remaining_locked_amount(
    fx_buy_order: Order,
    fx_sell_order: Order,
    fx_session: Session,
):
    fx_buy_order.volume = decimal.Decimal('200')
    fx_buy_order.remaining_volume = decimal.Decimal('100')
    fx_sell_order.volume = decimal.Decimal('300')
    fx_sell_order.remaining_volume = decimal.Decimal('150')

    assert fx_buy_order.remaining_locked_amount == decimal.Decimal('900000')
    assert fx_sell_order.remaining_locked_amount == decimal.Decimal('150')

    assert fx_session.query(Order.remaining_locked_amount).filter(
        Order.id == fx_buy_order.id, ).scalar() == decimal.Decimal('900000')
    assert fx_session.query(Order.remaining_locked_amount).filter(
        Order.id == fx_sell_order.id, ).scalar() == decimal.Decimal('150')
Esempio n. 3
0
def test_order_check_constraints(
    fx_buy_order: Order,
    fx_session: Session,
    fx_utcnow: datetime.datetime,
):
    fx_session.begin_nested()
    fx_buy_order.price = decimal.Decimal('0')
    with raises(IntegrityError) as e:
        fx_session.flush()
    assert 'ck_order_price_positive' in str(e.value)
    fx_session.rollback()

    fx_session.begin_nested()
    fx_buy_order.volume = decimal.Decimal('0')
    with raises(IntegrityError) as e:
        fx_session.flush()
    assert 'ck_order_volume' in str(e.value)
    fx_session.rollback()

    fx_session.begin_nested()
    fx_buy_order.remaining_volume = decimal.Decimal('-1')
    with raises(IntegrityError) as e:
        fx_session.flush()
    assert 'violates check constraint' in str(e.value)
    fx_session.rollback()

    fx_session.begin_nested()
    fx_buy_order.volume = decimal.Decimal('100')
    fx_buy_order.remaining_volume = decimal.Decimal('101')
    with raises(IntegrityError) as e:
        fx_session.flush()
    assert 'ck_order_volume' in str(e.value)
    fx_session.rollback()

    fx_session.begin_nested()
    fx_buy_order.pair = 'BTC/BTC'
    with raises(IntegrityError) as e:
        fx_session.flush()
    assert 'ck_order_currency' in str(e.value)
    fx_session.rollback()

    fx_session.begin_nested()
    fx_buy_order.remaining_volume = decimal.Decimal('0')
    fx_buy_order.filled_at = None
    with raises(IntegrityError) as e:
        fx_session.flush()
    assert 'ck_order_filled' in str(e.value)
    fx_session.rollback()

    fx_session.begin_nested()
    fx_buy_order.remaining_volume = decimal.Decimal('1')
    fx_buy_order.filled_at = fx_utcnow
    with raises(IntegrityError) as e:
        fx_session.flush()
    assert 'ck_order_filled' in str(e.value)
    fx_session.rollback()

    fx_session.begin_nested()
    fx_buy_order.remaining_volume = decimal.Decimal('0')
    fx_buy_order.cancel()
    with raises(IntegrityError) as e:
        fx_session.flush()
    assert 'ck_order_canceled' in str(e.value)
    fx_session.rollback()