Exemplo n.º 1
0
def test_not_enough_balance():
    order = copy.deepcopy(DUMMY_LIMIT_BUY_ORDER)
    order._quantity = Decimal('0.00001')

    market = BittrexMarket(mock_client_v1(), mock_client_v2())
    with pytest.raises(NotEnoughBalanceToPerformOrderException):
        market.place_order(order)
Exemplo n.º 2
0
def test_get_balance():
    market = BittrexMarket(mock_client_v1(), mock_client_v2())
    balance = market.get_balance('BTC')

    assert 'BTC' == balance.currency
    assert Decimal(MY_BTC_BALANCE) == balance.available_amount
    assert 'bittrex' == balance.market_name
Exemplo n.º 3
0
def test_invalid_order():
    market = BittrexMarket(mock_client_v1(), mock_client_v2())

    order = copy.deepcopy(DUMMY_LIMIT_BUY_ORDER)
    order._type = 'gandalf'

    with pytest.raises(ValueError):
        market.place_order(order)
Exemplo n.º 4
0
def test_get_oder_status(
    expected_open: bool,
    expected_closed_at: Union[datetime.datetime, None],
    expected_quantity_amount: Decimal,
    bittrex_response: Dict
):
    client_v2 = flexmock()
    client_v2.should_receive('get_order').with_args(DUMMY_ORDER_ID_ON_MARKET).and_return(bittrex_response)

    market = BittrexMarket(flexmock(), client_v2)
    order = flexmock(id_on_market=DUMMY_ORDER_ID_ON_MARKET)
    order_status = market.get_order_status(order)

    assert expected_open == order_status.is_open
    assert expected_closed_at == order_status.closed_at
    assert expected_quantity_amount == order_status.quantity_remaining
Exemplo n.º 5
0
def test_place_order():
    client_v1 = mock_client_v1()
    client_v1 \
        .should_receive('sell_limit') \
        .with_args('USDT-BTC', 1, 8000) \
        .and_return({'success': True, 'result': {'uuid': 'abcd'}}) \
        .once()

    market = BittrexMarket(client_v1, mock_client_v2())

    order = copy.deepcopy(DUMMY_LIMIT_BUY_ORDER)
    order._direction = DIRECTION_SELL

    order = market.place_order(order)

    assert '16fd2706-8baf-433b-82eb-8c7fada847da' == str(order.order_id)
    assert 'abcd' == order.id_on_market
Exemplo n.º 6
0
def test_market_order_not_implemented():
    market = BittrexMarket(mock_client_v1(), mock_client_v2())

    with pytest.raises(NotImplementedError):
        market.place_order(DUMMY_MARKET_BUY_ORDER)
Exemplo n.º 7
0
def test_result_validation():
    BittrexMarket._validate_result({'success': True})

    with pytest.raises(MarketException):
        BittrexMarket._validate_result({'success': False, 'message': 'You shall not pass!'})
Exemplo n.º 8
0
def test_cancel_order():
    client_v1 = mock_client_v1()
    client_v1.should_receive('cancel').with_args('abcd').and_return({'success': True}).once()

    market = BittrexMarket(client_v1, mock_client_v2())
    market.cancel_order('abcd')