-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Extend Order API with commission_type
- Loading branch information
Showing
5 changed files
with
236 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
182 changes: 182 additions & 0 deletions
182
tests/broker/broker_client/test_order_commission_routes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
from alpaca.broker.client import BrokerClient | ||
from alpaca.common.enums import BaseURL | ||
from alpaca.broker.enums import CommissionType | ||
from alpaca.trading.enums import OrderSide, OrderStatus, TimeInForce | ||
from alpaca.broker.requests import ( | ||
MarketOrderRequest, | ||
) | ||
|
||
|
||
def test_order_commission_type(reqmock, client: BrokerClient): | ||
account_id = "0d969814-40d6-4b2b-99ac-2e37427f1ad2" | ||
|
||
# 1. commission_type notional per order | ||
reqmock.post( | ||
f"{BaseURL.BROKER_SANDBOX.value}/v1/trading/accounts/{account_id}/orders", | ||
text=""" | ||
{ | ||
"id": "61e69015-8549-4bfd-b9c3-01e75843f47d", | ||
"client_order_id": "eb9e2aaa-f71a-4f51-b5b4-52a6c565dad4", | ||
"created_at": "2021-03-16T18:38:01.942282Z", | ||
"updated_at": "2021-03-16T18:38:01.942282Z", | ||
"submitted_at": "2021-03-16T18:38:01.937734Z", | ||
"filled_at": null, | ||
"expired_at": null, | ||
"canceled_at": null, | ||
"failed_at": null, | ||
"replaced_at": null, | ||
"replaced_by": null, | ||
"replaces": null, | ||
"asset_id": "b4695157-0d1d-4da0-8f9e-5c53149389e4", | ||
"symbol": "SPY`", | ||
"asset_class": "us_equity", | ||
"notional": null, | ||
"qty": 1, | ||
"filled_qty": "0", | ||
"filled_avg_price": null, | ||
"order_class": "simple", | ||
"order_type": "market", | ||
"type": "market", | ||
"side": "buy", | ||
"time_in_force": "day", | ||
"limit_price": null, | ||
"stop_price": null, | ||
"status": "accepted", | ||
"extended_hours": false, | ||
"legs": null, | ||
"trail_percent": null, | ||
"trail_price": null, | ||
"hwm": null, | ||
"commission": 1.25, | ||
"commission_type": "notional" | ||
} | ||
""", | ||
) | ||
|
||
mo = MarketOrderRequest( | ||
symbol="SPY", | ||
side=OrderSide.BUY, | ||
time_in_force=TimeInForce.DAY, | ||
qty=1, | ||
commission_type=CommissionType.NOTIONAL, | ||
) | ||
|
||
assert mo.commission_type == CommissionType.NOTIONAL | ||
|
||
mo_response = client.submit_order_for_account(account_id, mo) | ||
|
||
assert mo_response.status == OrderStatus.ACCEPTED | ||
|
||
# 2. commission_type bps | ||
reqmock.post( | ||
f"{BaseURL.BROKER_SANDBOX.value}/v1/trading/accounts/{account_id}/orders", | ||
text=""" | ||
{ | ||
"id": "61e69015-8549-4bfd-b9c3-01e75843f47d", | ||
"client_order_id": "eb9e2aaa-f71a-4f51-b5b4-52a6c565dad4", | ||
"created_at": "2021-03-16T18:38:01.942282Z", | ||
"updated_at": "2021-03-16T18:38:01.942282Z", | ||
"submitted_at": "2021-03-16T18:38:01.937734Z", | ||
"filled_at": null, | ||
"expired_at": null, | ||
"canceled_at": null, | ||
"failed_at": null, | ||
"replaced_at": null, | ||
"replaced_by": null, | ||
"replaces": null, | ||
"asset_id": "b4695157-0d1d-4da0-8f9e-5c53149389e4", | ||
"symbol": "SPY`", | ||
"asset_class": "us_equity", | ||
"notional": null, | ||
"qty": 1, | ||
"filled_qty": "0", | ||
"filled_avg_price": null, | ||
"order_class": "simple", | ||
"order_type": "market", | ||
"type": "market", | ||
"side": "buy", | ||
"time_in_force": "day", | ||
"limit_price": null, | ||
"stop_price": null, | ||
"status": "accepted", | ||
"extended_hours": false, | ||
"legs": null, | ||
"trail_percent": null, | ||
"trail_price": null, | ||
"hwm": null, | ||
"commission": 1.25, | ||
"commission_type": "bps" | ||
} | ||
""", | ||
) | ||
|
||
mo = MarketOrderRequest( | ||
symbol="SPY", | ||
side=OrderSide.BUY, | ||
time_in_force=TimeInForce.DAY, | ||
qty=1, | ||
commission_type=CommissionType.BPS, | ||
) | ||
|
||
assert mo.commission_type == CommissionType.BPS | ||
|
||
mo_response = client.submit_order_for_account(account_id, mo) | ||
|
||
assert mo_response.status == OrderStatus.ACCEPTED | ||
|
||
# 3. commission_type per qty | ||
reqmock.post( | ||
f"{BaseURL.BROKER_SANDBOX.value}/v1/trading/accounts/{account_id}/orders", | ||
text=""" | ||
{ | ||
"id": "61e69015-8549-4bfd-b9c3-01e75843f47d", | ||
"client_order_id": "eb9e2aaa-f71a-4f51-b5b4-52a6c565dad4", | ||
"created_at": "2021-03-16T18:38:01.942282Z", | ||
"updated_at": "2021-03-16T18:38:01.942282Z", | ||
"submitted_at": "2021-03-16T18:38:01.937734Z", | ||
"filled_at": null, | ||
"expired_at": null, | ||
"canceled_at": null, | ||
"failed_at": null, | ||
"replaced_at": null, | ||
"replaced_by": null, | ||
"replaces": null, | ||
"asset_id": "b4695157-0d1d-4da0-8f9e-5c53149389e4", | ||
"symbol": "SPY`", | ||
"asset_class": "us_equity", | ||
"notional": null, | ||
"qty": 3, | ||
"filled_qty": "0", | ||
"filled_avg_price": null, | ||
"order_class": "simple", | ||
"order_type": "market", | ||
"type": "market", | ||
"side": "buy", | ||
"time_in_force": "day", | ||
"limit_price": null, | ||
"stop_price": null, | ||
"status": "accepted", | ||
"extended_hours": false, | ||
"legs": null, | ||
"trail_percent": null, | ||
"trail_price": null, | ||
"hwm": null, | ||
"commission": 1.25, | ||
"commission_type": "bps" | ||
} | ||
""", | ||
) | ||
|
||
mo = MarketOrderRequest( | ||
symbol="SPY", | ||
side=OrderSide.BUY, | ||
time_in_force=TimeInForce.DAY, | ||
qty=1, | ||
commission_type=CommissionType.QTY, | ||
) | ||
|
||
assert mo.commission_type == CommissionType.QTY | ||
|
||
mo_response = client.submit_order_for_account(account_id, mo) | ||
|
||
assert mo_response.status == OrderStatus.ACCEPTED |