Skip to content

Commit b181d69

Browse files
authored
Add retrieval of brokerage information (#161)
* Add retrieval of brokerage information * Fix issues raised by pre-commit
1 parent a75b3e7 commit b181d69

File tree

6 files changed

+181
-4
lines changed

6 files changed

+181
-4
lines changed

stake/asx/order.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ class Config:
3636
alias_generator = camelcase
3737

3838

39+
class Brokerage(BaseModel):
40+
brokerage_fee: Optional[float] = None
41+
brokerage_discount: Optional[float] = None
42+
fixed_fee: Optional[float] = None
43+
variable_fee_percentage: Optional[float] = None
44+
variable_limit: Optional[int] = None
45+
46+
class Config:
47+
alias_generator = camelcase
48+
49+
3950
class CancelOrderRequest(BaseModel):
4051
order_id: str
4152

@@ -69,3 +80,17 @@ async def cancel(self, order: Union[Order, CancelOrderRequest]) -> bool:
6980
payload={},
7081
)
7182
return True
83+
84+
async def brokerage(self, order_amount: float) -> Brokerage:
85+
"""Retrieve the brokerage for an order.
86+
87+
Args:
88+
order_amount (float): the per unit purchase price
89+
Returns:
90+
Brokerage: ???
91+
"""
92+
93+
data = await self._client.get(
94+
self._client.exchange.brokerage.format(orderAmount=order_amount)
95+
)
96+
return Brokerage(**data)

stake/constant.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class NYSEUrl(BaseModel):
1616
account_transactions: str = urljoin(
1717
STAKE_URL, "users/accounts/accountTransactions", allow_fragments=True
1818
)
19+
brokerage: str = urljoin(
20+
STAKE_URL, "orders/brokerage?orderAmount={orderAmount}", allow_fragments=True
21+
)
1922
cancel_order: str = urljoin(
2023
STAKE_URL, "orders/cancelOrder/{orderId}", allow_fragments=True
2124
)
@@ -92,7 +95,11 @@ class ASXUrl(BaseModel):
9295
"""Contains all the visited stake urls for the ASX."""
9396

