mirror of
https://github.com/hydrosquall/tiingo-python.git
synced 2026-02-01 09:04:18 +01:00
Merge pull request #340 from n1rna/crypto-support
Add support for tiingo crypto endpoints to TiingoClient
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -73,3 +73,7 @@ travis_pypi_setup.py
|
||||
# Jupyter
|
||||
examples/.ipynb_checkpoints
|
||||
|
||||
# vs code
|
||||
.vscode/
|
||||
.history/
|
||||
|
||||
|
||||
@@ -14,3 +14,4 @@ Contributors
|
||||
* Bharat Kalluri
|
||||
* Stephen Clark <steveclarkcode@gmail.com>
|
||||
* Davis Thames
|
||||
* Nima Yazdanmehr
|
||||
|
||||
24
tests/fixtures/crypto_metadata.yaml
vendored
Normal file
24
tests/fixtures/crypto_metadata.yaml
vendored
Normal file
@@ -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: 200, message: OK}
|
||||
version: 1
|
||||
24
tests/fixtures/crypto_price_history.yaml
vendored
Normal file
24
tests/fixtures/crypto_price_history.yaml
vendored
Normal file
@@ -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: 200, message: OK}
|
||||
version: 1
|
||||
24
tests/fixtures/crypto_top_of_book.yaml
vendored
Normal file
24
tests/fixtures/crypto_top_of_book.yaml
vendored
Normal file
@@ -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: 200, message: OK}
|
||||
version: 1
|
||||
40
tests/test_crypto.py
Normal file
40
tests/test_crypto.py
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python
|
||||
"""Tests for `tiingo` package."""
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
import vcr
|
||||
|
||||
from tiingo import TiingoClient
|
||||
|
||||
|
||||
# CRYPTO ENDPOINTS
|
||||
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_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)
|
||||
assert 'topOfBookData' in top_of_book
|
||||
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='1day')
|
||||
assert len(price_history) == 2
|
||||
assert len(price_history[0]['priceData']) in [6, 7]
|
||||
assert 'exchangeData' in price_history[0]
|
||||
@@ -331,3 +331,63 @@ 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=[], exchanges=[],
|
||||
includeRawExchangeData=False, convertCurrency=None):
|
||||
url = 'https://api.tiingo.com/tiingo/crypto/top'
|
||||
params = {
|
||||
'tickers': ','.join(tickers)
|
||||
}
|
||||
|
||||
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'] = includeRawExchangeData
|
||||
if resampleFreq:
|
||||
params['resampleFreq'] = resampleFreq
|
||||
if convertCurrency:
|
||||
params['convertCurrency'] = convertCurrency
|
||||
|
||||
response = self._request('GET', url, params=params)
|
||||
return response.json()
|
||||
|
||||
def get_crypto_metadata(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()
|
||||
|
||||
Reference in New Issue
Block a user