Beispiel #1
0
async def test_account_limit_orders(account: cro.Account,
                                    exchange: cro.Exchange):
    buy_price = round(await exchange.get_price(cro.pairs.CRO_USDT) / 2, 4)
    order_ids = await asyncio.gather(*[
        account.buy_limit(cro.pairs.CRO_USDT, 0.001, buy_price)
        for i in range(25)
    ])
    order_ids += await asyncio.gather(*[
        account.sell_limit(cro.pairs.CRO_USDT, 0.001, round(buy_price * 4, 4))
        for i in range(25)
    ])
    all_orders = await account.get_orders_history(cro.pairs.CRO_USDT,
                                                  page_size=50)

    await account.cancel_order(order_ids[0],
                               cro.pairs.CRO_USDT,
                               check_status=True)
    order = await account.get_order(order_ids[0])
    assert order.is_canceled

    for order_id in order_ids[1:]:
        await account.cancel_order(order_id, cro.pairs.CRO_USDT)

    open_orders = [
        order for order in await account.get_open_orders()
        if order.id in order_ids
    ]
    assert not open_orders

    all_orders = await account.get_orders_history(cro.pairs.CRO_USDT,
                                                  page_size=50)
    ids = [order.id for order in all_orders]
    assert set(ids) & set(order_ids)
Beispiel #2
0
async def test_account_market_orders(account: cro.Account,
                                     exchange: cro.Exchange):
    order_ids = {'buy': [], 'sell': []}
    orders = []
    task = asyncio.create_task(listen_orders(account, orders))
    await asyncio.sleep(5)

    await asyncio.gather(
        *[make_trades(account, exchange, order_ids) for _ in range(10)])
    await asyncio.sleep(1)

    orders = await asyncio.gather(*[
        account.get_order(order_id)
        for order_id in order_ids['buy'] + order_ids['sell']
    ])
    for order in orders:
        assert order.trades, order

    trades = await account.get_trades(cro.pairs.CRO_USDT, page_size=20)
    for trade in trades:
        if trade.is_buy:
            assert trade.order_id in order_ids['buy']
            assert trade.order_id not in order_ids['sell']
        elif trade.is_sell:
            assert trade.order_id in order_ids['sell']
            assert trade.order_id not in order_ids['buy']

    await asyncio.sleep(10)

    assert len(orders) >= len(order_ids['buy']) + len(order_ids['sell'])

    if not task.cancelled():
        task.cancel()
    await asyncio.sleep(1)
Beispiel #3
0
async def test_account_buy_limit(exchange: cro.Exchange, account: cro.Account):
    buy_price = round(await exchange.get_price(cro.Pair.CROUSDT) / 2, 4)
    order_ids = await asyncio.gather(*[
        account.buy_limit(cro.Pair.CROUSDT, 0.01, buy_price)
        for i in range(10)
    ])
    all_orders = await account.get_orders(cro.Pair.CROUSDT, page_size=10)

    await account.cancel_order(
        order_ids[0], cro.Pair.CROUSDT, wait_for_cancel=True)
    order = await account.get_order(order_ids[0])
    assert order['status'] == cro.OrderStatus.CANCELED.value

    for order_id in order_ids[1:]:
        await account.cancel_order(order_id, cro.Pair.CROUSDT)

    open_orders = [
        order
        for order in await account.get_open_orders(cro.Pair.CROUSDT)
        if order['id'] in order_ids
    ]
    assert not open_orders

    all_orders = await account.get_orders(cro.Pair.CROUSDT, page_size=10)
    ids = [order['id'] for order in all_orders]
    assert set(ids) & set(order_ids)
async def test_no_dublicated_mass_limit_orders(exchange: cro.Exchange,
                                               account: cro.Account):
    buy_price = round(await exchange.get_price(cro.Pair.CRO_USDT) / 2, 4)
    order_ids = await asyncio.gather(*[
        account.buy_limit(cro.Pair.CRO_USDT, 0.001,
                          round(buy_price / 1000 + i / 10000.0, 4))
        for i in range(100)
    ])

    real_orders = await asyncio.gather(
        *[account.get_order(id_) for id_ in order_ids])
    for order in real_orders:
        assert order.status == cro.OrderStatus.ACTIVE, order

    assert len(real_orders) == 100

    orders = await account.get_open_orders(cro.Pair.CRO_USDT)
    assert sorted(o.id for o in orders) == sorted(order_ids)
Beispiel #5
0
async def test_no_dublicated_mass_limit_orders(exchange: cro.Exchange,
                                               account: cro.Account):
    buy_price = round(await exchange.get_price(cro.pairs.CRO_USDT) / 2, 4)
    orders_count = 100
    order_ids = await asyncio.gather(*[
        account.buy_limit(cro.pairs.CRO_USDT, 0.001,
                          round(buy_price + i * 0.0001, 4))
        for i in range(orders_count)
    ])

    real_orders = await asyncio.gather(
        *[account.get_order(id_) for id_ in order_ids])
    for order in real_orders:
        assert order.is_active, order

    await asyncio.sleep(2)

    open_orders = await account.get_open_orders(cro.pairs.CRO_USDT)
    open_order_ids = sorted(o.id for o in open_orders if o.is_active)

    assert len(real_orders) == len(open_order_ids) == orders_count
    assert open_order_ids == sorted(order_ids)
Beispiel #6
0
async def test_no_dublicated_mass_limit_orders(
        exchange: cro.Exchange, account: cro.Account):
    buy_price = round(await exchange.get_price(cro.Pair.CROUSDT) / 2, 4)
    order_ids = await asyncio.gather(*[
        account.buy_limit(
            cro.Pair.CROUSDT, 0.01,
            round(buy_price / 2 + i / 10000.0, 4)
        )
        for i in range(150)
    ])

    orders = await account.get_open_orders(cro.Pair.CROUSDT)
    assert sorted(o['id'] for o in orders) == sorted(order_ids)
Beispiel #7
0
async def listen_orders(account: cro.Account, orders):
    async for order in account.listen_orders(cro.pairs.CRO_USDT):
        orders.append(order)