From 7935168ade26b134cb382a3402ce43e4aea18db3 Mon Sep 17 00:00:00 2001 From: n1rna Date: Sun, 13 Oct 2019 00:28:57 +0330 Subject: [PATCH 1/9] Add support for tiingo crypto endpoints to TiingoClient --- tiingo/api.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/tiingo/api.py b/tiingo/api.py index f02023a..7f3a5ec 100644 --- a/tiingo/api.py +++ b/tiingo/api.py @@ -144,7 +144,7 @@ class TiingoClient(RestClient): is_valid = self._is_eod_frequency(frequency) or re.match(self._frequency_pattern, frequency) return not is_valid - def _get_url(self, ticker, frequency): + def _get_price_url(self, ticker, frequency): """ Return url based on frequency. Daily, weekly, or yearly use Tiingo EOD api; anything less than daily uses the iex intraday api. @@ -178,7 +178,7 @@ class TiingoClient(RestClient): fmt (string): 'csv' or 'json' frequency (string): Resample frequency """ - url = self._get_url(ticker, frequency) + url = self._get_price_url(ticker, frequency) params = { 'format': fmt if fmt != "object" else 'json', # conversion local 'resampleFreq': frequency @@ -245,7 +245,7 @@ class TiingoClient(RestClient): if pandas_is_installed: if type(tickers) is str: stock = tickers - url = self._get_url(stock, frequency) + url = self._get_price_url(stock, frequency) response = self._request('GET', url, params=params) df = pd.DataFrame(response.json()) if metric_name is not None: @@ -258,7 +258,7 @@ class TiingoClient(RestClient): else: prices = pd.DataFrame() for stock in tickers: - url = self._get_url(stock, frequency) + url = self._get_price_url(stock, frequency) response = self._request('GET', url, params=params) df = pd.DataFrame(response.json()) df.index = df['date'] @@ -331,3 +331,66 @@ class TiingoClient(RestClient): return data elif fmt == 'object': return dict_to_object(data, "BulkNews") + + # Crypto + # tiingo/crypto + def get_crypto_top_of_book(self, tickers=[], + endDate=None, exchanges=[], + includeRawExchangeData=False, convertCurrency=None): + url = 'https://api.tiingo.com/tiingo/crypto/top' + params = { + 'tickers': ','.join(tickers) + } + + if endDate: + params['endDate'] = endDate + if len(exchanges): + params['exchanges'] = ','.join(exchanges) + if includeRawExchangeData is True: + params['includeRawExchangeData'] = True + if convertCurrency: + params['convertCurrency'] = convertCurrency + + response = self._request('GET', url, params=params) + return response.json() + + def get_crypto_price_history(self, tickers=[], baseCurrency=None, + startDate=None, endDate=None, exchanges=[], + consolidateBaseCurrency=False, includeRawExchangeData=False, + resampleFreq=None, convertCurrency=None): + url = 'https://api.tiingo.com/tiingo/crypto/prices' + params = { + 'tickers': ','.join(tickers) + } + + if startDate: + params['startDate'] = startDate + if endDate: + params['endDate'] = endDate + if len(exchanges): + params['exchanges'] = ','.join(exchanges) + if consolidateBaseCurrency is True: + params['consolidateBaseCurrency'] = ','.join(consolidateBaseCurrency) + if includeRawExchangeData is True: + params['includeRawExchangeData'] = ','.join(includeRawExchangeData) + if resampleFreq: + params['resampleFreq'] = resampleFreq + if convertCurrency: + params['convertCurrency'] = convertCurrency + + response = self._request('GET', url, params=params) + return response.json() + + def get_crypto_meta_data(self, tickers=[], fmt='json'): + url = 'https://api.tiingo.com/tiingo/crypto' + + params = { + 'tickers': ','.join(tickers), + 'format': fmt, + } + + response = self._request('GET', url, params=params) + if fmt == 'csv': + return response.content.decode("utf-8") + else: + return response.json() From 50aacf395fef416781b86bb0c09035f2d7cf129e Mon Sep 17 00:00:00 2001 From: n1rna Date: Sun, 13 Oct 2019 00:49:58 +0330 Subject: [PATCH 2/9] Add tests for crypto endpoints --- tests/test_crypto.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_crypto.py diff --git a/tests/test_crypto.py b/tests/test_crypto.py new file mode 100644 index 0000000..c9bd95f --- /dev/null +++ b/tests/test_crypto.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +"""Tests for `tiingo` package.""" + +from unittest import TestCase + +from tiingo import TiingoClient + + +# CRYPTO ENDPOINTS +class TestCryptoEndpoints(TestCase): + + def setUp(self): + self._client = TiingoClient() + + def test_crypto_metadata(self): + metadata = self._client.get_crypto_meta_data(ticker=['btcusd', 'fldcbtc']) + + assert len(metadata) == 2 + assert metadata[0].ticker == 'btcusd' + assert metadata[1].ticker == 'fldcbtc' + + def test_crypto_top_of_book(self): + top_of_book = self._client.get_crypto_top_of_book(tickers=['btcusd', 'fldcbtc'], + endDate='2018-01-02', includeRawExchangeData=True) + assert 'topOfBookData' in top_of_book + assert len(top_of_book['topOfBookData']) == 2 + assert 'exchangeData' in top_of_book + + def test_crypto_price_history(self): + price_history = self._client.get_crypto_price_history(tickers=['btcusd', 'fldcbtc'], + startDate='2019-05-01', endDate='2019-05-02', + includeRawExchangeData=True, resampleFreq='daily') + assert len(price_history) == 2 + assert len(price_history[0]['priceData']) in [6, 7] + assert 'exchangeData' in price_history[0] From 3747d62a7c82046aaffa2818989a407853330343 Mon Sep 17 00:00:00 2001 From: n1rna Date: Sun, 13 Oct 2019 23:53:31 +0330 Subject: [PATCH 3/9] Add vs code internal paths to .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index efd5394..598ad47 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,7 @@ travis_pypi_setup.py # Jupyter examples/.ipynb_checkpoints +# vs code +.vscode/ +.history/ + From d50c04929c42540946ed60a12635b57eb738ef90 Mon Sep 17 00:00:00 2001 From: n1rna Date: Sun, 13 Oct 2019 23:54:48 +0330 Subject: [PATCH 4/9] Add cassette fixtures for crypto endpoints --- tests/fixtures/crypto_metadata.yaml | 24 ++++++++++++++++++++++++ tests/fixtures/crypto_price_history.yaml | 24 ++++++++++++++++++++++++ tests/fixtures/crypto_top_of_book.yaml | 24 ++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 tests/fixtures/crypto_metadata.yaml create mode 100644 tests/fixtures/crypto_price_history.yaml create mode 100644 tests/fixtures/crypto_top_of_book.yaml diff --git a/tests/fixtures/crypto_metadata.yaml b/tests/fixtures/crypto_metadata.yaml new file mode 100644 index 0000000..ca8fa40 --- /dev/null +++ b/tests/fixtures/crypto_metadata.yaml @@ -0,0 +1,24 @@ +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.3.2] + method: GET + uri: https://api.tiingo.com/tiingo/crypto/?tickers=btcusd,fldcbtc + response: + body: {string: '[{"name":"Bitcoin Tether (BTC/USD)","description":"Tether (BTC/USD)","quoteCurrency":"usd","ticker":"btcusd","baseCurrency":"btc"},{"name":"FoldingCoin (FLDC/BTC)","description":"FoldingCoin (FLDC/BTC)","quoteCurrency":"btc","ticker":"fldcbtc","baseCurrency":"fldc"}]'} + headers: + Allow: ['GET, HEAD, OPTIONS'] + Content-Length: ['62'] + Content-Type: [application/json] + Date: ['Sun, 08 Oct 2017 10:21:32 GMT'] + Server: [nginx/1.10.1] + Vary: [Cookie] + X-Frame-Options: [SAMEORIGIN] + status: {code: 403, message: Forbidden} +version: 1 diff --git a/tests/fixtures/crypto_price_history.yaml b/tests/fixtures/crypto_price_history.yaml new file mode 100644 index 0000000..65794b8 --- /dev/null +++ b/tests/fixtures/crypto_price_history.yaml @@ -0,0 +1,24 @@ +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.3.2] + method: GET + uri: https://api.tiingo.com/tiingo/crypto/prices/?tickers=btcusd,fldcbtc&includeRawExchangeData=true&endDate=2019-05-02&startDate=2019-05-01&resampleFreq=1day + response: + body: {string: '[{"ticker":"btcusd","baseCurrency":"btc","quoteCurrency":"usd","priceData":[{"volume":27749.729226739997,"date":"2019-05-01T00:00:00+00:00","volumeNotional":150406020.75066727,"close":5420.0896708474575,"open":5367.348827845256,"low":5358.100876910302,"tradesDone":214889,"high":5443.811868611532},{"volume":40036.510605330004,"date":"2019-05-02T00:00:00+00:00","volumeNotional":222030376.30221513,"close":5545.697488248552,"open":5441.491804492167,"low":5426.033480300644,"tradesDone":241005,"high":5590.235084334595}],"exchangeData":{"BIBOX":[{"exchangeCode":"BIBOX","volume":null,"date":"2019-05-01T00:00:00+00:00","volumeNotional":null,"close":5391.82,"open":5315.6435,"low":5314.7716,"tradesDone":null,"high":5397.23},{"exchangeCode":"BIBOX","volume":null,"date":"2019-05-02T00:00:00+00:00","volumeNotional":null,"close":5499.37,"open":5383.96,"low":5371.21,"tradesDone":null,"high":5535.73}],"BINANCE":[{"exchangeCode":"BINANCE","volume":17217.473216,"date":"2019-05-01T00:00:00+00:00","volumeNotional":92685101.81637119,"close":5383.2,"open":5321.94,"low":5316.2,"tradesDone":155085,"high":5402},{"exchangeCode":"BINANCE","volume":22795.787835,"date":"2019-05-02T00:00:00+00:00","volumeNotional":125214299.12523644,"close":5492.87,"open":5383.2,"low":5370,"tradesDone":171919,"high":5538}],"BITFINEX":[{"exchangeCode":"BITFINEX","volume":5435.17396422,"date":"2019-05-01T00:00:00+00:00","volumeNotional":30597311.83157649,"close":5629.5,"open":5599.52273017,"low":5577.5,"tradesDone":19550,"high":5655},{"exchangeCode":"BITFINEX","volume":11027.14067892,"date":"2019-05-02T00:00:00+00:00","volumeNotional":63323355.348698094,"close":5742.5,"open":5629.6,"low":5611.1,"tradesDone":28040,"high":5784.3}],"BITTREX":[{"exchangeCode":"BITTREX","volume":256.46137423,"date":"2019-05-01T00:00:00+00:00","volumeNotional":1365938.4123636545,"close":5326.098,"open":5320,"low":5267.502,"tradesDone":1832,"high":5387.45},{"exchangeCode":"BITTREX","volume":485.69222735,"date":"2019-05-02T00:00:00+00:00","volumeNotional":2619338.18209855,"close":5393,"open":5325.815,"low":5310,"tradesDone":2473,"high":5530}],"GDAX":[{"exchangeCode":"GDAX","volume":4840.62067229,"date":"2019-05-01T00:00:00+00:00","volumeNotional":25757668.69035593,"close":5321.15,"open":5270.68,"low":5265.59,"tradesDone":38422,"high":5358.39},{"exchangeCode":"GDAX","volume":5727.88986406,"date":"2019-05-02T00:00:00+00:00","volumeNotional":30873383.64618204,"close":5390.01,"open":5321.15,"low":5302.59,"tradesDone":38573,"high":5429.62}]}},{"ticker":"fldcbtc","baseCurrency":"fldc","quoteCurrency":"btc","priceData":[{"volume":34807.97636632,"date":"2019-05-01T00:00:00+00:00","volumeNotional":0.0066135155096008,"close":1.9e-7,"open":1.8e-7,"low":1.8e-7,"tradesDone":2,"high":1.9e-7},{"volume":283386.06880708,"date":"2019-05-02T00:00:00+00:00","volumeNotional":0.05100949238527439,"close":1.8e-7,"open":1.9e-7,"low":1.8e-7,"tradesDone":20,"high":2e-7}],"exchangeData":{"BITTREX":[{"exchangeCode":"BITTREX","volume":34807.97636632,"date":"2019-05-01T00:00:00+00:00","volumeNotional":0.0066135155096008,"close":1.9e-7,"open":1.8e-7,"low":1.8e-7,"tradesDone":2,"high":1.9e-7},{"exchangeCode":"BITTREX","volume":283386.06880708,"date":"2019-05-02T00:00:00+00:00","volumeNotional":0.05100949238527439,"close":1.8e-7,"open":1.9e-7,"low":1.8e-7,"tradesDone":20,"high":2e-7}]}}]'} + headers: + Allow: ['GET, HEAD, OPTIONS'] + Content-Length: ['62'] + Content-Type: [application/json] + Date: ['Sun, 08 Oct 2017 10:21:32 GMT'] + Server: [nginx/1.10.1] + Vary: [Cookie] + X-Frame-Options: [SAMEORIGIN] + status: {code: 403, message: Forbidden} +version: 1 diff --git a/tests/fixtures/crypto_top_of_book.yaml b/tests/fixtures/crypto_top_of_book.yaml new file mode 100644 index 0000000..1d8d019 --- /dev/null +++ b/tests/fixtures/crypto_top_of_book.yaml @@ -0,0 +1,24 @@ +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.3.2] + method: GET + uri: https://api.tiingo.com/tiingo/crypto/top/?tickers=btcusd,fldcbtc&includeRawExchangeData=true + response: + body: {string: '[{"ticker":"btcusd","baseCurrency":"btc","quoteCurrency":"usd","topOfBookData":[{"bidPrice":10160.51,"quoteTimestamp":"2019-10-03T23:00:15.363000+00:00","askExchange":"GEMINI","lastSize":0.001338,"askSize":0.1,"lastExchange":"BINANCE","lastPrice":8220.83,"bidExchange":"BITSTAMP","bidSize":2.88067305,"askPrice":8209.92,"lastSaleTimestamp":"2019-10-13T20:20:03.712000+00:00","lastSizeNotional":10.999470539999999}],"exchangeData":{"GEMINI":[{"bidPrice":8206.45,"exchangeCode":"GEMINI","lastSize":0.1,"quoteTimestampStr":"2019-10-03T23:00:15.363000+00:00","askSize":0.1,"lastPrice":8206.45,"lastSaleTimestampStr":"2019-10-03T23:00:09.652000+00:00","bidSize":0.1,"askPrice":8209.92}],"BITTREX":[{"bidPrice":8225.115,"exchangeCode":"BITTREX","lastSize":0.54573986,"quoteTimestampStr":"2019-10-13T20:20:03.668153+00:00","askSize":1.30618005,"lastPrice":8225.124,"lastSaleTimestampStr":"2019-10-13T20:19:52.790000+00:00","bidSize":10.25824791,"askPrice":8225.116}],"GDAX":[{"bidPrice":8225,"exchangeCode":"GDAX","lastSize":0.026867,"quoteTimestampStr":"2019-10-13T20:20:03.805667+00:00","askSize":0.07619918,"lastPrice":8228.53,"lastSaleTimestampStr":"2019-10-13T20:19:59.821000+00:00","bidSize":0.70558435,"askPrice":8228.55}],"KUCOIN":[{"bidPrice":null,"exchangeCode":"KUCOIN","lastSize":0.03,"quoteTimestampStr":"2019-10-13T20:20:03.367832+00:00","askSize":0.15054194,"lastPrice":8221,"lastSaleTimestampStr":"2019-10-13T20:20:03.568812+00:00","bidSize":null,"askPrice":8221.3}],"BINANCE":[{"bidPrice":8220.83,"exchangeCode":"BINANCE","lastSize":0.001338,"quoteTimestampStr":"2019-10-13T20:20:02.924000+00:00","askSize":0.126467,"lastPrice":8220.83,"lastSaleTimestampStr":"2019-10-13T20:20:03.712000+00:00","bidSize":0.005,"askPrice":8227.88}],"BITSTAMP":[{"bidPrice":10160.51,"exchangeCode":"BITSTAMP","lastSize":0.0097418,"quoteTimestampStr":"2019-08-27T10:02:48+00:00","askSize":0.01,"lastPrice":10162.19,"lastSaleTimestampStr":"2019-08-27T10:02:43+00:00","bidSize":2.88067305,"askPrice":10166.66}],"POLONIEX":[{"bidPrice":8214.74394741,"exchangeCode":"POLONIEX","lastSize":1.2e-7,"quoteTimestampStr":"2019-10-13T20:20:02.655109+00:00","askSize":1,"lastPrice":8224.99999998,"lastSaleTimestampStr":"2019-10-13T20:19:56+00:00","bidSize":0.00815241,"askPrice":8224.99999999}],"BIBOX":[{"bidPrice":8215.5596,"exchangeCode":"BIBOX","lastSize":0.797,"quoteTimestampStr":"2019-10-13T20:20:01.509000+00:00","askSize":0.555,"lastPrice":8225.68,"lastSaleTimestampStr":"2019-10-13T20:20:01.509000+00:00","bidSize":0.049,"askPrice":8225}],"BITFINEX":[{"bidPrice":8240.5,"exchangeCode":"BITFINEX","lastSize":0.005,"quoteTimestampStr":"2019-10-13T20:20:03.757465+00:00","askSize":0.335,"lastPrice":8242.3,"lastSaleTimestampStr":"2019-10-13T20:20:03.496000+00:00","bidSize":1.42055391,"askPrice":8246.9}],"GATECOIN":[{"bidPrice":3195.2,"exchangeCode":"GATECOIN","lastSize":0.00307,"quoteTimestampStr":"2018-12-16T00:16:40.664723+00:00","askSize":null,"lastPrice":3203,"lastSaleTimestampStr":"2018-12-15T09:25:27+00:00","bidSize":0.007,"askPrice":null}],"HITBTC":[{"bidPrice":8204.22,"exchangeCode":"HITBTC","lastSize":0.05,"quoteTimestampStr":"2019-10-13T20:20:03.295656+00:00","askSize":0.125,"lastPrice":8208.7,"lastSaleTimestampStr":"2019-10-13T20:18:09.564000+00:00","bidSize":0.14567,"askPrice":8211.44}]}},{"ticker":"fldcbtc","baseCurrency":"fldc","quoteCurrency":"btc","topOfBookData":[{"bidPrice":4e-8,"quoteTimestamp":"2019-10-13T20:18:23.845035+00:00","askExchange":"BITTREX","lastSize":200000,"askSize":982944.10988522,"lastExchange":"BITTREX","lastPrice":5e-8,"bidExchange":"BITTREX","bidSize":1596297.3588658,"askPrice":8e-8,"lastSaleTimestamp":"2019-10-13T07:45:21.210000+00:00","lastSizeNotional":0.01}],"exchangeData":{"BITTREX":[{"bidPrice":4e-8,"exchangeCode":"BITTREX","lastSize":200000,"quoteTimestampStr":"2019-10-13T20:18:23.845035+00:00","askSize":982944.10988522,"lastPrice":5e-8,"lastSaleTimestampStr":"2019-10-13T07:45:21.210000+00:00","bidSize":1596297.3588658,"askPrice":8e-8}]}}]'} + headers: + Allow: ['GET, HEAD, OPTIONS'] + Content-Length: ['62'] + Content-Type: [application/json] + Date: ['Sun, 08 Oct 2017 10:21:32 GMT'] + Server: [nginx/1.10.1] + Vary: [Cookie] + X-Frame-Options: [SAMEORIGIN] + status: {code: 403, message: Forbidden} +version: 1 From e7de01cd109828b5c235fab7e01f50241413bd0d Mon Sep 17 00:00:00 2001 From: n1rna Date: Sun, 13 Oct 2019 23:55:25 +0330 Subject: [PATCH 5/9] Use vcr cassette fixtures in crypto tests --- tests/test_crypto.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_crypto.py b/tests/test_crypto.py index c9bd95f..1111608 100644 --- a/tests/test_crypto.py +++ b/tests/test_crypto.py @@ -3,6 +3,8 @@ from unittest import TestCase +import vcr + from tiingo import TiingoClient @@ -12,13 +14,15 @@ class TestCryptoEndpoints(TestCase): def setUp(self): self._client = TiingoClient() + @vcr.user_cassette('tests/fixtures/crypto_metadata.yaml') def test_crypto_metadata(self): - metadata = self._client.get_crypto_meta_data(ticker=['btcusd', 'fldcbtc']) + metadata = self._client.get_crypto_metadata(ticker=['btcusd', 'fldcbtc']) assert len(metadata) == 2 assert metadata[0].ticker == 'btcusd' assert metadata[1].ticker == 'fldcbtc' + @vcr.use_cassette('tests/fixtures/crypto_top_of_book.yaml') def test_crypto_top_of_book(self): top_of_book = self._client.get_crypto_top_of_book(tickers=['btcusd', 'fldcbtc'], endDate='2018-01-02', includeRawExchangeData=True) @@ -26,10 +30,11 @@ class TestCryptoEndpoints(TestCase): assert len(top_of_book['topOfBookData']) == 2 assert 'exchangeData' in top_of_book + @vcr.user_cassette('tests/fixtures/crypto_price_history.yaml') def test_crypto_price_history(self): price_history = self._client.get_crypto_price_history(tickers=['btcusd', 'fldcbtc'], startDate='2019-05-01', endDate='2019-05-02', - includeRawExchangeData=True, resampleFreq='daily') + includeRawExchangeData=True, resampleFreq='1day') assert len(price_history) == 2 assert len(price_history[0]['priceData']) in [6, 7] assert 'exchangeData' in price_history[0] From b18f358d6101b5bcee0053419114cc5ffdcb3bfc Mon Sep 17 00:00:00 2001 From: n1rna Date: Sun, 13 Oct 2019 23:56:29 +0330 Subject: [PATCH 6/9] Fix some minor issues and typos --- tiingo/api.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tiingo/api.py b/tiingo/api.py index 7f3a5ec..35cde06 100644 --- a/tiingo/api.py +++ b/tiingo/api.py @@ -144,7 +144,7 @@ class TiingoClient(RestClient): is_valid = self._is_eod_frequency(frequency) or re.match(self._frequency_pattern, frequency) return not is_valid - def _get_price_url(self, ticker, frequency): + def _get_url(self, ticker, frequency): """ Return url based on frequency. Daily, weekly, or yearly use Tiingo EOD api; anything less than daily uses the iex intraday api. @@ -178,7 +178,7 @@ class TiingoClient(RestClient): fmt (string): 'csv' or 'json' frequency (string): Resample frequency """ - url = self._get_price_url(ticker, frequency) + url = self._get_url(ticker, frequency) params = { 'format': fmt if fmt != "object" else 'json', # conversion local 'resampleFreq': frequency @@ -245,7 +245,7 @@ class TiingoClient(RestClient): if pandas_is_installed: if type(tickers) is str: stock = tickers - url = self._get_price_url(stock, frequency) + url = self._get_url(stock, frequency) response = self._request('GET', url, params=params) df = pd.DataFrame(response.json()) if metric_name is not None: @@ -258,7 +258,7 @@ class TiingoClient(RestClient): else: prices = pd.DataFrame() for stock in tickers: - url = self._get_price_url(stock, frequency) + url = self._get_url(stock, frequency) response = self._request('GET', url, params=params) df = pd.DataFrame(response.json()) df.index = df['date'] @@ -372,7 +372,7 @@ class TiingoClient(RestClient): if consolidateBaseCurrency is True: params['consolidateBaseCurrency'] = ','.join(consolidateBaseCurrency) if includeRawExchangeData is True: - params['includeRawExchangeData'] = ','.join(includeRawExchangeData) + params['includeRawExchangeData'] = includeRawExchangeData if resampleFreq: params['resampleFreq'] = resampleFreq if convertCurrency: @@ -381,7 +381,7 @@ class TiingoClient(RestClient): response = self._request('GET', url, params=params) return response.json() - def get_crypto_meta_data(self, tickers=[], fmt='json'): + def get_crypto_metadata(self, tickers=[], fmt='json'): url = 'https://api.tiingo.com/tiingo/crypto' params = { From 58efa544ec63044141abd0cabc37a97664f2c1bb Mon Sep 17 00:00:00 2001 From: n1rna Date: Wed, 16 Oct 2019 10:56:39 +0330 Subject: [PATCH 7/9] Fix status code and some typos in crypto fixtures --- tests/fixtures/crypto_metadata.yaml | 4 ++-- tests/fixtures/crypto_price_history.yaml | 4 ++-- tests/fixtures/crypto_top_of_book.yaml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/fixtures/crypto_metadata.yaml b/tests/fixtures/crypto_metadata.yaml index ca8fa40..5d552dc 100644 --- a/tests/fixtures/crypto_metadata.yaml +++ b/tests/fixtures/crypto_metadata.yaml @@ -9,7 +9,7 @@ interactions: Content-Type: [application/json] User-Agent: [tiingo-python-client 0.3.2] method: GET - uri: https://api.tiingo.com/tiingo/crypto/?tickers=btcusd,fldcbtc + uri: https://api.tiingo.com/tiingo/crypto?tickers=btcusd,fldcbtc response: body: {string: '[{"name":"Bitcoin Tether (BTC/USD)","description":"Tether (BTC/USD)","quoteCurrency":"usd","ticker":"btcusd","baseCurrency":"btc"},{"name":"FoldingCoin (FLDC/BTC)","description":"FoldingCoin (FLDC/BTC)","quoteCurrency":"btc","ticker":"fldcbtc","baseCurrency":"fldc"}]'} headers: @@ -20,5 +20,5 @@ interactions: Server: [nginx/1.10.1] Vary: [Cookie] X-Frame-Options: [SAMEORIGIN] - status: {code: 403, message: Forbidden} + status: {code: 200, message: OK} version: 1 diff --git a/tests/fixtures/crypto_price_history.yaml b/tests/fixtures/crypto_price_history.yaml index 65794b8..75e3b42 100644 --- a/tests/fixtures/crypto_price_history.yaml +++ b/tests/fixtures/crypto_price_history.yaml @@ -9,7 +9,7 @@ interactions: Content-Type: [application/json] User-Agent: [tiingo-python-client 0.3.2] method: GET - uri: https://api.tiingo.com/tiingo/crypto/prices/?tickers=btcusd,fldcbtc&includeRawExchangeData=true&endDate=2019-05-02&startDate=2019-05-01&resampleFreq=1day + uri: https://api.tiingo.com/tiingo/crypto/prices?tickers=btcusd,fldcbtc&includeRawExchangeData=true&endDate=2019-05-02&startDate=2019-05-01&resampleFreq=1day response: body: {string: '[{"ticker":"btcusd","baseCurrency":"btc","quoteCurrency":"usd","priceData":[{"volume":27749.729226739997,"date":"2019-05-01T00:00:00+00:00","volumeNotional":150406020.75066727,"close":5420.0896708474575,"open":5367.348827845256,"low":5358.100876910302,"tradesDone":214889,"high":5443.811868611532},{"volume":40036.510605330004,"date":"2019-05-02T00:00:00+00:00","volumeNotional":222030376.30221513,"close":5545.697488248552,"open":5441.491804492167,"low":5426.033480300644,"tradesDone":241005,"high":5590.235084334595}],"exchangeData":{"BIBOX":[{"exchangeCode":"BIBOX","volume":null,"date":"2019-05-01T00:00:00+00:00","volumeNotional":null,"close":5391.82,"open":5315.6435,"low":5314.7716,"tradesDone":null,"high":5397.23},{"exchangeCode":"BIBOX","volume":null,"date":"2019-05-02T00:00:00+00:00","volumeNotional":null,"close":5499.37,"open":5383.96,"low":5371.21,"tradesDone":null,"high":5535.73}],"BINANCE":[{"exchangeCode":"BINANCE","volume":17217.473216,"date":"2019-05-01T00:00:00+00:00","volumeNotional":92685101.81637119,"close":5383.2,"open":5321.94,"low":5316.2,"tradesDone":155085,"high":5402},{"exchangeCode":"BINANCE","volume":22795.787835,"date":"2019-05-02T00:00:00+00:00","volumeNotional":125214299.12523644,"close":5492.87,"open":5383.2,"low":5370,"tradesDone":171919,"high":5538}],"BITFINEX":[{"exchangeCode":"BITFINEX","volume":5435.17396422,"date":"2019-05-01T00:00:00+00:00","volumeNotional":30597311.83157649,"close":5629.5,"open":5599.52273017,"low":5577.5,"tradesDone":19550,"high":5655},{"exchangeCode":"BITFINEX","volume":11027.14067892,"date":"2019-05-02T00:00:00+00:00","volumeNotional":63323355.348698094,"close":5742.5,"open":5629.6,"low":5611.1,"tradesDone":28040,"high":5784.3}],"BITTREX":[{"exchangeCode":"BITTREX","volume":256.46137423,"date":"2019-05-01T00:00:00+00:00","volumeNotional":1365938.4123636545,"close":5326.098,"open":5320,"low":5267.502,"tradesDone":1832,"high":5387.45},{"exchangeCode":"BITTREX","volume":485.69222735,"date":"2019-05-02T00:00:00+00:00","volumeNotional":2619338.18209855,"close":5393,"open":5325.815,"low":5310,"tradesDone":2473,"high":5530}],"GDAX":[{"exchangeCode":"GDAX","volume":4840.62067229,"date":"2019-05-01T00:00:00+00:00","volumeNotional":25757668.69035593,"close":5321.15,"open":5270.68,"low":5265.59,"tradesDone":38422,"high":5358.39},{"exchangeCode":"GDAX","volume":5727.88986406,"date":"2019-05-02T00:00:00+00:00","volumeNotional":30873383.64618204,"close":5390.01,"open":5321.15,"low":5302.59,"tradesDone":38573,"high":5429.62}]}},{"ticker":"fldcbtc","baseCurrency":"fldc","quoteCurrency":"btc","priceData":[{"volume":34807.97636632,"date":"2019-05-01T00:00:00+00:00","volumeNotional":0.0066135155096008,"close":1.9e-7,"open":1.8e-7,"low":1.8e-7,"tradesDone":2,"high":1.9e-7},{"volume":283386.06880708,"date":"2019-05-02T00:00:00+00:00","volumeNotional":0.05100949238527439,"close":1.8e-7,"open":1.9e-7,"low":1.8e-7,"tradesDone":20,"high":2e-7}],"exchangeData":{"BITTREX":[{"exchangeCode":"BITTREX","volume":34807.97636632,"date":"2019-05-01T00:00:00+00:00","volumeNotional":0.0066135155096008,"close":1.9e-7,"open":1.8e-7,"low":1.8e-7,"tradesDone":2,"high":1.9e-7},{"exchangeCode":"BITTREX","volume":283386.06880708,"date":"2019-05-02T00:00:00+00:00","volumeNotional":0.05100949238527439,"close":1.8e-7,"open":1.9e-7,"low":1.8e-7,"tradesDone":20,"high":2e-7}]}}]'} headers: @@ -20,5 +20,5 @@ interactions: Server: [nginx/1.10.1] Vary: [Cookie] X-Frame-Options: [SAMEORIGIN] - status: {code: 403, message: Forbidden} + status: {code: 200, message: OK} version: 1 diff --git a/tests/fixtures/crypto_top_of_book.yaml b/tests/fixtures/crypto_top_of_book.yaml index 1d8d019..663e7cf 100644 --- a/tests/fixtures/crypto_top_of_book.yaml +++ b/tests/fixtures/crypto_top_of_book.yaml @@ -9,7 +9,7 @@ interactions: Content-Type: [application/json] User-Agent: [tiingo-python-client 0.3.2] method: GET - uri: https://api.tiingo.com/tiingo/crypto/top/?tickers=btcusd,fldcbtc&includeRawExchangeData=true + uri: https://api.tiingo.com/tiingo/crypto/top?tickers=btcusd,fldcbtc&includeRawExchangeData=true response: body: {string: '[{"ticker":"btcusd","baseCurrency":"btc","quoteCurrency":"usd","topOfBookData":[{"bidPrice":10160.51,"quoteTimestamp":"2019-10-03T23:00:15.363000+00:00","askExchange":"GEMINI","lastSize":0.001338,"askSize":0.1,"lastExchange":"BINANCE","lastPrice":8220.83,"bidExchange":"BITSTAMP","bidSize":2.88067305,"askPrice":8209.92,"lastSaleTimestamp":"2019-10-13T20:20:03.712000+00:00","lastSizeNotional":10.999470539999999}],"exchangeData":{"GEMINI":[{"bidPrice":8206.45,"exchangeCode":"GEMINI","lastSize":0.1,"quoteTimestampStr":"2019-10-03T23:00:15.363000+00:00","askSize":0.1,"lastPrice":8206.45,"lastSaleTimestampStr":"2019-10-03T23:00:09.652000+00:00","bidSize":0.1,"askPrice":8209.92}],"BITTREX":[{"bidPrice":8225.115,"exchangeCode":"BITTREX","lastSize":0.54573986,"quoteTimestampStr":"2019-10-13T20:20:03.668153+00:00","askSize":1.30618005,"lastPrice":8225.124,"lastSaleTimestampStr":"2019-10-13T20:19:52.790000+00:00","bidSize":10.25824791,"askPrice":8225.116}],"GDAX":[{"bidPrice":8225,"exchangeCode":"GDAX","lastSize":0.026867,"quoteTimestampStr":"2019-10-13T20:20:03.805667+00:00","askSize":0.07619918,"lastPrice":8228.53,"lastSaleTimestampStr":"2019-10-13T20:19:59.821000+00:00","bidSize":0.70558435,"askPrice":8228.55}],"KUCOIN":[{"bidPrice":null,"exchangeCode":"KUCOIN","lastSize":0.03,"quoteTimestampStr":"2019-10-13T20:20:03.367832+00:00","askSize":0.15054194,"lastPrice":8221,"lastSaleTimestampStr":"2019-10-13T20:20:03.568812+00:00","bidSize":null,"askPrice":8221.3}],"BINANCE":[{"bidPrice":8220.83,"exchangeCode":"BINANCE","lastSize":0.001338,"quoteTimestampStr":"2019-10-13T20:20:02.924000+00:00","askSize":0.126467,"lastPrice":8220.83,"lastSaleTimestampStr":"2019-10-13T20:20:03.712000+00:00","bidSize":0.005,"askPrice":8227.88}],"BITSTAMP":[{"bidPrice":10160.51,"exchangeCode":"BITSTAMP","lastSize":0.0097418,"quoteTimestampStr":"2019-08-27T10:02:48+00:00","askSize":0.01,"lastPrice":10162.19,"lastSaleTimestampStr":"2019-08-27T10:02:43+00:00","bidSize":2.88067305,"askPrice":10166.66}],"POLONIEX":[{"bidPrice":8214.74394741,"exchangeCode":"POLONIEX","lastSize":1.2e-7,"quoteTimestampStr":"2019-10-13T20:20:02.655109+00:00","askSize":1,"lastPrice":8224.99999998,"lastSaleTimestampStr":"2019-10-13T20:19:56+00:00","bidSize":0.00815241,"askPrice":8224.99999999}],"BIBOX":[{"bidPrice":8215.5596,"exchangeCode":"BIBOX","lastSize":0.797,"quoteTimestampStr":"2019-10-13T20:20:01.509000+00:00","askSize":0.555,"lastPrice":8225.68,"lastSaleTimestampStr":"2019-10-13T20:20:01.509000+00:00","bidSize":0.049,"askPrice":8225}],"BITFINEX":[{"bidPrice":8240.5,"exchangeCode":"BITFINEX","lastSize":0.005,"quoteTimestampStr":"2019-10-13T20:20:03.757465+00:00","askSize":0.335,"lastPrice":8242.3,"lastSaleTimestampStr":"2019-10-13T20:20:03.496000+00:00","bidSize":1.42055391,"askPrice":8246.9}],"GATECOIN":[{"bidPrice":3195.2,"exchangeCode":"GATECOIN","lastSize":0.00307,"quoteTimestampStr":"2018-12-16T00:16:40.664723+00:00","askSize":null,"lastPrice":3203,"lastSaleTimestampStr":"2018-12-15T09:25:27+00:00","bidSize":0.007,"askPrice":null}],"HITBTC":[{"bidPrice":8204.22,"exchangeCode":"HITBTC","lastSize":0.05,"quoteTimestampStr":"2019-10-13T20:20:03.295656+00:00","askSize":0.125,"lastPrice":8208.7,"lastSaleTimestampStr":"2019-10-13T20:18:09.564000+00:00","bidSize":0.14567,"askPrice":8211.44}]}},{"ticker":"fldcbtc","baseCurrency":"fldc","quoteCurrency":"btc","topOfBookData":[{"bidPrice":4e-8,"quoteTimestamp":"2019-10-13T20:18:23.845035+00:00","askExchange":"BITTREX","lastSize":200000,"askSize":982944.10988522,"lastExchange":"BITTREX","lastPrice":5e-8,"bidExchange":"BITTREX","bidSize":1596297.3588658,"askPrice":8e-8,"lastSaleTimestamp":"2019-10-13T07:45:21.210000+00:00","lastSizeNotional":0.01}],"exchangeData":{"BITTREX":[{"bidPrice":4e-8,"exchangeCode":"BITTREX","lastSize":200000,"quoteTimestampStr":"2019-10-13T20:18:23.845035+00:00","askSize":982944.10988522,"lastPrice":5e-8,"lastSaleTimestampStr":"2019-10-13T07:45:21.210000+00:00","bidSize":1596297.3588658,"askPrice":8e-8}]}}]'} headers: @@ -20,5 +20,5 @@ interactions: Server: [nginx/1.10.1] Vary: [Cookie] X-Frame-Options: [SAMEORIGIN] - status: {code: 403, message: Forbidden} + status: {code: 200, message: OK} version: 1 From c455fd856d971c0c5024c0f7b9e045f86094a902 Mon Sep 17 00:00:00 2001 From: n1rna Date: Wed, 16 Oct 2019 10:57:30 +0330 Subject: [PATCH 8/9] Remove `endDate` argument from crypto top of book endpoint --- tiingo/api.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tiingo/api.py b/tiingo/api.py index 35cde06..897326f 100644 --- a/tiingo/api.py +++ b/tiingo/api.py @@ -334,16 +334,13 @@ class TiingoClient(RestClient): # Crypto # tiingo/crypto - def get_crypto_top_of_book(self, tickers=[], - endDate=None, exchanges=[], + def get_crypto_top_of_book(self, tickers=[], exchanges=[], includeRawExchangeData=False, convertCurrency=None): url = 'https://api.tiingo.com/tiingo/crypto/top' params = { 'tickers': ','.join(tickers) } - if endDate: - params['endDate'] = endDate if len(exchanges): params['exchanges'] = ','.join(exchanges) if includeRawExchangeData is True: From fb1295376a1049b8d2d8819a648b82c9f7c0087b Mon Sep 17 00:00:00 2001 From: n1rna Date: Wed, 16 Oct 2019 11:00:29 +0330 Subject: [PATCH 9/9] Add name to AUTHORS.rst --- AUTHORS.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index c39b6a0..fcc5a57 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -14,3 +14,4 @@ Contributors * Bharat Kalluri * Stephen Clark * Davis Thames +* Nima Yazdanmehr