mirror of
https://github.com/hydrosquall/tiingo-python.git
synced 2025-12-27 07:55:29 +01:00
Add columns param to get_ticker_price, including tests
This commit is contained in:
27
tests/fixtures/ticker_price_with_multiple_columns.yaml
vendored
Normal file
27
tests/fixtures/ticker_price_with_multiple_columns.yaml
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
interactions:
|
||||
- request:
|
||||
body: null
|
||||
headers:
|
||||
Accept: ['*/*']
|
||||
Accept-Encoding: ['gzip, deflate']
|
||||
Authorization: [Token 0000000000000000000000000000000000000000]
|
||||
Connection: [keep-alive]
|
||||
Content-Type: [application/json]
|
||||
User-Agent: [tiingo-python-client 0.5.0]
|
||||
method: GET
|
||||
uri: https://api.tiingo.com/tiingo/daily/GOOGL/prices?format=json&resampleFreq=daily&columns=open,high,low,close,volume
|
||||
response:
|
||||
body: {string: '[{"close":165.14,"date":"2024-10-22T00:00:00+00:00","high":165.77,"low":162.98,"open":162.98,"volume":16568121}]'}
|
||||
headers:
|
||||
Allow: ['GET, HEAD, OPTIONS']
|
||||
Content-Length: ['1982']
|
||||
Content-Type: [application/json]
|
||||
Date: ['Wed, 23 Oct 2024 02:42:06 GMT']
|
||||
Server: [nginx/1.10.1]
|
||||
Vary: ['Accept, Cookie']
|
||||
X-Frame-Options: [SAMEORIGIN]
|
||||
status: {code: 200, message: OK}
|
||||
version: 1
|
||||
|
||||
|
||||
|
||||
27
tests/fixtures/ticker_price_with_volume_column.yaml
vendored
Normal file
27
tests/fixtures/ticker_price_with_volume_column.yaml
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
interactions:
|
||||
- request:
|
||||
body: null
|
||||
headers:
|
||||
Accept: ['*/*']
|
||||
Accept-Encoding: ['gzip, deflate']
|
||||
Authorization: [Token 0000000000000000000000000000000000000000]
|
||||
Connection: [keep-alive]
|
||||
Content-Type: [application/json]
|
||||
User-Agent: [tiingo-python-client 0.5.0]
|
||||
method: GET
|
||||
uri: https://api.tiingo.com/tiingo/daily/GOOGL/prices?format=json&resampleFreq=daily&columns=volume
|
||||
response:
|
||||
body: {string: '[{"date":"2024-10-22T00:00:00+00:00","volume":16568121}]'}
|
||||
headers:
|
||||
Allow: ['GET, HEAD, OPTIONS']
|
||||
Content-Length: ['1001']
|
||||
Content-Type: [application/json]
|
||||
Date: ['Wed, 23 Oct 2024 02:42:06 GMT']
|
||||
Server: [nginx/1.10.1]
|
||||
Vary: ['Accept, Cookie']
|
||||
X-Frame-Options: [SAMEORIGIN]
|
||||
status: {code: 200, message: OK}
|
||||
version: 1
|
||||
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class TestTickerPrices(TestCase):
|
||||
def test_ticker_metadata_as_object(self):
|
||||
metadata = self._client.get_ticker_metadata("GOOGL", fmt="object")
|
||||
assert metadata.ticker == "GOOGL" # Access property via ATTRIBUTE
|
||||
assert metadata.name # (contrast with key access above
|
||||
assert metadata.name # (contrast with key access above
|
||||
|
||||
@vcr.use_cassette('tests/fixtures/ticker_price.yaml')
|
||||
def test_ticker_price(self):
|
||||
@@ -68,7 +68,7 @@ class TestTickerPrices(TestCase):
|
||||
def test_ticker_price(self):
|
||||
"""Test that weekly frequency works"""
|
||||
prices = self._client.get_ticker_price("GOOGL", startDate='2018-01-05',
|
||||
endDate='2018-01-19', frequency='weekly')
|
||||
endDate='2018-01-19', frequency='weekly')
|
||||
assert len(prices) == 3
|
||||
assert prices[0].get('adjClose')
|
||||
|
||||
@@ -98,6 +98,34 @@ class TestTickerPrices(TestCase):
|
||||
rows = list(reader)
|
||||
assert len(rows) > 2 # more than 1 day of data
|
||||
|
||||
@vcr.use_cassette('tests/fixtures/ticker_price_with_volume_column.yaml')
|
||||
def test_ticker_price_with_volume_column(self):
|
||||
"""Confirm that CSV endpoint works"""
|
||||
prices = self._client.get_ticker_price("GOOGL",
|
||||
columns="volume",
|
||||
fmt='json')
|
||||
assert len(prices) == 1
|
||||
assert prices[0].get('date')
|
||||
assert not prices[0].get('high')
|
||||
assert not prices[0].get('low')
|
||||
assert not prices[0].get('open')
|
||||
assert not prices[0].get('close')
|
||||
assert prices[0].get('volume')
|
||||
|
||||
@vcr.use_cassette('tests/fixtures/ticker_price_with_multiple_columns.yaml')
|
||||
def test_ticker_price_with_multiple_columns(self):
|
||||
"""Confirm that CSV endpoint works"""
|
||||
prices = self._client.get_ticker_price("GOOGL",
|
||||
columns="open,high,low,close,volume",
|
||||
fmt='json')
|
||||
assert len(prices) == 1
|
||||
assert prices[0].get('date')
|
||||
assert prices[0].get('high')
|
||||
assert prices[0].get('low')
|
||||
assert prices[0].get('open')
|
||||
assert prices[0].get('close')
|
||||
assert prices[0].get('volume')
|
||||
|
||||
@vcr.use_cassette('tests/fixtures/intraday_price.yaml')
|
||||
def test_intraday_ticker_price(self):
|
||||
"""Test the EOD Prices Endpoint with data param"""
|
||||
@@ -149,6 +177,7 @@ class TestTickerPrices(TestCase):
|
||||
endDate="2018-01-02",
|
||||
frequency="1.5mins")
|
||||
|
||||
|
||||
# tiingo/news
|
||||
class TestNews(TestCase):
|
||||
|
||||
@@ -227,6 +256,7 @@ class TestNews(TestCase):
|
||||
with self.assertRaises(RestClientError):
|
||||
assert self._client.get_bulk_news(file_id="1", fmt="object")
|
||||
|
||||
|
||||
# FUNDAMENTALS ENDPOINTS
|
||||
class TestFundamentals(TestCase):
|
||||
|
||||
|
||||
@@ -114,6 +114,24 @@ class TestTiingoWithPython(TestCase):
|
||||
frequency="30Min")
|
||||
self.assertGreater(len(prices), 1)
|
||||
|
||||
@vcr.use_cassette('tests/fixtures/ticker_price_with_volume_column.yaml')
|
||||
def test_get_dataframe_with_volume_column(self):
|
||||
"""Confirm that CSV endpoint works"""
|
||||
prices = self._client.get_dataframe("GOOGL",
|
||||
columns="volume",
|
||||
fmt='json')
|
||||
assert len(prices) == 1
|
||||
assert len(prices.columns) == 2
|
||||
|
||||
@vcr.use_cassette('tests/fixtures/ticker_price_with_multiple_columns.yaml')
|
||||
def test_get_dataframe_with_multiple_columns(self):
|
||||
"""Confirm that CSV endpoint works"""
|
||||
prices = self._client.get_dataframe("GOOGL",
|
||||
columns="open,high,low,close,volume",
|
||||
fmt='json')
|
||||
assert len(prices) == 1
|
||||
assert len(prices.columns) == 6
|
||||
|
||||
def test_metric_name_column_error(self):
|
||||
with self.assertRaises(APIColumnNameError):
|
||||
self._client.get_dataframe(['GOOGL', 'AAPL'], startDate='2018-01-05',
|
||||
|
||||
Reference in New Issue
Block a user