-
Notifications
You must be signed in to change notification settings - Fork 346
add summaries endpoint #340
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
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
33948a4
summaries endpoint framework
chaig15 7bf6550
summaries endpoint framework
chaig15 c56d4dc
add models
chaig15 b2c9cb7
lint
chaig15 53fc809
add test
chaig15 6fb9e13
Fix any_of being a list
jbonzo 843979c
Test fixes
jbonzo eb007ec
lint
jbonzo 13a353b
fix list tickers
chaig15 6f18601
fix list tickers
chaig15 ff7320d
add new tests
chaig15 6e55e84
lint
chaig15 a4500a5
remove test and format json
chaig15 dd4d9e1
lint
chaig15 90f2fb5
fix test expected response for summaries
chaig15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -12,3 +12,4 @@ | |
| from .splits import * | ||
| from .tickers import * | ||
| from .trades import * | ||
| from .summaries import * | ||
This file contains hidden or 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,70 @@ | ||
| from sqlite3 import Timestamp | ||
| from typing import Optional | ||
| from ...modelclass import modelclass | ||
| from .tickers import Branding | ||
|
|
||
|
|
||
| @modelclass | ||
| class Session: | ||
| "Contains Session data for the summaries endpoint." | ||
| change: Optional[float] = None | ||
| change_percent: Optional[float] = None | ||
| early_trading_change: Optional[float] = None | ||
| early_trading_change_percent: Optional[float] = None | ||
| late_trading_change: Optional[float] = None | ||
| late_trading_change_percent: Optional[float] = None | ||
| close: Optional[float] = None | ||
| high: Optional[float] = None | ||
| low: Optional[float] = None | ||
| open: Optional[float] = None | ||
| previous_close: Optional[float] = None | ||
| volume: Optional[float] = None | ||
|
|
||
| @staticmethod | ||
| def from_dict(d): | ||
| return Session(**d) | ||
|
|
||
|
|
||
| @modelclass | ||
| class Options: | ||
| "Contains options data for the summaries endpoint" | ||
| contract_type: Optional[str] = None | ||
jbonzo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| exercise_style: Optional[str] = None | ||
| expiration_date: Optional[str] = None | ||
| shares_per_contract: Optional[float] = None | ||
| strike_price: Optional[float] = None | ||
| underlying_ticker: Optional[float] = None | ||
|
|
||
| @staticmethod | ||
| def from_dict(d): | ||
| return Options(**d) | ||
|
|
||
|
|
||
| @modelclass | ||
| class SummaryResult: | ||
| "Contains summary result data for a list of tickers" | ||
| price: Optional[float] = None | ||
| name: Optional[str] = None | ||
| ticker: Optional[str] = None | ||
jbonzo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| branding: Optional[Branding] = None | ||
| market_status: Optional[str] = None | ||
| type: Optional[str] = None | ||
| session: Optional[Session] = None | ||
jbonzo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| options: Optional[Options] = None | ||
| error: Optional[str] = None | ||
| message: Optional[str] = None | ||
|
|
||
| @staticmethod | ||
| def from_dict(d): | ||
| return SummaryResult( | ||
| price=d.get("price", None), | ||
| name=d.get("name", None), | ||
| ticker=d.get("ticker", None), | ||
| branding=None if "branding" not in d else Branding.from_dict(d["branding"]), | ||
| market_status=d.get("market_status", None), | ||
| type=d.get("type", None), | ||
| session=None if "session" not in d else Session.from_dict(d["session"]), | ||
| options=None if "options" not in d else Options.from_dict(d["options"]), | ||
| error=d.get("error", None), | ||
| message=d.get("message", None), | ||
| ) | ||
This file contains hidden or 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,33 @@ | ||
| from polygon.rest.models.summaries import SummaryResult | ||
| from .base import BaseClient | ||
| from typing import Optional, Any, Dict, List, Union, Iterator | ||
| from .models import Order | ||
| from urllib3 import HTTPResponse | ||
| from datetime import datetime, date | ||
|
|
||
|
|
||
| class SummariesClient(BaseClient): | ||
| def get_summaries( | ||
| self, | ||
| ticker_any_of: Optional[List[str]] = None, | ||
| params: Optional[Dict[str, Any]] = None, | ||
| raw: bool = False, | ||
| ) -> Union[List[SummaryResult], HTTPResponse]: | ||
| """ | ||
| GetSummaries retrieves summaries for the ticker list with the given params. | ||
| For more details see https://polygon.io/docs/stocks/get_v1_summaries. | ||
|
|
||
| :param ticker_any_of: The ticker symbol | ||
| :param params: Any additional query params | ||
| :param raw: Return raw object instead of results object | ||
| :return: SummaryResults | ||
| """ | ||
|
|
||
| url = f"/v1/summaries" | ||
| return self._get( | ||
| path=url, | ||
| params=self._get_params(self.get_summaries, locals()), | ||
| result_key="results", | ||
| deserializer=SummaryResult.from_dict, | ||
| raw=raw, | ||
| ) |
101 changes: 101 additions & 0 deletions
101
...mmaries&ticker.any_of=NCLH%2CO%3ANCLH221014C00005000%2CC%3AEURUSD%2CX%3ABTCUSD%2CAPx.json
This file contains hidden or 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,101 @@ | ||
| { | ||
| "request_id":"abc123", | ||
| "results":[ | ||
| { | ||
| "branding":{ | ||
| "icon_url":"https://api.polygon.io/icon.png", | ||
| "logo_url":"https://api.polygon.io/logo.svg" | ||
| }, | ||
| "market_status":"closed", | ||
| "name":"Norwegian Cruise Lines", | ||
| "price":22.3, | ||
| "session":{ | ||
| "change":-1.05, | ||
| "change_percent":-4.67, | ||
| "close":21.4, | ||
| "early_trading_change":-0.39, | ||
| "early_trading_change_percent":-0.07, | ||
| "high":22.49, | ||
| "late_trading_change":1.2, | ||
| "late_trading_change_percent":3.92, | ||
| "low":21.35, | ||
| "open":22.49, | ||
| "previous_close":22.45, | ||
| "volume":37 | ||
| }, | ||
| "ticker":"NCLH", | ||
| "type":"stocks" | ||
| }, | ||
| { | ||
| "market_status":"closed", | ||
| "name":"NCLH $5 Call", | ||
| "options":{ | ||
| "contract_type":"call", | ||
| "exercise_style":"american", | ||
| "expiration_date":"2022-10-14", | ||
| "shares_per_contract":100, | ||
| "strike_price":5, | ||
| "underlying_ticker":"NCLH" | ||
| }, | ||
| "price":6.6, | ||
| "session":{ | ||
| "change":-0.05, | ||
| "change_percent":-1.07, | ||
| "close":6.65, | ||
| "early_trading_change":-0.01, | ||
| "early_trading_change_percent":-0.03, | ||
| "high":7.01, | ||
| "late_trading_change":-0.4, | ||
| "late_trading_change_percent":-0.02, | ||
| "low":5.42, | ||
| "open":6.7, | ||
| "previous_close":6.71, | ||
| "volume":67 | ||
| }, | ||
| "ticker":"O:NCLH221014C00005000", | ||
| "type":"options" | ||
| }, | ||
| { | ||
| "market_status":"open", | ||
| "name":"Euro - United States Dollar", | ||
| "price":0.97989, | ||
| "session":{ | ||
| "change":-0.0001, | ||
| "change_percent":-0.67, | ||
| "close":0.97989, | ||
| "high":0.98999, | ||
| "low":0.96689, | ||
| "open":0.97889, | ||
| "previous_close":0.98001 | ||
| }, | ||
| "ticker":"C:EURUSD", | ||
| "type":"fx" | ||
| }, | ||
| { | ||
| "branding":{ | ||
| "icon_url":"https://api.polygon.io/icon.png", | ||
| "logo_url":"https://api.polygon.io/logo.svg" | ||
| }, | ||
| "market_status":"open", | ||
| "name":"Bitcoin - United States Dollar", | ||
| "price":32154.68, | ||
| "session":{ | ||
| "change":-201.23, | ||
| "change_percent":-0.77, | ||
| "close":32154.68, | ||
| "high":33124.28, | ||
| "low":28182.88, | ||
| "open":31129.32, | ||
| "previous_close":33362.18 | ||
| }, | ||
| "ticker":"X:BTCUSD", | ||
| "type":"crypto" | ||
| }, | ||
| { | ||
| "error":"NOT_FOUND", | ||
| "message":"Ticker not found.", | ||
| "ticker":"APx" | ||
| } | ||
| ], | ||
| "status":"OK" | ||
| } |
This file contains hidden or 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,106 @@ | ||
| from polygon.rest.models import SummaryResult, Branding, Session, Options | ||
| from base import BaseTest | ||
|
|
||
|
|
||
| class SummariesTest(BaseTest): | ||
| def test_get_summaries_list(self): | ||
| ticker_any_of = ["NCLH", "O:NCLH221014C00005000", "C:EURUSD", "X:BTCUSD", "APx"] | ||
| summary_results = self.c.get_summaries(ticker_any_of) | ||
| expected = [ | ||
| SummaryResult( | ||
| price=22.3, | ||
| name="Norwegian Cruise Lines", | ||
| ticker="NCLH", | ||
| branding=Branding( | ||
| icon_url="https://api.polygon.io/icon.png", | ||
| logo_url="https://api.polygon.io/logo.svg", | ||
| ), | ||
| market_status="closed", | ||
| type="stocks", | ||
| session=Session( | ||
| change=-1.05, | ||
| change_percent=-4.67, | ||
| close=21.4, | ||
| early_trading_change=-0.39, | ||
| early_trading_change_percent=-0.07, | ||
| high=22.49, | ||
| late_trading_change=1.2, | ||
| late_trading_change_percent=3.92, | ||
| low=21.35, | ||
| open=22.49, | ||
| previous_close=22.45, | ||
| volume=37, | ||
| ), | ||
| ), | ||
| SummaryResult( | ||
| price=6.6, | ||
| name="NCLH $5 Call", | ||
| ticker="O:NCLH221014C00005000", | ||
| market_status="closed", | ||
| type="options", | ||
| session=Session( | ||
| change=-0.05, | ||
| change_percent=-1.07, | ||
| close=6.65, | ||
| early_trading_change=-0.01, | ||
| early_trading_change_percent=-0.03, | ||
| high=7.01, | ||
| late_trading_change=-0.4, | ||
| late_trading_change_percent=-0.02, | ||
| low=5.42, | ||
| open=6.7, | ||
| previous_close=6.71, | ||
| volume=67, | ||
| ), | ||
| options=Options( | ||
| contract_type="call", | ||
| exercise_style="american", | ||
| expiration_date="2022-10-14", | ||
| shares_per_contract=100, | ||
| strike_price=5, | ||
| underlying_ticker="NCLH", | ||
| ), | ||
| ), | ||
| SummaryResult( | ||
| price=0.97989, | ||
| name="Euro - United States Dollar", | ||
| ticker="C:EURUSD", | ||
| market_status="open", | ||
| type="fx", | ||
| session=Session( | ||
| change=-0.0001, | ||
| change_percent=-0.67, | ||
| close=0.97989, | ||
| high=0.98999, | ||
| low=0.96689, | ||
| open=0.97889, | ||
| previous_close=0.98001, | ||
| ), | ||
| ), | ||
| SummaryResult( | ||
| price=32154.68, | ||
| name="Bitcoin - United States Dollar", | ||
| ticker="X:BTCUSD", | ||
| branding=Branding( | ||
| icon_url="https://api.polygon.io/icon.png", | ||
| logo_url="https://api.polygon.io/logo.svg", | ||
| ), | ||
| market_status="open", | ||
| type="crypto", | ||
| session=Session( | ||
| change=-201.23, | ||
| change_percent=-0.77, | ||
| close=32154.68, | ||
| high=33124.28, | ||
| low=28182.88, | ||
| open=31129.32, | ||
| previous_close=33362.18, | ||
| ), | ||
| ), | ||
| SummaryResult( | ||
| ticker="APx", | ||
| error="NOT_FOUND", | ||
| message="Ticker not found.", | ||
| ), | ||
| ] | ||
| self.assertEqual(summary_results, expected) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.