Skip to content
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
13 changes: 1 addition & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,7 @@ jobs:
- name: Run Tests
env: # Or as an environment variable
STAKE_TOKEN: ${{ secrets.STAKE_TOKEN }}
run: poetry install && poetry run pytest --cov=stake --cov-report=xml && poetry run coverage-badge -f -o coverage.svg
- name: Upload coverage
uses: actions/upload-artifact@v4
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == 3.10 }}
with:
name: coverage
path: coverage.svg
- name: Auto commit coverage badge
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == 3.10 }}
uses: EndBug/add-and-commit@v4.4.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: poetry install && poetry run pytest --cov=stake --cov-report=xml
- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@master
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == 3.10 }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
![Coverage](coverage.svg)[![Downloads](https://pepy.tech/badge/stake)](https://pepy.tech/project/stake)[![Downloads](https://pepy.tech/badge/stake/month)](https://pepy.tech/project/stake)
[![Downloads](https://pepy.tech/badge/stake)](https://pepy.tech/project/stake)[![Downloads](https://pepy.tech/badge/stake/month)](https://pepy.tech/project/stake)

# Stake

Expand Down
21 changes: 0 additions & 21 deletions coverage.svg

This file was deleted.

1,456 changes: 719 additions & 737 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pre-commit = "^4.2.0"
pytest-coverage = "^0.0"
pytest-mock = "^3.3.0"
faker = "^4.14.0"
coverage-badge = "^1.0.1"
pytest-recording = "^0.13.4"


Expand Down
9 changes: 3 additions & 6 deletions stake/asx/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@ class GenericTradeRequest(BaseModel):
model_config = ConfigDict(alias_generator=camelcase, populate_by_name=True)

@model_validator(mode="after")
@classmethod
def symbol_or_instrument_type(
cls, value: "GenericTradeRequest"
) -> "GenericTradeRequest":
if value.symbol is None and value.instrument_code is None:
def symbol_or_instrument_type(self) -> "GenericTradeRequest":
if self.symbol is None and self.instrument_code is None:
raise ValueError("Either specify symbol or instrument_code")
return value
return self


class LimitBuyRequest(GenericTradeRequest):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json
Content-Type:
- application/json
method: GET
uri: https://api2.prd.hellostake.com/api/user
response:
body:
string:
'{"canTradeOnUnsettledFunds": false, "cpfValue": null, "emailVerified":
true, "hasFunded": true, "hasTraded": true, "userId": "7c9bbfae-0000-47b7-0000-0e66d868c2cf",
"username": "michael29", "emailAddress": "reevesmegan@gilmore-wright.biz",
"dw_AccountId": "1cf93550-8eb4-4c32-a229-826cf8c1be59", "dw_AccountNumber":
"z0-0593879b", "macAccountNumber": "d9-0481457G", "status": null, "macStatus":
"BASIC_USER", "dwStatus": null, "truliooStatus": "APPROVED", "truliooStatusWithWatchlist":
null, "firstName": "Rita", "middleName": null, "lastName": "Jones", "phoneNumber":
"(640)242-4270x965", "signUpPhase": 0, "ackSignedWhen": "2023-10-01", "createdDate":
1574303699770, "stakeApprovedDate": null, "accountType": "INDIVIDUAL", "masterAccountId":
null, "referralCode": "W2-6612029X", "referredByCode": null, "regionIdentifier":
"AUS", "assetSummary": null, "fundingStatistics": null, "tradingStatistics":
null, "w8File": [], "rewardJourneyTimestamp": null, "rewardJourneyStatus":
null, "userProfile": {"residentialAddress": null, "postalAddress": null},
"ledgerBalance": 0.0, "fxSpeed": "Instant", "dateOfBirth": null, "upToDateDetails2021":
"NO_REQUIREMENTS", "stakeKycStatus": "KYC_APPROVED", "awxMigrationDocsRequired":
null, "documentsStatus": "NO_ACTION", "accountStatus": "OPEN", "mfaenabled":
false}'
headers: {}
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Content-Type:
- application/json
method: GET
uri: https://api2.prd.hellostake.com/api/asx/instrument/search?searchKey=CBA
response:
body:
string:
'{"instruments": [{"instrumentId": "CBA.XAU", "symbol": "CBA", "name":
"Commonwealth Bank of Australia", "type": "EQUITY", "recentAnnouncement":
false, "sensitive": false, "gfdOnly": false, "marketCap": "289.29B", "exchange":
null, "score": 0}, {"instrumentId": "CBAPI.XAU", "symbol": "CBAPI", "name":
"Commonwealth Bank of Australia", "type": "INTEREST_RATE", "recentAnnouncement":
false, "sensitive": false, "gfdOnly": false, "marketCap": "289.29B", "exchange":
null, "score": 2}, {"instrumentId": "CBAPJ.XAU", "symbol": "CBAPJ", "name":
"Commonwealth Bank of Australia", "type": "INTEREST_RATE", "recentAnnouncement":
false, "sensitive": false, "gfdOnly": false, "marketCap": "289.29B", "exchange":
null, "score": 2}, {"instrumentId": "CBAPK.XAU", "symbol": "CBAPK", "name":
"Commonwealth Bank of Australia", "type": "INTEREST_RATE", "recentAnnouncement":
false, "sensitive": false, "gfdOnly": false, "marketCap": "289.29B", "exchange":
null, "score": 2}, {"instrumentId": "CBAPL.XAU", "symbol": "CBAPL", "name":
"Commonwealth Bank of Australia", "type": "INTEREST_RATE", "recentAnnouncement":
false, "sensitive": false, "gfdOnly": false, "marketCap": "289.29B", "exchange":
null, "score": 2}, {"instrumentId": "CBAPM.XAU", "symbol": "CBAPM", "name":
"Commonwealth Bank of Australia", "type": "INTEREST_RATE", "recentAnnouncement":
false, "sensitive": false, "gfdOnly": false, "marketCap": "289.29B", "exchange":
null, "score": 2}, {"instrumentId": "CB8.XAU", "symbol": "CB8", "name": "CBA
Toress Basket [CB8]", "type": "EQUITY", "recentAnnouncement": false, "sensitive":
false, "gfdOnly": false, "marketCap": "289.29B", "exchange": null, "score":
120}, {"instrumentId": "IHCB.XAU", "symbol": "IHCB", "name": "iShares Core
Global Corporate Bond (AUD Hedged) ETF", "type": "ETF", "recentAnnouncement":
false, "sensitive": false, "gfdOnly": false, "marketCap": "266M", "exchange":
null, "score": 122}], "instrumentTags": []}'
headers: {}
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Content-Type:
- application/json
method: GET
uri: https://api2.prd.hellostake.com/api/asx/instrument/singleQuote/CBA
response:
body:
string:
'{"marketStatus": "CLOSED", "lastTradedExchange": "ASX", "symbol": "CBA",
"lastTradedTimestamp": 1775107195, "lastTrade": "172.8000", "bid": "172.8000",
"ask": "172.8100", "priorClose": "171.9000", "open": "171.7000", "high": "174.2200",
"low": "171.3500", "pointsChange": "0.9000", "percentageChange": "0.52", "outOfMarketPrice":
"172.8000", "outOfMarketQuantity": "784637", "outOfMarketSurplus": "187003",
"volume": 1927460}'
headers: {}
status:
code: 200
message: OK
version: 1
113 changes: 113 additions & 0 deletions tests/cassettes/test_product/test_search_products[exchange1-MSFT].yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json
Content-Type:
- application/json
method: GET
uri: https://api2.prd.hellostake.com/api/user
response:
body:
string:
'{"canTradeOnUnsettledFunds": false, "cpfValue": null, "emailVerified":
true, "hasFunded": true, "hasTraded": true, "userId": "7c9bbfae-0000-47b7-0000-0e66d868c2cf",
"username": "michael29", "emailAddress": "reevesmegan@gilmore-wright.biz",
"dw_AccountId": "1cf93550-8eb4-4c32-a229-826cf8c1be59", "dw_AccountNumber":
"z0-0593879b", "macAccountNumber": "d9-0481457G", "status": null, "macStatus":
"BASIC_USER", "dwStatus": null, "truliooStatus": "APPROVED", "truliooStatusWithWatchlist":
null, "firstName": "Rita", "middleName": null, "lastName": "Jones", "phoneNumber":
"(640)242-4270x965", "signUpPhase": 0, "ackSignedWhen": "2023-10-01", "createdDate":
1574303699770, "stakeApprovedDate": null, "accountType": "INDIVIDUAL", "masterAccountId":
null, "referralCode": "W2-6612029X", "referredByCode": null, "regionIdentifier":
"AUS", "assetSummary": null, "fundingStatistics": null, "tradingStatistics":
null, "w8File": [], "rewardJourneyTimestamp": null, "rewardJourneyStatus":
null, "userProfile": {"residentialAddress": null, "postalAddress": null},
"ledgerBalance": 0.0, "fxSpeed": "Instant", "dateOfBirth": null, "upToDateDetails2021":
"NO_REQUIREMENTS", "stakeKycStatus": "KYC_APPROVED", "awxMigrationDocsRequired":
null, "documentsStatus": "NO_ACTION", "accountStatus": "OPEN", "mfaenabled":
false}'
headers: {}
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Content-Type:
- application/json
method: GET
uri: https://api2.prd.hellostake.com/api/products/getProductSuggestions/MSFT
response:
body:
string:
'{"instruments": [{"name": "Microsoft Corporation", "symbol": "MSFT",
"encodedName": "microsoft-corporation-msft", "instrumentId": "e234cc98-cd08-4b04-a388-fe5c822beea6",
"stakeInstrumentId": "e3769c0b-456d-49dd-bec5-7a750c146d11", "imageUrl": "https://d3an3cesqmrf1x.cloudfront.net/images/symbols/msft.png",
"exchange": "NSQ"}, {"name": "DIREXION DAILY MSFT BEAR 1X", "symbol": "MSFD",
"encodedName": "direxion-daily-msft-bear-1x-msfd", "instrumentId": "001b5a31-32fb-401d-82b5-f2dc3ec98fae",
"stakeInstrumentId": "83bc732b-cc03-4baa-9451-00e21d6cd9ef", "imageUrl": "https://drivewealth.imgix.net/symbols/msfd_1666599112.png?fit=fillmax&w=125&h=125&bg=FFFFFF",
"exchange": "NMQ"}, {"name": "GraniteShares 2x Long MSFT Daily ETF", "symbol":
"MSFL", "encodedName": "graniteshares-2x-long-msft-daily-etf-msfl", "instrumentId":
"18998b7b-e440-48e5-8cc0-556d5ad5a991", "stakeInstrumentId": "d22172a0-fdf1-4aad-a796-8850c835023b",
"imageUrl": "https://drivewealth.imgix.net/symbols/msfl_1714794745.png?fit=fillmax&w=125&h=125&bg=FFFFFF",
"exchange": "NMQ"}, {"name": "ROUNDHILL MSFT WEEKLYPAY ETF", "symbol": "MSFW",
"encodedName": "roundhill-msft-weeklypay-etf-msfw", "instrumentId": "36001204-bb72-4db4-b0ba-9b9c602c9729",
"stakeInstrumentId": "5a04cb5e-28d9-4e0c-9fa2-0c1c83a8f221", "imageUrl": "https://drivewealth.imgix.net/symbols/msfw_1753257703.png?fit=fillmax&w=125&h=125&bg=FFFFFF",
"exchange": "BTQ"}, {"name": "YieldMax MSFT Option Income Strategy ETF", "symbol":
"MSFO", "encodedName": "yieldmax-msft-option-income-strategy-etf-msfo", "instrumentId":
"634c3949-de0a-467b-baa7-fb60c993ed19", "stakeInstrumentId": "645ee7ea-0434-4d96-a7af-d279f84de86d",
"imageUrl": "https://drivewealth.imgix.net/symbols/msfo_1697073212.png?fit=fillmax&w=125&h=125&bg=FFFFFF",
"exchange": "PCQ"}, {"name": "DIREXION DAILY MSFT BULL 1.5", "symbol": "MSFU",
"encodedName": "direxion-daily-msft-bull-15-msfu", "instrumentId": "838e1162-c850-484c-b3b9-3054749b5e39",
"stakeInstrumentId": "01e9d902-9593-495b-b7f5-6074c83940ca", "imageUrl": "https://drivewealth.imgix.net/symbols/msfu_1666599113.png?fit=fillmax&w=125&h=125&bg=FFFFFF",
"exchange": "NMQ"}], "instrumentTags": []}'
headers: {}
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Content-Type:
- application/json
method: GET
uri: https://api2.prd.hellostake.com/api/products/searchProduct?symbol=MSFT&page=1&max=1
response:
body:
string:
'{"products": [{"id": "1cf93550-8eb4-4c32-a229-826cf8c1be59", "stakeInstrumentId":
"e3769c0b-456d-49dd-bec5-7a750c146d11", "instrumentTypeID": null, "symbol":
"MSFT", "description": "Microsoft Corporation is a technology company. The
Company develops, licenses, and supports a range of software products, services
and devices. The Company''s segments include Productivity and Business Processes,
Intelligent Cloud and More Personal Computing. The Company''s products include
operating systems; cross-device productivity applications; server applications;
business solution applications; desktop and server management tools; software
development tools; video games, and training and certification of computer
system integrators and developers. It also designs, manufactures, and sells
devices, including personal computers (PCs), tablets, gaming and entertainment
consoles, phones, other intelligent devices, and related accessories, that
integrate with its cloud-based offerings. It offers an array of services,
including cloud-based solutions that provide customers with software, services,
platforms, and content, and it provides solution support and consulting services.",
"category": "Stock", "currencyID": "USD", "urlImage": "https://d3an3cesqmrf1x.cloudfront.net/images/symbols/msft.png",
"sector": "Technology", "name": "Microsoft Corporation", "prePostMarketDailyReturn":
-0.06, "prePostMarketDailyReturnPercentage": -0.02, "dailyReturn": 4.09, "dailyReturnPercentage":
1.11, "lastTraded": 373.46, "monthlyReturn": 0.0, "yearlyReturnPercentage":
46.75, "yearlyReturnValue": 74.48, "popularity": 1717.0, "watched": 35555,
"news": 0, "bought": 157339, "viewed": 129200, "productType": "Instrument",
"exchange": "NSQ", "status": "ACTIVE", "type": "EQUITY", "encodedName": "microsoft-corporation-msft",
"period": "YEAR RETURN", "extendedHoursNotionalStatus": "ACTIVE", "inceptionDate":
511056000000, "marketCap": 3162416042769, "instrumentTags": [], "childInstruments":
[]}]}'
headers: {}
status:
code: 200
message: OK
version: 1
1 change: 1 addition & 0 deletions tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async def test_get_product(
@pytest.mark.parametrize(
"exchange, keyword", ((constant.ASX, "CBA"), (constant.NYSE, "MSFT"))
)
@pytest.mark.vcr()
@pytest.mark.asyncio
async def test_search_products(
tracing_client: StakeClient, exchange: BaseModel, keyword: str
Expand Down
Loading