9497
ASX_STAKE_URL: str = "https://global-prd-api.hellostake.com/api/asx/"
95-
98+
brokerage: str = urljoin(
99+
ASX_STAKE_URL,
100+
"orders/brokerage?orderAmount={orderAmount}",
101+
allow_fragments=True,
102+
)
96103
cash_available: str = urljoin(ASX_STAKE_URL, "cash", allow_fragments=True)
97104
cancel_order: str = urljoin(
98105
ASX_STAKE_URL, "orders/{orderId}/cancel", allow_fragments=True
@@ -119,10 +126,10 @@ class ASXUrl(BaseModel):
119126
trade_activity: str = urljoin(
120127
ASX_STAKE_URL, "orders/tradeActivity", allow_fragments=True
121128
)
122-
watchlists = urljoin(
129+
watchlists: str = urljoin(
123130
ASX_STAKE_URL, "instrument/v2/watchlists", allow_fragments=True
124131
)
125-
create_watchlist = urljoin(
132+
create_watchlist: str = urljoin(
126133
ASX_STAKE_URL, "instrument/v2/watchlist", allow_fragments=True
127134
)
128135
read_watchlist: str = urljoin(

stake/order.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime
22
from enum import IntEnum
3-
from typing import List, Union
3+
from typing import List, Optional, Union
44

55
from pydantic import BaseModel, Field
66

@@ -40,6 +40,16 @@ class Config:
4040
alias_generator = camelcase
4141

4242

43+
class Brokerage(BaseModel):
44+
brokerage_fee: Optional[float] = None
45+
fixed_fee: Optional[float] = None
46+
variable_fee_percentage: Optional[float] = None
47+
variable_limit: Optional[int] = None
48+
49+
class Config:
50+
alias_generator = camelcase
51+
52+
4353
class CancelOrderRequest(BaseModel):
4454
order_id: str
4555

@@ -72,3 +82,17 @@ async def cancel(self, order: Union[Order, CancelOrderRequest]) -> bool:
7282
self._client.exchange.cancel_order.format(orderId=order.order_id)
7383
)
7484
return True
85+
86+
async def brokerage(self, order_amount: float) -> Brokerage:
87+
"""Retrieve the brokerage for an order.
88+
89+
Args:
90+
order_amount (float): the per unit purchase price
91+
Returns:
92+
Brokerage: the brokerage information
93+
"""
94+
95+
data = await self._client.get(
96+
self._client.exchange.brokerage.format(orderAmount=order_amount)
97+
)
98+
return Brokerage(**data)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- application/json
7+
Content-Type:
8+
- application/json
9+
method: GET
10+
uri: https://global-prd-api.hellostake.com/api/user
11+
response:
12+
body:
13+
string:
14+
'{"canTradeOnUnsettledFunds": false, "cpfValue": null, "emailVerified":
15+
true, "hasFunded": true, "hasTraded": true, "userId": "7c9bbfae-0000-47b7-0000-0e66d868c2cf",
16+
"username": "michael29", "emailAddress": "reevesmegan@gilmore-wright.biz",
17+
"dw_AccountId": "1cf93550-8eb4-4c32-a229-826cf8c1be59", "dw_AccountNumber":
18+
"z0-0593879b", "macAccountNumber": "d9-0481457G", "status": null, "macStatus":
19+
"BASIC_USER", "dwStatus": null, "truliooStatus": "APPROVED", "truliooStatusWithWatchlist":
20+
null, "firstName": "Rita", "middleName": null, "lastName": "Jones", "phoneNumber":
21+
"(640)242-4270x965", "signUpPhase": 0, "ackSignedWhen": "2021-11-15", "createdDate":
22+
1574303699770, "stakeApprovedDate": null, "accountType": "INDIVIDUAL", "masterAccountId":
23+
null, "referralCode": "W2-6612029X", "referredByCode": null, "regionIdentifier":
24+
"AUS", "assetSummary": null, "fundingStatistics": null, "tradingStatistics":
25+
null, "w8File": [], "rewardJourneyTimestamp": null, "rewardJourneyStatus":
26+
null, "userProfile": {"residentialAddress": null, "postalAddress": null},
27+
"ledgerBalance": 0.0, "investorAccreditations": null, "proscoreStatus": null,
28+
"fxSpeed": "Regular", "facilitaStatus": null, "dateOfBirth": null, "upToDateDetails2021":
29+
"NO_REQUIREMENTS", "stakeKycStatus": "KYC_APPROVED", "awxMigrationDocsRequired":
30+
null, "documentsStatus": "NO_ACTION", "accountStatus": "OPEN", "mfaenabled":
31+
false}'
32+
headers: {}
33+
status:
34+
code: 200
35+
message: OK
36+
url: https://global-prd-api.hellostake.com/api/user
37+
- request:
38+
body: null
39+
headers:
40+
Accept:
41+
- application/json
42+
Content-Type:
43+
- application/json
44+
method: GET
45+
uri: https://global-prd-api.hellostake.com/api/orders/brokerage?orderAmount=1.0
46+
response:
47+
body:
48+
string:
49+
'{"brokerageFee": 3, "fixedFee": 3, "variableFeePercentage": 0.01,
50+
"variableLimit": 30000}'
51+
headers: {}
52+
status:
53+
code: 200
54+
message: OK
55+
url: https://global-prd-api.hellostake.com/api/orders/brokerage?orderAmount=1.0
56+
version: 1
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- application/json
7+
Content-Type:
8+
- application/json
9+
method: GET
10+
uri: https://global-prd-api.hellostake.com/api/user
11+
response:
12+
body:
13+
string:
14+
'{"canTradeOnUnsettledFunds": false, "cpfValue": null, "emailVerified":
15+
true, "hasFunded": true, "hasTraded": true, "userId": "7c9bbfae-0000-47b7-0000-0e66d868c2cf",
16+
"username": "leonardzachary", "emailAddress": "ellen70@bates-williams.com",
17+
"dw_AccountId": "1cf93550-8eb4-4c32-a229-826cf8c1be59", "dw_AccountNumber":
18+
"R6-1813041A", "macAccountNumber": "K4-3517949y", "status": null, "macStatus":
19+
"BASIC_USER", "dwStatus": null, "truliooStatus": "APPROVED", "truliooStatusWithWatchlist":
20+
null, "firstName": "Tammy", "middleName": null, "lastName": "Alexander", "phoneNumber":
21+
"9011530005", "signUpPhase": 0, "ackSignedWhen": "2022-01-22", "createdDate":
22+
1574303699770, "stakeApprovedDate": null, "accountType": "INDIVIDUAL", "masterAccountId":
23+
null, "referralCode": "A1-2107594j", "referredByCode": null, "regionIdentifier":
24+
"AUS", "assetSummary": null, "fundingStatistics": null, "tradingStatistics":
25+
null, "w8File": [], "rewardJourneyTimestamp": null, "rewardJourneyStatus":
26+
null, "userProfile": {"residentialAddress": null, "postalAddress": null},
27+
"ledgerBalance": 0.0, "investorAccreditations": null, "proscoreStatus": null,
28+
"fxSpeed": "Regular", "facilitaStatus": null, "dateOfBirth": null, "upToDateDetails2021":
29+
"NO_REQUIREMENTS", "stakeKycStatus": "KYC_APPROVED", "awxMigrationDocsRequired":
30+
null, "documentsStatus": "NO_ACTION", "accountStatus": "OPEN", "mfaenabled":
31+
false}'
32+
headers: {}
33+
status:
34+
code: 200
35+
message: OK
36+
url: https://global-prd-api.hellostake.com/api/user
37+
- request:
38+
body: null
39+
headers:
40+
Accept:
41+
- application/json
42+
Content-Type:
43+
- application/json
44+
method: GET
45+
uri: https://global-prd-api.hellostake.com/api/asx/orders/brokerage?orderAmount=1.0
46+
response:
47+
body:
48+
string:
49+
'{"brokerageFee": 3.00, "brokerageDiscount": 0.00, "fixedFee": 3.00,
50+
"variableFeePercentage": 0.01, "variableLimit": 30000}'
51+
headers: {}
52+
status:
53+
code: 200
54+
message: OK
55+
url: https://global-prd-api.hellostake.com/api/asx/orders/brokerage?orderAmount=1.0
56+
version: 1

tests/test_order.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ async def test_cancel_order(tracing_client: StakeClient, exchange):
2626
assert cancel_order
2727
orders = await tracing_client.orders.list()
2828
assert len(orders) == how_many_orders - 1
29+
30+
31+
@pytest.mark.parametrize("exchange", (constant.NYSE, constant.ASX))
32+
@pytest.mark.vcr()
33+
@pytest.mark.asyncio
34+
async def test_brokerage(tracing_client: StakeClient, exchange):
35+
tracing_client.set_exchange(exchange)
36+
brokerage = await tracing_client.orders.brokerage(order_amount=1.0)
37+
assert brokerage

0 commit comments

Comments
 (0)