From 85c2a5d9969ef553f2a813d83b219ce01a217df6 Mon Sep 17 00:00:00 2001 From: justinpolygon <123573436+justinpolygon@users.noreply.github.com> Date: Wed, 29 Mar 2023 05:29:02 -0700 Subject: [PATCH 1/4] Add crypto, forex, and indices examples --- examples/rest/crypto-aggregates_bars.py | 27 +++++++++++ examples/rest/crypto-conditions.py | 13 ++++++ examples/rest/crypto-daily_open_close.py | 16 +++++++ examples/rest/crypto-exchanges.py | 27 +++++++++++ examples/rest/crypto-grouped_daily_bars.py | 22 +++++++++ .../crypto-last_trade_for_a_crypto_pair.py | 15 +++++++ examples/rest/crypto-market_holidays.py | 22 +++++++++ examples/rest/crypto-market_status.py | 11 +++++ examples/rest/crypto-previous_close.py | 14 ++++++ examples/rest/crypto-snapshots_all_tickers.py | 45 +++++++++++++++++++ .../rest/crypto-snapshots_gainers_losers.py | 43 ++++++++++++++++++ examples/rest/crypto-snapshots_ticker.py | 11 +++++ .../crypto-snapshots_ticker_full_book_l2.py | 13 ++++++ .../rest/crypto-technical_indicators_ema.py | 11 +++++ .../rest/crypto-technical_indicators_macd.py | 11 +++++ .../rest/crypto-technical_indicators_rsi.py | 11 +++++ .../rest/crypto-technical_indicators_sma.py | 11 +++++ examples/rest/crypto-tickers.py | 13 ++++++ examples/rest/crypto-trades.py | 15 +++++++ examples/rest/forex-aggregates_bars.py | 27 +++++++++++ examples/rest/forex-conditions.py | 13 ++++++ examples/rest/forex-exchanges.py | 27 +++++++++++ examples/rest/forex-grouped_daily_bars.py | 22 +++++++++ .../forex-last_quote_for_a_currency_pair.py | 15 +++++++ examples/rest/forex-market_holidays.py | 22 +++++++++ examples/rest/forex-market_status.py | 11 +++++ examples/rest/forex-previous_close.py | 14 ++++++ examples/rest/forex-quotes.py | 13 ++++++ .../forex-real-time_currency_conversion.py | 15 +++++++ examples/rest/forex-snapshots_all_tickers.py | 45 +++++++++++++++++++ .../rest/forex-snapshots_gainers_losers.py | 43 ++++++++++++++++++ examples/rest/forex-snapshots_ticker.py | 11 +++++ .../rest/forex-technical_indicators_ema.py | 11 +++++ .../rest/forex-technical_indicators_macd.py | 11 +++++ .../rest/forex-technical_indicators_rsi.py | 11 +++++ .../rest/forex-technical_indicators_sma.py | 11 +++++ examples/rest/forex-tickers.py | 13 ++++++ examples/rest/indices-aggregates_bars.py | 27 +++++++++++ examples/rest/indices-daily_open_close.py | 16 +++++++ examples/rest/indices-market_holidays.py | 22 +++++++++ examples/rest/indices-market_status.py | 11 +++++ examples/rest/indices-previous_close.py | 14 ++++++ examples/rest/indices-snapshots.py | 13 ++++++ .../rest/indices-technical_indicators_ema.py | 11 +++++ .../rest/indices-technical_indicators_macd.py | 11 +++++ .../rest/indices-technical_indicators_rsi.py | 11 +++++ .../rest/indices-technical_indicators_sma.py | 11 +++++ examples/rest/indices-ticker_types.py | 20 +++++++++ examples/rest/indices-tickers.py | 13 ++++++ examples/rest/options-market_holidays.py | 2 +- 50 files changed, 867 insertions(+), 1 deletion(-) create mode 100644 examples/rest/crypto-aggregates_bars.py create mode 100644 examples/rest/crypto-conditions.py create mode 100644 examples/rest/crypto-daily_open_close.py create mode 100644 examples/rest/crypto-exchanges.py create mode 100644 examples/rest/crypto-grouped_daily_bars.py create mode 100644 examples/rest/crypto-last_trade_for_a_crypto_pair.py create mode 100644 examples/rest/crypto-market_holidays.py create mode 100644 examples/rest/crypto-market_status.py create mode 100644 examples/rest/crypto-previous_close.py create mode 100644 examples/rest/crypto-snapshots_all_tickers.py create mode 100644 examples/rest/crypto-snapshots_gainers_losers.py create mode 100644 examples/rest/crypto-snapshots_ticker.py create mode 100644 examples/rest/crypto-snapshots_ticker_full_book_l2.py create mode 100644 examples/rest/crypto-technical_indicators_ema.py create mode 100644 examples/rest/crypto-technical_indicators_macd.py create mode 100644 examples/rest/crypto-technical_indicators_rsi.py create mode 100644 examples/rest/crypto-technical_indicators_sma.py create mode 100644 examples/rest/crypto-tickers.py create mode 100644 examples/rest/crypto-trades.py create mode 100644 examples/rest/forex-aggregates_bars.py create mode 100644 examples/rest/forex-conditions.py create mode 100644 examples/rest/forex-exchanges.py create mode 100644 examples/rest/forex-grouped_daily_bars.py create mode 100644 examples/rest/forex-last_quote_for_a_currency_pair.py create mode 100644 examples/rest/forex-market_holidays.py create mode 100644 examples/rest/forex-market_status.py create mode 100644 examples/rest/forex-previous_close.py create mode 100644 examples/rest/forex-quotes.py create mode 100644 examples/rest/forex-real-time_currency_conversion.py create mode 100644 examples/rest/forex-snapshots_all_tickers.py create mode 100644 examples/rest/forex-snapshots_gainers_losers.py create mode 100644 examples/rest/forex-snapshots_ticker.py create mode 100644 examples/rest/forex-technical_indicators_ema.py create mode 100644 examples/rest/forex-technical_indicators_macd.py create mode 100644 examples/rest/forex-technical_indicators_rsi.py create mode 100644 examples/rest/forex-technical_indicators_sma.py create mode 100644 examples/rest/forex-tickers.py create mode 100644 examples/rest/indices-aggregates_bars.py create mode 100644 examples/rest/indices-daily_open_close.py create mode 100644 examples/rest/indices-market_holidays.py create mode 100644 examples/rest/indices-market_status.py create mode 100644 examples/rest/indices-previous_close.py create mode 100644 examples/rest/indices-snapshots.py create mode 100644 examples/rest/indices-technical_indicators_ema.py create mode 100644 examples/rest/indices-technical_indicators_macd.py create mode 100644 examples/rest/indices-technical_indicators_rsi.py create mode 100644 examples/rest/indices-technical_indicators_sma.py create mode 100644 examples/rest/indices-ticker_types.py create mode 100644 examples/rest/indices-tickers.py diff --git a/examples/rest/crypto-aggregates_bars.py b/examples/rest/crypto-aggregates_bars.py new file mode 100644 index 00000000..b75ea762 --- /dev/null +++ b/examples/rest/crypto-aggregates_bars.py @@ -0,0 +1,27 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/crypto/get_v2_aggs_ticker__cryptoticker__range__multiplier___timespan___from___to +# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#polygon.RESTClient.get_aggs + +# API key injected below for easy use. If not provided, the script will attempt +# to use the environment variable "POLYGON_API_KEY". +# +# setx POLYGON_API_KEY "" <- windows +# export POLYGON_API_KEY="" <- mac/linux +# +# Note: To persist the environment variable you need to add the above command +# to the shell startup script (e.g. .bashrc or .bash_profile. +# +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +aggs = client.get_aggs( + "X:BTCUSD", + 1, + "day", + "2023-01-30", + "2023-02-03", +) + +print(aggs) diff --git a/examples/rest/crypto-conditions.py b/examples/rest/crypto-conditions.py new file mode 100644 index 00000000..93e3feda --- /dev/null +++ b/examples/rest/crypto-conditions.py @@ -0,0 +1,13 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/crypto/get_v3_reference_conditions +# https://polygon-api-client.readthedocs.io/en/latest/Reference.html#list-conditions + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +conditions = [] +for c in client.list_conditions("crypto", limit=1000): + conditions.append(c) +print(conditions) diff --git a/examples/rest/crypto-daily_open_close.py b/examples/rest/crypto-daily_open_close.py new file mode 100644 index 00000000..8ff3ad41 --- /dev/null +++ b/examples/rest/crypto-daily_open_close.py @@ -0,0 +1,16 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/crypto/get_v1_open-close_crypto__from___to___date +# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#get-daily-open-close-agg + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +# make request +request = client.get_daily_open_close_agg( + "X:BTCUSD", + "2023-01-09", +) + +print(request) diff --git a/examples/rest/crypto-exchanges.py b/examples/rest/crypto-exchanges.py new file mode 100644 index 00000000..c5c2cf79 --- /dev/null +++ b/examples/rest/crypto-exchanges.py @@ -0,0 +1,27 @@ +from polygon import RESTClient +from polygon.rest.models import ( + Exchange, +) + +# docs +# https://polygon.io/docs/crypto/get_v3_reference_exchanges +# https://polygon-api-client.readthedocs.io/en/latest/Reference.html#get-exchanges + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +exchanges = client.get_exchanges("crypto") +print(exchanges) + +# loop over exchanges +for exchange in exchanges: + + # verify this is an exchange + if isinstance(exchange, Exchange): + + # print exchange info + print( + "{:<15}{} ({})".format( + exchange.asset_class, exchange.name, exchange.operating_mic + ) + ) diff --git a/examples/rest/crypto-grouped_daily_bars.py b/examples/rest/crypto-grouped_daily_bars.py new file mode 100644 index 00000000..6ca01bc0 --- /dev/null +++ b/examples/rest/crypto-grouped_daily_bars.py @@ -0,0 +1,22 @@ +from polygon import RESTClient +import pprint + +# docs +# https://polygon.io/docs/crypto/get_v2_aggs_grouped_locale_global_market_crypto__date +# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#get-grouped-daily-aggs + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +grouped = client.get_grouped_daily_aggs( + "2023-01-09", + locale='global', + market_type='crypto' +) + +# print(grouped) + +# pprint (short for "pretty-print") is a module that provides a more human- +# readable output format for data structures. +pp = pprint.PrettyPrinter(indent=2) +pp.pprint(grouped) diff --git a/examples/rest/crypto-last_trade_for_a_crypto_pair.py b/examples/rest/crypto-last_trade_for_a_crypto_pair.py new file mode 100644 index 00000000..78abc11f --- /dev/null +++ b/examples/rest/crypto-last_trade_for_a_crypto_pair.py @@ -0,0 +1,15 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/crypto/get_v1_last_crypto__from___to +# https://polygon-api-client.readthedocs.io/en/latest/Trades.html#get-last-crypto-trade + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +trade = client.get_last_crypto_trade( + "BTC", + "USD" +) + +print(trade) diff --git a/examples/rest/crypto-market_holidays.py b/examples/rest/crypto-market_holidays.py new file mode 100644 index 00000000..13113917 --- /dev/null +++ b/examples/rest/crypto-market_holidays.py @@ -0,0 +1,22 @@ +from polygon import RESTClient +from polygon.rest.models import ( + MarketHoliday, +) + +# docs +# https://polygon.io/docs/crypto/get_v1_marketstatus_upcoming +# https://polygon-api-client.readthedocs.io/en/latest/Reference.html#get-market-holidays + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +holidays = client.get_market_holidays() +# print(holidays) + +# print date, name, and exchange +for holiday in holidays: + + # verify this is an exchange + if isinstance(holiday, MarketHoliday): + + print("{:<15}{:<15} ({})".format(holiday.date, holiday.name, holiday.exchange)) diff --git a/examples/rest/crypto-market_status.py b/examples/rest/crypto-market_status.py new file mode 100644 index 00000000..4265997c --- /dev/null +++ b/examples/rest/crypto-market_status.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/crypto/get_v1_marketstatus_now +# https://polygon-api-client.readthedocs.io/en/latest/Reference.html#get-market-status + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +result = client.get_market_status() +print(result) diff --git a/examples/rest/crypto-previous_close.py b/examples/rest/crypto-previous_close.py new file mode 100644 index 00000000..bf309fed --- /dev/null +++ b/examples/rest/crypto-previous_close.py @@ -0,0 +1,14 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/crypto/get_v2_aggs_ticker__cryptoticker__prev +# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#get-previous-close-agg + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +aggs = client.get_previous_close_agg( + "X:BTCUSD", +) + +print(aggs) diff --git a/examples/rest/crypto-snapshots_all_tickers.py b/examples/rest/crypto-snapshots_all_tickers.py new file mode 100644 index 00000000..c7b6baef --- /dev/null +++ b/examples/rest/crypto-snapshots_all_tickers.py @@ -0,0 +1,45 @@ +from polygon import RESTClient +from polygon.rest.models import ( + TickerSnapshot, + Agg, +) + +# docs +# https://polygon.io/docs/crypto/get_v2_snapshot_locale_global_markets_crypto_tickers +# https://polygon-api-client.readthedocs.io/en/latest/Snapshot.html#get-all-snapshots + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +snapshot = client.get_snapshot_all("crypto") # all tickers + +# print raw values +print(snapshot) + +# crunch some numbers +for item in snapshot: + + # verify this is an TickerSnapshot + if isinstance(item, TickerSnapshot): + + # verify this is an Agg + if isinstance(item.prev_day, Agg): + + # verify this is a float + if isinstance(item.prev_day.open, float) and isinstance( + item.prev_day.close, float + ): + + percent_change = ( + (item.prev_day.close - item.prev_day.open) + / item.prev_day.open + * 100 + ) + print( + "{:<15}{:<15}{:<15}{:.2f} %".format( + item.ticker, + item.prev_day.open, + item.prev_day.close, + percent_change, + ) + ) diff --git a/examples/rest/crypto-snapshots_gainers_losers.py b/examples/rest/crypto-snapshots_gainers_losers.py new file mode 100644 index 00000000..61a51fa1 --- /dev/null +++ b/examples/rest/crypto-snapshots_gainers_losers.py @@ -0,0 +1,43 @@ +from polygon import RESTClient +from polygon.rest.models import ( + TickerSnapshot, +) + +# docs +# https://polygon.io/docs/crypto/get_v2_snapshot_locale_global_markets_crypto__direction +# https://polygon-api-client.readthedocs.io/en/latest/Snapshot.html#get-gainers-losers-snapshot + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +# get gainers +gainers = client.get_snapshot_direction("crypto", "gainers") +# print(gainers) + +# print ticker with % change +for gainer in gainers: + + # verify this is a TickerSnapshot + if isinstance(gainer, TickerSnapshot): + + # verify this is a float + if isinstance(gainer.todays_change_percent, float): + + print("{:<15}{:.2f} %".format(gainer.ticker, gainer.todays_change_percent)) + +print() + +# get losers +losers = client.get_snapshot_direction("crypto", "losers") +# print(losers) + +# print ticker with % change +for loser in losers: + + # verify this is a TickerSnapshot + if isinstance(loser, TickerSnapshot): + + # verify this is a float + if isinstance(loser.todays_change_percent, float): + + print("{:<15}{:.2f} %".format(loser.ticker, loser.todays_change_percent)) diff --git a/examples/rest/crypto-snapshots_ticker.py b/examples/rest/crypto-snapshots_ticker.py new file mode 100644 index 00000000..31a48ebd --- /dev/null +++ b/examples/rest/crypto-snapshots_ticker.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/crypto/get_v2_snapshot_locale_global_markets_crypto_tickers__ticker +# https://polygon-api-client.readthedocs.io/en/latest/Snapshot.html#get-ticker-snapshot + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +ticker = client.get_snapshot_ticker("crypto", "X:BTCUSD") +print(ticker) diff --git a/examples/rest/crypto-snapshots_ticker_full_book_l2.py b/examples/rest/crypto-snapshots_ticker_full_book_l2.py new file mode 100644 index 00000000..38d239cf --- /dev/null +++ b/examples/rest/crypto-snapshots_ticker_full_book_l2.py @@ -0,0 +1,13 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/crypto/get_v2_snapshot_locale_global_markets_crypto_tickers__ticker__book +# https://polygon-api-client.readthedocs.io/en/latest/Snapshot.html#get-crypto-l2-book-snapshot + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +snapshot = client.get_snapshot_crypto_book("X:BTCUSD") + +# print raw values +print(snapshot) diff --git a/examples/rest/crypto-technical_indicators_ema.py b/examples/rest/crypto-technical_indicators_ema.py new file mode 100644 index 00000000..edd45dee --- /dev/null +++ b/examples/rest/crypto-technical_indicators_ema.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/crypto/get_v1_indicators_ema__cryptoticker +# https://github.com/polygon-io/client-python/blob/master/polygon/rest/indicators.py + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +ema = client.get_ema("X:BTCUSD") +print(ema) diff --git a/examples/rest/crypto-technical_indicators_macd.py b/examples/rest/crypto-technical_indicators_macd.py new file mode 100644 index 00000000..d1f60337 --- /dev/null +++ b/examples/rest/crypto-technical_indicators_macd.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/crypto/get_v1_indicators_macd__cryptoticker +# https://github.com/polygon-io/client-python/blob/master/polygon/rest/indicators.py + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +macd = client.get_macd("X:BTCUSD") +print(macd) diff --git a/examples/rest/crypto-technical_indicators_rsi.py b/examples/rest/crypto-technical_indicators_rsi.py new file mode 100644 index 00000000..38423590 --- /dev/null +++ b/examples/rest/crypto-technical_indicators_rsi.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/crypto/get_v1_indicators_rsi__cryptoticker +# https://github.com/polygon-io/client-python/blob/master/polygon/rest/indicators.py + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +rsi = client.get_rsi("X:BTCUSD") +print(rsi) diff --git a/examples/rest/crypto-technical_indicators_sma.py b/examples/rest/crypto-technical_indicators_sma.py new file mode 100644 index 00000000..072c205b --- /dev/null +++ b/examples/rest/crypto-technical_indicators_sma.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/crypto/get_v1_indicators_sma__cryptoticker +# https://github.com/polygon-io/client-python/blob/master/polygon/rest/indicators.py + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +sma = client.get_sma("X:BTCUSD") +print(sma) \ No newline at end of file diff --git a/examples/rest/crypto-tickers.py b/examples/rest/crypto-tickers.py new file mode 100644 index 00000000..922e8ca1 --- /dev/null +++ b/examples/rest/crypto-tickers.py @@ -0,0 +1,13 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/crypto/get_v3_reference_tickers +# https://polygon-api-client.readthedocs.io/en/latest/Reference.html#list-tickers + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +tickers = [] +for t in client.list_tickers(market='crypto', limit=1000): + tickers.append(t) +print(tickers) diff --git a/examples/rest/crypto-trades.py b/examples/rest/crypto-trades.py new file mode 100644 index 00000000..7cafd989 --- /dev/null +++ b/examples/rest/crypto-trades.py @@ -0,0 +1,15 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/crypto/get_v3_trades__cryptoticker +# https://polygon-api-client.readthedocs.io/en/latest/Trades.html#polygon.RESTClient.list_trades + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +trades = [] +for t in client.list_trades("X:BTC-USD", "2023-02-01", limit=50000): + trades.append(t) + +# prints each trade that took place +print(trades) diff --git a/examples/rest/forex-aggregates_bars.py b/examples/rest/forex-aggregates_bars.py new file mode 100644 index 00000000..56f50aa6 --- /dev/null +++ b/examples/rest/forex-aggregates_bars.py @@ -0,0 +1,27 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/forex/get_v2_aggs_ticker__forexticker__range__multiplier___timespan___from___to +# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#polygon.RESTClient.get_aggs + +# API key injected below for easy use. If not provided, the script will attempt +# to use the environment variable "POLYGON_API_KEY". +# +# setx POLYGON_API_KEY "" <- windows +# export POLYGON_API_KEY="" <- mac/linux +# +# Note: To persist the environment variable you need to add the above command +# to the shell startup script (e.g. .bashrc or .bash_profile. +# +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +aggs = client.get_aggs( + "C:EURUSD", + 1, + "day", + "2023-01-30", + "2023-02-03", +) + +print(aggs) diff --git a/examples/rest/forex-conditions.py b/examples/rest/forex-conditions.py new file mode 100644 index 00000000..fca1e887 --- /dev/null +++ b/examples/rest/forex-conditions.py @@ -0,0 +1,13 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/forex/get_v3_reference_conditions +# https://polygon-api-client.readthedocs.io/en/latest/Reference.html#list-conditions + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +conditions = [] +for c in client.list_conditions("fx", limit=1000): + conditions.append(c) +print(conditions) diff --git a/examples/rest/forex-exchanges.py b/examples/rest/forex-exchanges.py new file mode 100644 index 00000000..a573a19b --- /dev/null +++ b/examples/rest/forex-exchanges.py @@ -0,0 +1,27 @@ +from polygon import RESTClient +from polygon.rest.models import ( + Exchange, +) + +# docs +# https://polygon.io/docs/options/get_v3_reference_exchanges +# https://polygon-api-client.readthedocs.io/en/latest/Reference.html#get-exchanges + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +exchanges = client.get_exchanges("fx") +print(exchanges) + +# loop over exchanges +for exchange in exchanges: + + # verify this is an exchange + if isinstance(exchange, Exchange): + + # print exchange info + print( + "{:<15}{} ({})".format( + exchange.asset_class, exchange.name, exchange.operating_mic + ) + ) diff --git a/examples/rest/forex-grouped_daily_bars.py b/examples/rest/forex-grouped_daily_bars.py new file mode 100644 index 00000000..6f4bed97 --- /dev/null +++ b/examples/rest/forex-grouped_daily_bars.py @@ -0,0 +1,22 @@ +from polygon import RESTClient +import pprint + +# docs +# https://polygon.io/docs/forex/get_v2_aggs_grouped_locale_global_market_fx__date +# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#get-grouped-daily-aggs + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +grouped = client.get_grouped_daily_aggs( + "2023-03-27", + locale='global', + market_type='fx', +) + +# print(grouped) + +# pprint (short for "pretty-print") is a module that provides a more human- +# readable output format for data structures. +pp = pprint.PrettyPrinter(indent=2) +pp.pprint(grouped) diff --git a/examples/rest/forex-last_quote_for_a_currency_pair.py b/examples/rest/forex-last_quote_for_a_currency_pair.py new file mode 100644 index 00000000..8b3c78b1 --- /dev/null +++ b/examples/rest/forex-last_quote_for_a_currency_pair.py @@ -0,0 +1,15 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/forex/get_v1_last_quote_currencies__from___to +# https://polygon-api-client.readthedocs.io/en/latest/Quotes.html#get-last-forex-quote + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +quote = client.get_last_forex_quote( + "AUD", + "USD", +) + +print(quote) diff --git a/examples/rest/forex-market_holidays.py b/examples/rest/forex-market_holidays.py new file mode 100644 index 00000000..85489844 --- /dev/null +++ b/examples/rest/forex-market_holidays.py @@ -0,0 +1,22 @@ +from polygon import RESTClient +from polygon.rest.models import ( + MarketHoliday, +) + +# docs +# https://polygon.io/docs/forex/get_v1_marketstatus_upcoming +# https://polygon-api-client.readthedocs.io/en/latest/Reference.html#get-market-holidays + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +holidays = client.get_market_holidays() +# print(holidays) + +# print date, name, and exchange +for holiday in holidays: + + # verify this is an exchange + if isinstance(holiday, MarketHoliday): + + print("{:<15}{:<15} ({})".format(holiday.date, holiday.name, holiday.exchange)) diff --git a/examples/rest/forex-market_status.py b/examples/rest/forex-market_status.py new file mode 100644 index 00000000..06f544cc --- /dev/null +++ b/examples/rest/forex-market_status.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/forex/get_v1_marketstatus_now +# https://polygon-api-client.readthedocs.io/en/latest/Reference.html#get-market-status + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +result = client.get_market_status() +print(result) diff --git a/examples/rest/forex-previous_close.py b/examples/rest/forex-previous_close.py new file mode 100644 index 00000000..0de11709 --- /dev/null +++ b/examples/rest/forex-previous_close.py @@ -0,0 +1,14 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/forex/get_v2_aggs_ticker__forexticker__prev +# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#get-previous-close-agg + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +aggs = client.get_previous_close_agg( + "C:EURUSD", +) + +print(aggs) diff --git a/examples/rest/forex-quotes.py b/examples/rest/forex-quotes.py new file mode 100644 index 00000000..880ebca8 --- /dev/null +++ b/examples/rest/forex-quotes.py @@ -0,0 +1,13 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/forex/get_v3_quotes__fxticker +# https://polygon-api-client.readthedocs.io/en/latest/Quotes.html#list-quotes + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +quotes = [] +for t in client.list_quotes("C:EUR-USD", "2023-02-01", limit=50000): + quotes.append(t) +print(quotes) diff --git a/examples/rest/forex-real-time_currency_conversion.py b/examples/rest/forex-real-time_currency_conversion.py new file mode 100644 index 00000000..b50099c9 --- /dev/null +++ b/examples/rest/forex-real-time_currency_conversion.py @@ -0,0 +1,15 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/forex/get_v1_conversion__from___to +# https://polygon-api-client.readthedocs.io/en/latest/Quotes.html#get-real-time-currency-conversion + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +rate = client.get_real_time_currency_conversion( + "AUD", + "USD", +) + +print(rate) diff --git a/examples/rest/forex-snapshots_all_tickers.py b/examples/rest/forex-snapshots_all_tickers.py new file mode 100644 index 00000000..ffb75e26 --- /dev/null +++ b/examples/rest/forex-snapshots_all_tickers.py @@ -0,0 +1,45 @@ +from polygon import RESTClient +from polygon.rest.models import ( + TickerSnapshot, + Agg, +) + +# docs +# https://polygon.io/docs/forex/get_v2_snapshot_locale_global_markets_forex_tickers +# https://polygon-api-client.readthedocs.io/en/latest/Snapshot.html#get-all-snapshots + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +snapshot = client.get_snapshot_all("forex") # all tickers + +# print raw values +print(snapshot) + +# crunch some numbers +for item in snapshot: + + # verify this is an TickerSnapshot + if isinstance(item, TickerSnapshot): + + # verify this is an Agg + if isinstance(item.prev_day, Agg): + + # verify this is a float + if isinstance(item.prev_day.open, float) and isinstance( + item.prev_day.close, float + ): + + percent_change = ( + (item.prev_day.close - item.prev_day.open) + / item.prev_day.open + * 100 + ) + print( + "{:<15}{:<15}{:<15}{:.2f} %".format( + item.ticker, + item.prev_day.open, + item.prev_day.close, + percent_change, + ) + ) diff --git a/examples/rest/forex-snapshots_gainers_losers.py b/examples/rest/forex-snapshots_gainers_losers.py new file mode 100644 index 00000000..16a59149 --- /dev/null +++ b/examples/rest/forex-snapshots_gainers_losers.py @@ -0,0 +1,43 @@ +from polygon import RESTClient +from polygon.rest.models import ( + TickerSnapshot, +) + +# docs +# https://polygon.io/docs/forex/get_v2_snapshot_locale_global_markets_forex__direction +# https://polygon-api-client.readthedocs.io/en/latest/Snapshot.html#get-gainers-losers-snapshot + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +# get gainers +gainers = client.get_snapshot_direction("forex", "gainers") +# print(gainers) + +# print ticker with % change +for gainer in gainers: + + # verify this is a TickerSnapshot + if isinstance(gainer, TickerSnapshot): + + # verify this is a float + if isinstance(gainer.todays_change_percent, float): + + print("{:<15}{:.2f} %".format(gainer.ticker, gainer.todays_change_percent)) + +print() + +# get losers +losers = client.get_snapshot_direction("forex", "losers") +# print(losers) + +# print ticker with % change +for loser in losers: + + # verify this is a TickerSnapshot + if isinstance(loser, TickerSnapshot): + + # verify this is a float + if isinstance(loser.todays_change_percent, float): + + print("{:<15}{:.2f} %".format(loser.ticker, loser.todays_change_percent)) diff --git a/examples/rest/forex-snapshots_ticker.py b/examples/rest/forex-snapshots_ticker.py new file mode 100644 index 00000000..9dbfc0ff --- /dev/null +++ b/examples/rest/forex-snapshots_ticker.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/forex/get_v2_snapshot_locale_global_markets_forex_tickers__ticker +# https://polygon-api-client.readthedocs.io/en/latest/Snapshot.html#get-ticker-snapshot + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +ticker = client.get_snapshot_ticker("forex", "C:EURUSD") +print(ticker) diff --git a/examples/rest/forex-technical_indicators_ema.py b/examples/rest/forex-technical_indicators_ema.py new file mode 100644 index 00000000..ab927dcb --- /dev/null +++ b/examples/rest/forex-technical_indicators_ema.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/forex/get_v1_indicators_ema__fxticker +# https://github.com/polygon-io/client-python/blob/master/polygon/rest/indicators.py + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +ema = client.get_ema("C:EURUSD") +print(ema) diff --git a/examples/rest/forex-technical_indicators_macd.py b/examples/rest/forex-technical_indicators_macd.py new file mode 100644 index 00000000..2613f61a --- /dev/null +++ b/examples/rest/forex-technical_indicators_macd.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/forex/get_v1_indicators_macd__fxticker +# https://github.com/polygon-io/client-python/blob/master/polygon/rest/indicators.py + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +macd = client.get_macd("C:EURUSD") +print(macd) diff --git a/examples/rest/forex-technical_indicators_rsi.py b/examples/rest/forex-technical_indicators_rsi.py new file mode 100644 index 00000000..0b3001ac --- /dev/null +++ b/examples/rest/forex-technical_indicators_rsi.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/forex/get_v1_indicators_rsi__fxticker +# https://github.com/polygon-io/client-python/blob/master/polygon/rest/indicators.py + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +rsi = client.get_rsi("C:EURUSD") +print(rsi) diff --git a/examples/rest/forex-technical_indicators_sma.py b/examples/rest/forex-technical_indicators_sma.py new file mode 100644 index 00000000..22389b63 --- /dev/null +++ b/examples/rest/forex-technical_indicators_sma.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/forex/get_v1_indicators_sma__fxticker +# https://github.com/polygon-io/client-python/blob/master/polygon/rest/indicators.py + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +sma = client.get_sma("C:EURUSD") +print(sma) diff --git a/examples/rest/forex-tickers.py b/examples/rest/forex-tickers.py new file mode 100644 index 00000000..8a3e13f8 --- /dev/null +++ b/examples/rest/forex-tickers.py @@ -0,0 +1,13 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/forex/get_v3_reference_tickers +# https://polygon-api-client.readthedocs.io/en/latest/Reference.html#list-tickers + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +tickers = [] +for t in client.list_tickers(market='fx', limit=1000): + tickers.append(t) +print(tickers) diff --git a/examples/rest/indices-aggregates_bars.py b/examples/rest/indices-aggregates_bars.py new file mode 100644 index 00000000..b5305648 --- /dev/null +++ b/examples/rest/indices-aggregates_bars.py @@ -0,0 +1,27 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/indices/get_v2_aggs_ticker__indicesticker__range__multiplier___timespan___from___to +# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#polygon.RESTClient.get_aggs + +# API key injected below for easy use. If not provided, the script will attempt +# to use the environment variable "POLYGON_API_KEY". +# +# setx POLYGON_API_KEY "" <- windows +# export POLYGON_API_KEY="" <- mac/linux +# +# Note: To persist the environment variable you need to add the above command +# to the shell startup script (e.g. .bashrc or .bash_profile. +# +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +aggs = client.get_aggs( + "I:SPX", + 1, + "day", + "2023-03-10", + "2023-03-10", +) + +print(aggs) diff --git a/examples/rest/indices-daily_open_close.py b/examples/rest/indices-daily_open_close.py new file mode 100644 index 00000000..f84a51ab --- /dev/null +++ b/examples/rest/indices-daily_open_close.py @@ -0,0 +1,16 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/indices/get_v1_open-close__indicesticker___date +# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#get-daily-open-close-agg + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +# make request +request = client.get_daily_open_close_agg( + "I:SPX", + "2023-03-28", +) + +print(request) diff --git a/examples/rest/indices-market_holidays.py b/examples/rest/indices-market_holidays.py new file mode 100644 index 00000000..c1e94932 --- /dev/null +++ b/examples/rest/indices-market_holidays.py @@ -0,0 +1,22 @@ +from polygon import RESTClient +from polygon.rest.models import ( + MarketHoliday, +) + +# docs +# https://polygon.io/docs/indices/get_v1_marketstatus_upcoming +# https://polygon-api-client.readthedocs.io/en/latest/Reference.html#get-market-holidays + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +holidays = client.get_market_holidays() +# print(holidays) + +# print date, name, and exchange +for holiday in holidays: + + # verify this is an exchange + if isinstance(holiday, MarketHoliday): + + print("{:<15}{:<15} ({})".format(holiday.date, holiday.name, holiday.exchange)) diff --git a/examples/rest/indices-market_status.py b/examples/rest/indices-market_status.py new file mode 100644 index 00000000..6c74dee3 --- /dev/null +++ b/examples/rest/indices-market_status.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/indices/get_v1_marketstatus_now +# https://polygon-api-client.readthedocs.io/en/latest/Reference.html#get-market-status + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +result = client.get_market_status() +print(result) diff --git a/examples/rest/indices-previous_close.py b/examples/rest/indices-previous_close.py new file mode 100644 index 00000000..8774bd6e --- /dev/null +++ b/examples/rest/indices-previous_close.py @@ -0,0 +1,14 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/indices/get_v2_aggs_ticker__indicesticker__prev +# https://polygon-api-client.readthedocs.io/en/latest/Aggs.html#get-previous-close-agg + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +aggs = client.get_previous_close_agg( + "I:SPX", +) + +print(aggs) diff --git a/examples/rest/indices-snapshots.py b/examples/rest/indices-snapshots.py new file mode 100644 index 00000000..ed1560cc --- /dev/null +++ b/examples/rest/indices-snapshots.py @@ -0,0 +1,13 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/indices/get_v3_snapshot_indices +# https://github.com/polygon-io/client-python/blob/master/polygon/rest/snapshot.py# + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +snapshot = client.get_snapshot_indices("I:SPX") + +# print raw values +print(snapshot) diff --git a/examples/rest/indices-technical_indicators_ema.py b/examples/rest/indices-technical_indicators_ema.py new file mode 100644 index 00000000..bbf9bc39 --- /dev/null +++ b/examples/rest/indices-technical_indicators_ema.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/indices/get_v1_indicators_ema__indicesticker +# https://github.com/polygon-io/client-python/blob/master/polygon/rest/indicators.py + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +ema = client.get_ema("I:SPX") +print(ema) diff --git a/examples/rest/indices-technical_indicators_macd.py b/examples/rest/indices-technical_indicators_macd.py new file mode 100644 index 00000000..751258aa --- /dev/null +++ b/examples/rest/indices-technical_indicators_macd.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/indices/get_v1_indicators_macd__indicesticker +# https://github.com/polygon-io/client-python/blob/master/polygon/rest/indicators.py + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +macd = client.get_macd("I:SPX") +print(macd) diff --git a/examples/rest/indices-technical_indicators_rsi.py b/examples/rest/indices-technical_indicators_rsi.py new file mode 100644 index 00000000..93f1a16b --- /dev/null +++ b/examples/rest/indices-technical_indicators_rsi.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/indices/get_v1_indicators_rsi__indicesticker +# https://github.com/polygon-io/client-python/blob/master/polygon/rest/indicators.py + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +rsi = client.get_rsi("I:SPX") +print(rsi) diff --git a/examples/rest/indices-technical_indicators_sma.py b/examples/rest/indices-technical_indicators_sma.py new file mode 100644 index 00000000..5343e54d --- /dev/null +++ b/examples/rest/indices-technical_indicators_sma.py @@ -0,0 +1,11 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/indices/get_v1_indicators_sma__indicesticker +# https://github.com/polygon-io/client-python/blob/master/polygon/rest/indicators.py + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +sma = client.get_sma("I:SPX") +print(sma) diff --git a/examples/rest/indices-ticker_types.py b/examples/rest/indices-ticker_types.py new file mode 100644 index 00000000..9b05a4c0 --- /dev/null +++ b/examples/rest/indices-ticker_types.py @@ -0,0 +1,20 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/indices/get_v3_reference_tickers_types +# https://polygon-api-client.readthedocs.io/en/latest/Reference.html#get-ticker-types + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +try: + types = client.get_ticker_types("indices") +except TypeError as e: + if "not NoneType" in str(e): + print("None found") + types = None + else: + raise + +if types is not None: + print(types) diff --git a/examples/rest/indices-tickers.py b/examples/rest/indices-tickers.py new file mode 100644 index 00000000..06d20bab --- /dev/null +++ b/examples/rest/indices-tickers.py @@ -0,0 +1,13 @@ +from polygon import RESTClient + +# docs +# https://polygon.io/docs/indices/get_v3_reference_tickers +# https://polygon-api-client.readthedocs.io/en/latest/Reference.html#list-tickers + +# client = RESTClient("XXXXXX") # hardcoded api_key is used +client = RESTClient() # POLYGON_API_KEY environment variable is used + +tickers = [] +for t in client.list_tickers(market='indices', limit=1000): + tickers.append(t) +print(tickers) diff --git a/examples/rest/options-market_holidays.py b/examples/rest/options-market_holidays.py index d54b8758..c1e94932 100644 --- a/examples/rest/options-market_holidays.py +++ b/examples/rest/options-market_holidays.py @@ -4,7 +4,7 @@ ) # docs -# https://polygon.io/docs/options/get_v1_marketstatus_upcoming +# https://polygon.io/docs/indices/get_v1_marketstatus_upcoming # https://polygon-api-client.readthedocs.io/en/latest/Reference.html#get-market-holidays # client = RESTClient("XXXXXX") # hardcoded api_key is used From ccb83b4380b54603090be5acaaafa24dc1497ca5 Mon Sep 17 00:00:00 2001 From: justinpolygon <123573436+justinpolygon@users.noreply.github.com> Date: Wed, 29 Mar 2023 05:48:51 -0700 Subject: [PATCH 2/4] fix linting --- examples/rest/crypto-grouped_daily_bars.py | 4 +--- examples/rest/crypto-last_trade_for_a_crypto_pair.py | 5 +---- examples/rest/crypto-snapshots_all_tickers.py | 2 +- examples/rest/crypto-technical_indicators_sma.py | 2 +- examples/rest/crypto-tickers.py | 2 +- examples/rest/forex-grouped_daily_bars.py | 4 ++-- examples/rest/forex-snapshots_all_tickers.py | 2 +- examples/rest/forex-tickers.py | 2 +- examples/rest/indices-ticker_types.py | 7 +++++++ examples/rest/indices-tickers.py | 2 +- examples/rest/options-market_holidays.py | 2 +- 11 files changed, 18 insertions(+), 16 deletions(-) diff --git a/examples/rest/crypto-grouped_daily_bars.py b/examples/rest/crypto-grouped_daily_bars.py index 6ca01bc0..ec1bdb81 100644 --- a/examples/rest/crypto-grouped_daily_bars.py +++ b/examples/rest/crypto-grouped_daily_bars.py @@ -9,9 +9,7 @@ client = RESTClient() # POLYGON_API_KEY environment variable is used grouped = client.get_grouped_daily_aggs( - "2023-01-09", - locale='global', - market_type='crypto' + "2023-01-09", locale="global", market_type="crypto" ) # print(grouped) diff --git a/examples/rest/crypto-last_trade_for_a_crypto_pair.py b/examples/rest/crypto-last_trade_for_a_crypto_pair.py index 78abc11f..850bd98a 100644 --- a/examples/rest/crypto-last_trade_for_a_crypto_pair.py +++ b/examples/rest/crypto-last_trade_for_a_crypto_pair.py @@ -7,9 +7,6 @@ # client = RESTClient("XXXXXX") # hardcoded api_key is used client = RESTClient() # POLYGON_API_KEY environment variable is used -trade = client.get_last_crypto_trade( - "BTC", - "USD" -) +trade = client.get_last_crypto_trade("BTC", "USD") print(trade) diff --git a/examples/rest/crypto-snapshots_all_tickers.py b/examples/rest/crypto-snapshots_all_tickers.py index c7b6baef..91441aae 100644 --- a/examples/rest/crypto-snapshots_all_tickers.py +++ b/examples/rest/crypto-snapshots_all_tickers.py @@ -11,7 +11,7 @@ # client = RESTClient("XXXXXX") # hardcoded api_key is used client = RESTClient() # POLYGON_API_KEY environment variable is used -snapshot = client.get_snapshot_all("crypto") # all tickers +snapshot = client.get_snapshot_all("crypto") # all tickers # print raw values print(snapshot) diff --git a/examples/rest/crypto-technical_indicators_sma.py b/examples/rest/crypto-technical_indicators_sma.py index 072c205b..f343ff7b 100644 --- a/examples/rest/crypto-technical_indicators_sma.py +++ b/examples/rest/crypto-technical_indicators_sma.py @@ -8,4 +8,4 @@ client = RESTClient() # POLYGON_API_KEY environment variable is used sma = client.get_sma("X:BTCUSD") -print(sma) \ No newline at end of file +print(sma) diff --git a/examples/rest/crypto-tickers.py b/examples/rest/crypto-tickers.py index 922e8ca1..8eb07170 100644 --- a/examples/rest/crypto-tickers.py +++ b/examples/rest/crypto-tickers.py @@ -8,6 +8,6 @@ client = RESTClient() # POLYGON_API_KEY environment variable is used tickers = [] -for t in client.list_tickers(market='crypto', limit=1000): +for t in client.list_tickers(market="crypto", limit=1000): tickers.append(t) print(tickers) diff --git a/examples/rest/forex-grouped_daily_bars.py b/examples/rest/forex-grouped_daily_bars.py index 6f4bed97..f8130877 100644 --- a/examples/rest/forex-grouped_daily_bars.py +++ b/examples/rest/forex-grouped_daily_bars.py @@ -10,8 +10,8 @@ grouped = client.get_grouped_daily_aggs( "2023-03-27", - locale='global', - market_type='fx', + locale="global", + market_type="fx", ) # print(grouped) diff --git a/examples/rest/forex-snapshots_all_tickers.py b/examples/rest/forex-snapshots_all_tickers.py index ffb75e26..0650bbc6 100644 --- a/examples/rest/forex-snapshots_all_tickers.py +++ b/examples/rest/forex-snapshots_all_tickers.py @@ -11,7 +11,7 @@ # client = RESTClient("XXXXXX") # hardcoded api_key is used client = RESTClient() # POLYGON_API_KEY environment variable is used -snapshot = client.get_snapshot_all("forex") # all tickers +snapshot = client.get_snapshot_all("forex") # all tickers # print raw values print(snapshot) diff --git a/examples/rest/forex-tickers.py b/examples/rest/forex-tickers.py index 8a3e13f8..c1736721 100644 --- a/examples/rest/forex-tickers.py +++ b/examples/rest/forex-tickers.py @@ -8,6 +8,6 @@ client = RESTClient() # POLYGON_API_KEY environment variable is used tickers = [] -for t in client.list_tickers(market='fx', limit=1000): +for t in client.list_tickers(market="fx", limit=1000): tickers.append(t) print(tickers) diff --git a/examples/rest/indices-ticker_types.py b/examples/rest/indices-ticker_types.py index 9b05a4c0..ec3277e9 100644 --- a/examples/rest/indices-ticker_types.py +++ b/examples/rest/indices-ticker_types.py @@ -1,4 +1,9 @@ +from typing import Optional, Union, List +from urllib3 import HTTPResponse from polygon import RESTClient +from polygon.rest.models import ( + TickerTypes, +) # docs # https://polygon.io/docs/indices/get_v3_reference_tickers_types @@ -7,6 +12,8 @@ # client = RESTClient("XXXXXX") # hardcoded api_key is used client = RESTClient() # POLYGON_API_KEY environment variable is used +types: Optional[Union[List[TickerTypes], HTTPResponse]] = None + try: types = client.get_ticker_types("indices") except TypeError as e: diff --git a/examples/rest/indices-tickers.py b/examples/rest/indices-tickers.py index 06d20bab..a0786f19 100644 --- a/examples/rest/indices-tickers.py +++ b/examples/rest/indices-tickers.py @@ -8,6 +8,6 @@ client = RESTClient() # POLYGON_API_KEY environment variable is used tickers = [] -for t in client.list_tickers(market='indices', limit=1000): +for t in client.list_tickers(market="indices", limit=1000): tickers.append(t) print(tickers) diff --git a/examples/rest/options-market_holidays.py b/examples/rest/options-market_holidays.py index c1e94932..d54b8758 100644 --- a/examples/rest/options-market_holidays.py +++ b/examples/rest/options-market_holidays.py @@ -4,7 +4,7 @@ ) # docs -# https://polygon.io/docs/indices/get_v1_marketstatus_upcoming +# https://polygon.io/docs/options/get_v1_marketstatus_upcoming # https://polygon-api-client.readthedocs.io/en/latest/Reference.html#get-market-holidays # client = RESTClient("XXXXXX") # hardcoded api_key is used From f6909713bbfec19d956073ce911496b7d56f515c Mon Sep 17 00:00:00 2001 From: justinpolygon <123573436+justinpolygon@users.noreply.github.com> Date: Mon, 3 Apr 2023 14:13:50 -0700 Subject: [PATCH 3/4] Update crypto-snapshots_all_tickers.py Fix line space --- examples/rest/crypto-snapshots_all_tickers.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/examples/rest/crypto-snapshots_all_tickers.py b/examples/rest/crypto-snapshots_all_tickers.py index 91441aae..42cc5f65 100644 --- a/examples/rest/crypto-snapshots_all_tickers.py +++ b/examples/rest/crypto-snapshots_all_tickers.py @@ -30,16 +30,5 @@ item.prev_day.close, float ): - percent_change = ( - (item.prev_day.close - item.prev_day.open) - / item.prev_day.open - * 100 - ) - print( - "{:<15}{:<15}{:<15}{:.2f} %".format( - item.ticker, - item.prev_day.open, - item.prev_day.close, - percent_change, - ) - ) + percent_change = ((item.prev_day.close - item.prev_day.open)/item.prev_day.open*100) + print("{:<15}{:<15}{:<15}{:.2f} %".format(item.ticker,item.prev_day.open,item.prev_day.close,percent_change)) From 5aaf501a1c1830dd04beb0bf49272e07bdc4fa13 Mon Sep 17 00:00:00 2001 From: justinpolygon <123573436+justinpolygon@users.noreply.github.com> Date: Mon, 3 Apr 2023 14:21:41 -0700 Subject: [PATCH 4/4] Update crypto-snapshots_all_tickers.py Updated code style to pass lint check. --- examples/rest/crypto-snapshots_all_tickers.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/rest/crypto-snapshots_all_tickers.py b/examples/rest/crypto-snapshots_all_tickers.py index 42cc5f65..91441aae 100644 --- a/examples/rest/crypto-snapshots_all_tickers.py +++ b/examples/rest/crypto-snapshots_all_tickers.py @@ -30,5 +30,16 @@ item.prev_day.close, float ): - percent_change = ((item.prev_day.close - item.prev_day.open)/item.prev_day.open*100) - print("{:<15}{:<15}{:<15}{:.2f} %".format(item.ticker,item.prev_day.open,item.prev_day.close,percent_change)) + percent_change = ( + (item.prev_day.close - item.prev_day.open) + / item.prev_day.open + * 100 + ) + print( + "{:<15}{:<15}{:<15}{:.2f} %".format( + item.ticker, + item.prev_day.open, + item.prev_day.close, + percent_change, + ) + )