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
30 changes: 30 additions & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from polygon import RESTClient

import os
import unittest
import httpretty # type: ignore

# mocks are stored in file tree
mocks = []
dirname = os.path.dirname(__file__)
mockdir = os.path.join(dirname, "mocks")
for dname, _, files in os.walk(mockdir):
for fname in files:
if fname.endswith(".json"):
abspath = os.path.join(dname, fname)
with open(abspath, "r") as f:
urllpath = abspath.replace(mockdir, "").replace(".json", "")
mocks.append((urllpath, f.read()))
# print('load', urllpath)


class BaseTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.maxDiff = None
cls.c = RESTClient("", verbose=True)
httpretty.enable(verbose=True, allow_net_connect=False)
for m in mocks:
url = cls.c.BASE + m[0]
# print('register', url)
httpretty.register_uri(httpretty.GET, url, m[1], match_querystring=True)
110 changes: 0 additions & 110 deletions tests/mocks.py

This file was deleted.

14 changes: 14 additions & 0 deletions tests/mocks/v1/last/crypto/BTC/USD.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"last": {
"conditions": [
2
],
"exchange": 2,
"price": 39976.89682331,
"size": 0.005,
"timestamp": 1651180409688
},
"request_id": "d67c9bfe1fa0c29db9177d78b3ab713c",
"status": "success",
"symbol": "BTC-USD"
}
15 changes: 15 additions & 0 deletions tests/mocks/v1/marketstatus/now.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"market": "extended-hours",
"earlyHours": false,
"afterHours": true,
"serverTime": "2022-04-28T16:48:08-04:00",
"exchanges": {
"nyse": "extended-hours",
"nasdaq": "extended-hours",
"otc": "extended-hours"
},
"currencies": {
"fx": "open",
"crypto": "open"
}
}
90 changes: 90 additions & 0 deletions tests/mocks/v1/marketstatus/upcoming.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[
{
"exchange": "NYSE",
"name": "Memorial Day",
"date": "2022-05-30",
"status": "closed"
},
{
"exchange": "NASDAQ",
"name": "Memorial Day",
"date": "2022-05-30",
"status": "closed"
},
{
"exchange": "NASDAQ",
"name": "Juneteenth",
"date": "2022-06-20",
"status": "closed"
},
{
"exchange": "NYSE",
"name": "Juneteenth",
"date": "2022-06-20",
"status": "closed"
},
{
"exchange": "NYSE",
"name": "Independence Day",
"date": "2022-07-04",
"status": "closed"
},
{
"exchange": "NASDAQ",
"name": "Independence Day",
"date": "2022-07-04",
"status": "closed"
},
{
"exchange": "NYSE",
"name": "Labor Day",
"date": "2022-09-05",
"status": "closed"
},
{
"exchange": "NASDAQ",
"name": "Labor Day",
"date": "2022-09-05",
"status": "closed"
},
{
"exchange": "NYSE",
"name": "Thanksgiving",
"date": "2022-11-24",
"status": "closed"
},
{
"exchange": "NASDAQ",
"name": "Thanksgiving",
"date": "2022-11-24",
"status": "closed"
},
{
"exchange": "NYSE",
"name": "Thanksgiving",
"date": "2022-11-25",
"status": "early-close",
"open": "2022-11-25T14:30:00.000Z",
"close": "2022-11-25T18:00:00.000Z"
},
{
"exchange": "NASDAQ",
"name": "Thanksgiving",
"date": "2022-11-25",
"status": "early-close",
"open": "2022-11-25T14:30:00.000Z",
"close": "2022-11-25T18:00:00.000Z"
},
{
"exchange": "NYSE",
"name": "Christmas",
"date": "2022-12-26",
"status": "closed"
},
{
"exchange": "NASDAQ",
"name": "Christmas",
"date": "2022-12-26",
"status": "closed"
}
]
12 changes: 12 additions & 0 deletions tests/mocks/v1/open-close/AAPL/2005-04-01?adjusted=True.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"status": "OK",
"from": "2021-04-01",
"symbol": "AAPL",
"open": 123.66,
"high": 124.18,
"low": 122.49,
"close": 123,
"volume": 75089134,
"afterHours": 123,
"preMarket": 123.45
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"queryCount": 1,
"resultsCount": 1,
"adjusted": true,
"results": [
{
"T": "GIK",
"v": 895345,
"vw": 9.9979,
"o": 9.99,
"c": 10.02,
"h": 10.02,
"l": 9.9,
"t": 1602705600000,
"n": 96
}
],
"status": "OK",
"request_id": "eae3ded2d6d43f978125b7a8a609fad9",
"count": 1
}
22 changes: 22 additions & 0 deletions tests/mocks/v2/aggs/ticker/AAPL/prev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"ticker": "AAPL",
"queryCount": 1,
"resultsCount": 1,
"adjusted": true,
"results": [
{
"T": "AAPL",
"v": 95595226.0,
"vw": 158.6074,
"o": 162.25,
"c": 156.8,
"h": 162.34,
"l": 156.72,
"t": 1651003200000,
"n": 899965
}
],
"status": "OK",
"request_id": "5e5378d5ecaf3df794bb52e45d015d2e",
"count": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"ticker": "AAPL",
"queryCount": 2,
"resultsCount": 2,
"adjusted": true,
"results": [
{
"v": 642646396.0,
"vw": 1.469,
"o": 1.5032,
"c": 1.4604,
"h": 1.5064,
"l": 1.4489,
"t": 1112331600000,
"n": 82132
},
{
"v": 578172308.0,
"vw": 1.4589,
"o": 1.4639,
"c": 1.4675,
"h": 1.4754,
"l": 1.4343,
"t": 1112587200000,
"n": 65543
}
],
"status": "OK",
"request_id": "12afda77aab3b1936c5fb6ef4241ae42",
"count": 2
}
21 changes: 21 additions & 0 deletions tests/mocks/v2/last/trade/AAPL.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"results": {
"c": [
12,
37
],
"i": "237688",
"p": 166.25,
"s": 2,
"x": 4,
"r": 202,
"z": 3,
"T": "AAPL",
"t": 1651179319310617300,
"y": 1651179319308000000,
"f": 1651179319310588400,
"q": 7084210
},
"status": "OK",
"request_id": "d4bafa50e72cf9ed19ac538ae1a3185a"
}
29 changes: 29 additions & 0 deletions tests/mocks/v2/reference/news?ticker=NFLX.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"results": [
{
"id": "JeJEhAVoKaqJ2zF9nzQYMg07UlEeWlis6Dsop33TPQY",
"publisher": {
"name": "MarketWatch",
"homepage_url": "https://www.marketwatch.com/",
"logo_url": "https://s3.polygon.io/public/assets/news/logos/marketwatch.svg",
"favicon_url": "https://s3.polygon.io/public/assets/news/favicons/marketwatch.ico"
},
"title": "Theres a big hole in the Feds theory of inflation\u2014incomes are falling at a record 10.9 rate",
"author": "MarketWatch",
"published_utc": "2022-04-28T17:08:00Z",
"article_url": "https://www.marketwatch.com/story/theres-a-big-hole-in-the-feds-theory-of-inflationincomes-are-falling-at-a-record-10-9-rate-11651165705",
"tickers": [
"MSFT",
"TSN",
"NFLX",
"AMZN"
],
"amp_url": "https://www.marketwatch.com/amp/story/theres-a-big-hole-in-the-feds-theory-of-inflationincomes-are-falling-at-a-record-10-9-rate-11651165705",
"image_url": "https://images.mktw.net/im-533637/social",
"description": "If inflation is all due to an overly generous federal government giving its people too much money, then our inflation problem is about to go away."
}
],
"status": "OK",
"request_id": "f5248459196e12f27520afd41cee5126",
"count": 10
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"data": {
"askCount": 593.1412981600005,
"asks": [
{
"p": 11454,
"x": {
"2": 1
}
},
{
"p": 11455,
"x": {
"2": 1
}
}
],
"bidCount": 694.951789670001,
"bids": [
{
"p": 16303.17,
"x": {
"1": 2
}
},
{
"p": 16302.94,
"x": {
"1": 0.02859424,
"6": 0.023455
}
}
],
"spread": -4849.17,
"ticker": "X:BTCUSD",
"updated": 1605295074162
},
"status": "OK"
}
Loading