Exemplo n.º 1
0
def test_call_with_sell_order(mock_order_class, mock_exchange_class):

    exchange = mock_exchange_class.return_value
    exchange.quote_price.return_value = 7000.00

    order = mock_order_class.return_value
    order.pair = USD / BTC
    order.side = TradeSide.SELL

    criteria = Limit(limit_price=6800.00)
    assert criteria(order, exchange)

    criteria = Limit(limit_price=7000.00)
    assert criteria(order, exchange)

    criteria = Limit(limit_price=7200.00)
    assert not criteria(order, exchange)
Exemplo n.º 2
0
def test_and(mock_order_class, mock_exchange_class):

    # Test initialization
    criteria = Limit(limit_price=7000.00) & Timed(duration=5)
    assert criteria
    assert isinstance(criteria, Criteria)

    order = mock_order_class.return_value
    order.pair = USD / BTC
    order.created_at = 0

    exchange = mock_exchange_class.return_value

    # Test (limit=True, timed=True) ===> True
    order.clock.step = 3

    order.side = TradeSide.BUY
    exchange.quote_price = mock.Mock(return_value=6800.00)
    assert criteria(order, exchange)

    order.side = TradeSide.SELL
    exchange.quote_price = mock.Mock(return_value=7200.00)
    assert criteria(order, exchange)

    # Test (limit=True, timed=False) ===> False
    order.clock.step = 8

    order.side = TradeSide.BUY
    exchange.quote_price = mock.Mock(return_value=6800.00)
    assert not criteria(order, exchange)

    order.side = TradeSide.SELL
    exchange.quote_price = mock.Mock(return_value=7200.00)
    assert not criteria(order, exchange)

    # Test (limit=False, timed=True) ===> False
    order.clock.step = 3

    order.side = TradeSide.BUY
    exchange.quote_price = mock.Mock(return_value=7200.00)
    assert not criteria(order, exchange)

    order.side = TradeSide.SELL
    exchange.quote_price = mock.Mock(return_value=6800.00)
    assert not criteria(order, exchange)

    # Test (limit=False, timed=False) ===> False
    order.clock.step = 8

    order.side = TradeSide.BUY
    exchange.quote_price = mock.Mock(return_value=7200.00)
    assert not criteria(order, exchange)

    order.side = TradeSide.SELL
    exchange.quote_price = mock.Mock(return_value=6800.00)
    assert not criteria(order, exchange)
Exemplo n.º 3
0
def hidden_limit_order(step: int, side: 'TradeSide', pair: 'TradingPair',
                       price: float, size: float, portfolio: 'Portfolio'):

    order = Order(step=step,
                  side=side,
                  trade_type=TradeType.MARKET,
                  pair=pair,
                  price=price,
                  quantity=(size * pair.base),
                  portfolio=portfolio,
                  criteria=Limit(limit_price=price))

    return order
Exemplo n.º 4
0
def hidden_limit_order(step: int,
                       side: 'TradeSide',
                       pair: 'TradingPair',
                       price: float,
                       size: float,
                       portfolio: 'Portfolio',
                       ttl_in_seconds: int = None,
                       ttl_in_steps: int = None):
    instrument = pair.base if side == TradeSide.BUY else pair.quote
    order = Order(step=step,
                  side=side,
                  trade_type=TradeType.MARKET,
                  pair=pair,
                  price=price,
                  quantity=(size * instrument),
                  ttl_in_seconds=ttl_in_seconds,
                  ttl_in_steps=ttl_in_steps,
                  portfolio=portfolio,
                  criteria=Limit(limit_price=price))

    return order
Exemplo n.º 5
0
def hidden_limit_order(step: int,
                       side: 'TradeSide',
                       pair: 'TradingPair',
                       price: float,
                       size: float,
                       portfolio: 'Portfolio',
                       start: int = None,
                       end: int = None):
    instrument = side.instrument(pair)
    order = Order(step=step,
                  side=side,
                  trade_type=TradeType.MARKET,
                  pair=pair,
                  price=price,
                  quantity=(size * instrument),
                  start=start,
                  end=end,
                  portfolio=portfolio,
                  criteria=Limit(limit_price=price))

    return order
Exemplo n.º 6
0
def test_init():
    criteria = Limit(limit_price=7000.00)
    assert criteria.limit_price == 7000.00
Exemplo n.º 7
0
def test_str():
    criteria = Limit(limit_price=7000.00)
    assert str(criteria) == "<Limit: price={0}>".format(7000.00)