Ejemplo n.º 1
0
def test_to_dict():

    order_spec = OrderSpec(
        side=TradeSide.BUY,
        trade_type=TradeType.MARKET,
        pair=USD / BTC
    )

    d = order_spec.to_dict()
    assert d == {
        "id": order_spec.id,
        "type": order_spec.type,
        "pair": order_spec.pair,
        "criteria": order_spec.criteria
    }

    order_spec = OrderSpec(
        side=TradeSide.BUY,
        trade_type=TradeType.MARKET,
        pair=USD / BTC,
        criteria=lambda order, exchange: True
    )

    d = order_spec.to_dict()
    assert d == {
        "id": order_spec.id,
        "type": order_spec.type,
        "pair": order_spec.pair,
        "criteria": order_spec.criteria
    }
Ejemplo n.º 2
0
def test_to_dict(mock_exchange_class):

    exchange = mock_exchange_class.return_value
    exchange.options = ExchangeOptions()
    exchange.id = "fake_exchange_id"
    exchange.name = "coinbase"
    exchange.clock = mock.Mock()
    exchange.clock.step = 0
    exchange.quote_price = mock.Mock(return_value=Decimal(7000.00))

    order_spec = OrderSpec(side=TradeSide.BUY,
                           trade_type=TradeType.MARKET,
                           exchange_pair=ExchangePair(exchange, USD / BTC))

    d = order_spec.to_dict()
    assert d == {
        "id": order_spec.id,
        "type": order_spec.type,
        "exchange_pair": order_spec.exchange_pair,
        "criteria": order_spec.criteria
    }

    order_spec = OrderSpec(side=TradeSide.BUY,
                           trade_type=TradeType.MARKET,
                           exchange_pair=ExchangePair(exchange, USD / BTC),
                           criteria=lambda order, exchange: True)

    d = order_spec.to_dict()
    assert d == {
        "id": order_spec.id,
        "type": order_spec.type,
        "exchange_pair": order_spec.exchange_pair,
        "criteria": order_spec.criteria
    }