Skip to content

Commit 7ced9ed

Browse files
committed
Fixed funds_in_flight
1 parent de8f4dc commit 7ced9ed

6 files changed

Lines changed: 104 additions & 10 deletions

File tree

‎coverage.svg‎

Lines changed: 3 additions & 3 deletions
Loading

‎stake/client.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def __init__(
112112
self.user: Optional[user.User] = None
113113

114114
self.headers = Headers()
115-
self.httpClient = HttpClient
115+
self.http_client = HttpClient
116116

117117
# register all the clients
118118
self.equities = equity.EquitiesClient(self)
@@ -137,7 +137,7 @@ async def get(self, url: str, payload: dict = None) -> dict:
137137
Returns:
138138
dict: the json response
139139
"""
140-
return await self.httpClient.get(
140+
return await self.http_client.get(
141141
url, payload=payload, headers=self.headers.dict(by_alias=True)
142142
)
143143

@@ -151,7 +151,7 @@ async def post(self, url: str, payload: dict) -> dict:
151151
Returns:
152152
dict: the json response
153153
"""
154-
return await self.httpClient.post(
154+
return await self.http_client.post(
155155
url, payload=payload, headers=self.headers.dict(by_alias=True)
156156
)
157157

@@ -165,7 +165,7 @@ async def delete(self, url: str, payload: dict = None) -> bool:
165165
Returns:
166166
bool: True if the deletion was successful.
167167
"""
168-
return await self.httpClient.delete(
168+
return await self.http_client.delete(
169169
url, headers=self.headers.dict(by_alias=True), payload=payload
170170
)
171171

‎stake/funding.py‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ class Config:
6666
alias_generator = camelcase
6767

6868

69+
class FundsInFlight(BaseModel):
70+
type: str
71+
insert_date_time: str
72+
estimated_arrival_time: str
73+
estimated_arrival_time_us: str = Field(alias="estimatedArrivalTimeUS")
74+
transaction_type: str
75+
to_amount: float
76+
from_amount: float
77+
78+
class Config:
79+
alias_generator = camelcase
80+
81+
6982
class FundingsClient(BaseClient):
7083
async def list(self, request: FundingRequest) -> List[Funding]:
7184
payload = {
@@ -76,9 +89,13 @@ async def list(self, request: FundingRequest) -> List[Funding]:
7689

7790
return [Funding(**d) for d in data]
7891

79-
async def in_flight(self) -> dict:
92+
async def in_flight(self) -> List[FundsInFlight]:
8093
"""Returns the funds currently in flight."""
81-
return await self._client.get(Url.fund_details)["fundsInFlight"]
94+
data = await self._client.get(Url.fund_details)
95+
data = data.get("fundsInFlight")
96+
if not data:
97+
return []
98+
return [FundsInFlight(**d) for d in data]
8299

83100
async def cash_available(self) -> CashAvailable:
84101
data = await self._client.get(Url.cash_available)

‎tests/conftest.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ async def tracing_client(request, mocker):
176176
else:
177177
async with StakeClient() as client:
178178
yield client
179-
state = deepcopy(client.httpClient.state)
179+
state = deepcopy(client.http_client.state)
180180
RecordingHttpClient.user_id = str(client.user.id)
181181
state = RecordingHttpClient.redacted(state)
182182
json.dump(
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"tests.test_funding.test_funds_in_flight": [
3+
{
4+
"url": "{url}user",
5+
"body": null,
6+
"payload": {
7+
"userId": "7c9bbfae-0000-47b7-0000-0e66d868c2cf",
8+
"username": "rita19",
9+
"emailAddress": "torresbenjamin@gmail.com",
10+
"dw_id": "8bd56b19-9f9e-44d5-a10e-df7316f17d84",
11+
"dw_AccountId": "8bd56b19-9f9e-44d5-a10e-df7316f17d84",
12+
"dw_AccountNumber": "w4-1267174s",
13+
"macAccountNumber": "H1-7641957H",
14+
"status": "KYC_PENDING",
15+
"macStatus": "BASIC_USER",
16+
"dwStatus": "KYC_APPROVED",
17+
"truliooStatus": "APPROVED",
18+
"truliooStatusWithWatchlist": null,
19+
"firstName": "Tammy",
20+
"lastName": "Alexander",
21+
"phoneNumber": "9011530005",
22+
"signUpPhase": 0,
23+
"ackSignedWhen": "2020-09-08",
24+
"createdDate": 1574303699770,
25+
"stakeApprovedDate": null,
26+
"accountType": "INDIVIDUAL",
27+
"masterAccountId": null,
28+
"referralCode": "L7-2127933N",
29+
"referredByCode": null,
30+
"regionIdentifier": "AUS",
31+
"assetSummary": null,
32+
"fundingStatistics": null,
33+
"tradingStatistics": null,
34+
"w8File": [],
35+
"emailVerified": true,
36+
"hasFunded": true,
37+
"hasTraded": true,
38+
"rewardJourneyTimestamp": null,
39+
"rewardJourneyStatus": null,
40+
"userProfile": {
41+
"residentialAddress": null,
42+
"postalAddress": null
43+
},
44+
"ledgerBalance": 0,
45+
"investorAccreditations": null,
46+
"canTradeOnUnsettledFunds": true,
47+
"mfaenabled": false
48+
},
49+
"method": "GET"
50+
},
51+
{
52+
"url": "{url}fund/details",
53+
"body": null,
54+
"payload": {
55+
"fundsInFlight": [
56+
{
57+
"type": "Funding",
58+
"insertDateTime": "17 Sep 2020 05:21AM",
59+
"estimatedArrivalTime": "19 Sep 2020 05:00AM",
60+
"estimatedArrivalTimeUS": "Fri 1:00pm NY time",
61+
"transactionType": "Poli",
62+
"toAmount": 1512.0,
63+
"fromAmount": 2100.0
64+
}
65+
]
66+
},
67+
"method": "GET"
68+
}
69+
]
70+
}

‎tests/test_funding.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ async def test_cash_available(tracing_client):
1414
cash_available = await tracing_client.fundings.cash_available()
1515
assert cash_available.cash_available_for_withdrawal == 551.14
1616
assert cash_available.cash_settlement[0].utc_time.month == 9
17+
18+
19+
@pytest.mark.asyncio
20+
async def test_funds_in_flight(tracing_client):
21+
funds_in_flight = await tracing_client.fundings.in_flight()
22+
assert len(funds_in_flight) == 1
23+
assert funds_in_flight[0].transaction_type == "Poli"

0 commit comments

Comments
 (0)