Skip to content

Add submit order list support for sandbox #2714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Released on TBD (UTC).
- Added support for Pool liquidity updates for blockchain adapter (#2692), thanks @filipmacek
- Added fill report reconciliation warning when discrepancy with existing fill (#2706), thanks @faysou
- Added `bid_levels` and `ask_levels` for `OrderBook.pprint`
- Added support for order-list submission in the sandbox execution client.

### Breaking Changes
- Changed timer `allow_past=False` behavior: now validates the `next_event_time` instead of the `start_time`. This allows timers with past start times as long as their next scheduled event is still in the future
Expand Down
3 changes: 3 additions & 0 deletions nautilus_trader/adapters/sandbox/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ async def generate_position_status_reports(
def submit_order(self, command):
return self._client.submit_order(command)

def submit_order_list(self, command):
return self._client.submit_order_list(command)

def modify_order(self, command):
return self._client.modify_order(command)

Expand Down
67 changes: 65 additions & 2 deletions tests/integration_tests/adapters/sandbox/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import pytest

from nautilus_trader.backtest.exchange import SimulatedExchange
from nautilus_trader.common.component import TestClock
from nautilus_trader.common.factories import OrderFactory
from nautilus_trader.model.data import QuoteTick
from nautilus_trader.model.events import OrderAccepted
from nautilus_trader.model.events import OrderCanceled
Expand All @@ -27,8 +29,11 @@
from nautilus_trader.model.events import OrderSubmitted
from nautilus_trader.model.events import OrderUpdated
from nautilus_trader.model.identifiers import ClientOrderId
from nautilus_trader.model.identifiers import StrategyId
from nautilus_trader.model.identifiers import TraderId
from nautilus_trader.model.identifiers import VenueOrderId
from nautilus_trader.model.objects import Price
from nautilus_trader.model.orders.list import OrderList
from nautilus_trader.test_kit.stubs.commands import TestCommandStubs
from nautilus_trader.test_kit.stubs.execution import TestExecStubs

Expand All @@ -53,7 +58,6 @@ async def test_connect(exec_client):
assert exec_client.is_connected


@pytest.mark.skip(reason="Sandbox WIP")
@pytest.mark.asyncio()
async def test_submit_order_success(exec_client, instrument, strategy, events):
# Arrange
Expand All @@ -66,13 +70,72 @@ async def test_submit_order_success(exec_client, instrument, strategy, events):

# Assert
print(events)
_, submitted, _, accepted, _, filled, _ = events
_, submitted, _, accepted, filled, _, _ = events
assert isinstance(submitted, OrderSubmitted)
assert isinstance(accepted, OrderAccepted)
assert isinstance(filled, OrderFilled)
assert accepted.venue_order_id.value.startswith("SANDBOX-")


@pytest.mark.asyncio()
async def test_submit_orders_list_success(
exec_client,
instrument,
strategy,
events,
):
# Arrange
exec_client.connect()
factory = OrderFactory(
trader_id=TraderId("TESTER-000"),
strategy_id=StrategyId("S-001"),
clock=TestClock(),
)
first_order = TestExecStubs.limit_order(
instrument=instrument,
client_order_id=factory.generate_client_order_id(),
)
second_order = TestExecStubs.limit_order(
instrument=instrument,
client_order_id=factory.generate_client_order_id(),
)
order_list = OrderList(
order_list_id=factory.generate_order_list_id(),
orders=[first_order, second_order],
)

# Act
strategy.submit_order_list(order_list=order_list)
exec_client.on_data(_make_quote_tick(instrument))

# Assert
print(events)
(
_, # first initialized
_, # second initialized
first_submitted,
second_submitted,
_, # account state
first_accepted,
_, # account state
second_accepted,
first_filled,
_, # account state
_, # position opened
second_filled,
_, # account state
_, # position changed
) = events
assert isinstance(first_submitted, OrderSubmitted)
assert isinstance(second_submitted, OrderSubmitted)
assert isinstance(first_accepted, OrderAccepted)
assert isinstance(second_accepted, OrderAccepted)
assert isinstance(first_filled, OrderFilled)
assert isinstance(second_filled, OrderFilled)
assert first_accepted.venue_order_id.value.startswith("SANDBOX-")
assert second_accepted.venue_order_id.value.startswith("SANDBOX-")


@pytest.mark.asyncio()
async def test_modify_order_success(exec_client, strategy, instrument, events):
# Arrange
Expand Down
Loading