lagerfeuer / cryptocompare Goto Github PK
View Code? Open in Web Editor NEWPython3 Wrapper for the CryptoCompare API
License: MIT License
Python3 Wrapper for the CryptoCompare API
License: MIT License
If cryptocompare is queried too frequently I get the error message:
"[ERROR] You are over your rate limit please upgrade your account!"
Using get_historical_price_hour it will then return None. However I like to know itΕ because of the limitation and not e.g. coin is not supported. I do I do that?
Add unit tests to give a better testing experience when developing the library.
Cryptocompare appears to have implemented an exchange list API endpoint, though as of writing this, it was undocumented.
Add a workflow that will automatically upload the package to pypi if it is pushed with a version tag vX.X.X
.
Add get_pairs()
to module, to tests, and to README. Gets all pairs for an exchange, if passed, or all pairs for all exchanges otherwise.
please take a look at this patch
ps this is still the best library for getting quotes on pypi. would be nice if you keep working on this.
An error occurs when install the package by pip
$ pip install cryptocompare
Collecting cryptocompare
Using cached cryptocompare-0.3.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/private/var/folders/hc/jf7tmyyn3fq_8d7l7m_fm09c0000gn/T/pip-build-s3mE1w/cryptocompare/setup.py", line 3, in
with open('README.rst', encoding="utf-8") as f:
TypeError: 'encoding' is an invalid keyword argument for this functionCommand "python setup.py egg_info" failed with error code 1 in /private/var/folders/hc/jf7tmyyn3fq_8d7l7m_fm09c0000gn/T/pip-build-s3mE1w/cryptocompare/
I would like to know the historical value of coins from yesterday:
import cryptocompare
from datetime import datetime, timedelta
yesterday = datetime.now() - timedelta(1)
coin_list = ['BTC', 'XRP']
print(cryptocompare.get_historical_price(coin_list, 'EUR', yesterday))
I get the error:
[ERROR] There is no data for the symbol ['BTC', 'XRP'] .
Which forces me to request one coin at the time, which is quite slow..
Does cryptocompare supports proxy ? If yes How Could I redirect it's traffic via a proxy ?
Hey guys, just wanted to say that I really appreciate the work. Glad someone was able to get the API working in Python. Was wondering if you would be able to add in an API function for hourly historical data? Its already a function provided by Cryptocompare (HistoHour). Thanks.
get_avg (generateAvg on CryptoCompare) does not work anymore, not even the examples provided by CryptoCompare. They exit with error: "e param seems to be missing."
Hi,
I was wondering if there is a way to set the limit in historical data to ALL or MAX.
eg:
data = get_historical_price_minute('BTC', 'EUR', limit=ALL/MAX, exchange='CCCAGG', toTs=datetime.datetime.now())
I currently get "limit is larger than max value" when I use a large number for the limit.
Thanks.
Calling: cryptocompare.get_historical_price_day('ETH')
seems to have price errors compared with the REST api.
library returns most recent as:
{'time': 1675814400,
'high': 1580.22,
'low': 1552.67,
'open': 1557.99,
'volumefrom': 12791.86,
'volumeto': 19984578.54,
'close': 1561.35,
'conversionType': 'direct',
'conversionSymbol': ''}
https://min-api.cryptocompare.com/data/v2/histoday?fsym=ETH&tsym=USD&limit=10 - return
time: 1674950400
high: 1658.36
low: 1566.99
open: 1572.46
volumefrom: 502089.89
volumeto: 812096302.45
close: 1645.46
conversionType: "direct"
conversionSymbol: ""
Still maintain?
First off, thanks for this convenient library π
If I had one wish it would be to add the parameter 'e' to the method get_historical_price(). It is mentioned on the cryptocompare.com website and enables the caller to select a specific exchange as source for the historical price instead of the default cryptocompare.com aggregate CCCAGG.
I encountered recently issue with getting historical data during runtime app, for example Pyqt5 or even
running it on jupyter notebook. Here is example data:
Time now: 2023-06-13 12:07:23.156518
Time of data: 2023-06-13 02:09:00
{'time': 1686614940,
'high': 25901.76,
'low': 25894.92,
'open': 25895.07,
'volumefrom': 4.707,
'volumeto': 121916.59,
'close': 25901.42,
'conversionType': 'direct',
'conversionSymbol': ''}
The reason of that difference of time is because i ran kernel at night.
It always returns the data from the time kernel was started, so to get the real time data i would have to restart the kernel.
The same thing happens when using application in Pyqt5. However using cryptocompare.get_price(...)
it always returns the newest value. Somewhere i read that it could be caching mechanism implemented in the library I am not sure if it was meant to be like this. Is there any solution to overcome this problem? Maybe it's only at my side and just can't address the issue.
Hi,
I would like advice to build the same function but to get all history of data (Close, dates, volume) between two dates :)
And for all tradable pairs
Could you please help me ? thanks
def get_historical_price(coin, curr=CURR, timestamp=time.time()):
if isinstance(timestamp, datetime.datetime):
timestamp = time.mktime(timestamp.timetuple())
return query_cryptocompare(URL_HIST_PRICE.format(coin, format_parameter(curr), int(timestamp)))
coin_price = (cryptocompare.get_price(coin,curr='USD',full=False))
dictlist = list(coin_price.values())
print(dictlist[0])
This gives us "{'USD': 0.06061}". Is it possible to just get the numerical value (0.06061) instead of getting the whole string "{'USD': 0.06061}"? This would be useful in further computations
All query functions shall use **kwargs
as the single argument, removing the need to specify each field separately and allowing users to pass all supported arguments by the API.
To do some testing on my local windows machine I want to update a SQLite database with an API call to Cryptocompare. However, I get different JSON back in Ubuntu (WSL) than I get back in Windows. Weird! This becomes a problem later when I parse the JSON into SQLite. To make matters even stranger, this works fine on my Ubuntu VM instance on Google Cloud.
In Ubuntu in Windows WS I run this and get this:
res = cryptocompare.get_historical_price_minute('BTC', curr='USD',limit=1) print(res)
[{'time': 1580058960, 'close': 8561, 'high': 8569.55, 'low': 8561, 'open': 8565.61, 'volumefrom': 35.27, 'volumeto': 302097.78}, {'time': 1580059020, 'close': 8554.96, 'high': 8561, 'low': 8554.96, 'open': 8561, 'volumefrom': 0, 'volumeto': 0}]
Under Windows Python I get this:
res = cryptocompare.get_historical_price_minute('BTC', curr='USD',limit=1)
print(res)
{'Response': 'Success', 'Type': 100, 'Aggregated': False, 'Data': [{'time': 1580059800, 'close': 8564.72, 'high': 8565.85, 'low': 8561.4, 'open': 8561.4, 'volumefrom': 9.249, 'volumeto': 79165.7}, {'time': 1580059860, 'close': 8564.51, 'high': 8564.72, 'low': 8564.51, 'open': 8564.72, 'volumefrom': 0, 'volumeto': 0}], 'TimeTo': 1580059860, 'TimeFrom': 1580059800, 'FirstValueInArray': True, 'ConversionType': {'type': 'direct', 'conversionSymbol': ''}, 'RateLimit': {}, 'HasWarning': False}
Hi,
suddenly i cant retrieve coin info no more. It throws this error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "..\cryptocompare.py", line 52, in get_coin_list
response = query_cryptocompare(URL_COIN_LIST, False)['Data']
TypeError: 'NoneType' object is not subscriptable
Error getting coin information. Expecting value: line 1 column 1 (char 0)
I am new to coding, so i dont know if thats really an issue of crypto compare, but i tried in a fresh console and i got same error. Maybe could some look into it.
now i need to do this: Pull out a request for all the coins on the list then print it's length
list=cryptocompare.get_coin_list(format=True)
print(len(list))
i wont something lees invasive like: Guste pool out the length
Number=cryptocompare.get_coin_list_number()
print(Number)
PS: if there is all ready a way i'm sorry
I think I found a bug that occurs in get_historical_price_hour_from
(and I think in get_historical_price_day_from
as well, but I only used get_historical_price_hour_from
so I will be talking about this function).
So basically if I understand your code correctly, you keep fetching the price history until we are at fromTs
, but basically if price history is not available (because we go beyond the time where price history is stored) it returns only zeroes: {'time': xxxxxxx, 'high': 0, 'low': 0, 'open': 0, 'volumefrom': 0, 'volumeto': 0, 'close': 0, 'conversionType': 'direct', 'conversionSymbol': ''}
and you remove those from the list in validHist = [elem for elem in p if elem["time"] >= fromTs_i and elem["open"] != 0 and elem["close"] != 0]
. So for example I would get this response if I try to get the price history of Ethereum on January 1st 2000. I would get only zeroes because Ethereum didn't exist back then.
And I think you also assumed that. Because a few lines later at if len(validHist) < len(p): break
, you check if we removed some zero entries (and elem["time"] >= fromTs_i
but that is not important for this story) and if we did, you assume that we reached the end of valid price histories and we break out of the while loop. However, when fetching the price history of Solana (but it applies to other coins as well), I got this:
For whatever reason, the price history sometimes has zero entries in it, even though we haven't reached the end yet! In my example, I was fetching from January 1st 2010 (just a lower bound to indicate that I want all the possible price history available) until July 1st 2023. But it prematurely terminated in this loop, even though there is more price history to fetch!
A possible fix could be to not terminate when we removed at least 1 entry, but to keep going until all 2000 (or to how much limit
is set) entries are zero entries. In that case you are absolutely sure that you reached the very beginning of a coin's price history.
Hi,
import cryptocompare as cr
from dotenv import load_dotenv # add this line for api key loading
import os
load_dotenv()
apikey=os.getenv('API_KEY')
(api key loaded successfully, the same as created).
# setting the key for cryptocompare library
cr.cryptocompare._set_api_key_parameter(apikey)
# response is ok, '&api_key=xxx(my api key here)'
but, when I am trying:
btc=cr.get_historical_price_day('BTC', currency='USD', limit=30)
I constantly get an error that I am over my rate limit.
Can you please direct me what I am doing wrong?
As title.
In following crptocompare API example, the variable limit works with aggregation number. However I don't find aggregation in your code.
The number of data points to return. If limit * aggregate > 2000 we reduce the limit param on our side. So a limit of 1000 and an aggerate of 4 would only return 2000 (max points) / 4 (aggregation size) = 500 total points + current one so 501. [ Min - 1] [ Max - 2000] [ Default - 168]
Can you explain how to understand variable limit? For example, if the return data points is 10 for a specific time, what does it mean?
Thank you!
In the Cryptocompare documentation these is a "News" section. Is this support in this wrapper because I can not find it.
In order to achieve 100% test coverage, find a way to imitate failing requests.
requirements.txt
is a mess right now, I accidentally exported my entire venv
folder. Clean it up and therefore remove the noise.
Hi,
I was wondering if it is possible to get the price and print of a coin as a string.
BTC = cryptocompare.get_price(currency='usd', coin='btc')
then
print(BTC)
This prints as a Python dictionary. What I want is to print only the price as text. I tried to measure the problem as a nested dictionary but I couldn't succeed.
Thanks already.
SOLUTION: Actually I found an issue on my code, print(BTC['BTC']['USD'])
basically this gives only the price.
Document the source code so that code completion will show doc strings when using cryptocompare.
Is there a way to pass CryptoCompare API keys to pull down more data?
I keep getting this error:
NameError: name 'TICKER' is not defined
When I run:
from cryptofeed import FeedHandler
fh = FeedHandler()
# ticker, trade, and book are user defined functions that
# will be called when ticker, trade and book updates are received
ticker_cb = {TICKER: TickerCallback(ticker)}
trade_cb = {TRADES: TradeCallback(trade)}
gemini_cb = {TRADES: TradeCallback(trade), L2_BOOK: BookCallback(book)}
fh.add_feed(Coinbase(pairs=['BTC-USD'], channels=[TICKER], callbacks=ticker_cb))
fh.add_feed(Bitfinex(pairs=['BTC-USD'], channels=[TICKER], callbacks=ticker_cb))
fh.add_feed(Poloniex(pairs=['BTC-USDT'], channels=[TRADES], callbacks=trade_cb))
fh.add_feed(Gemini(pairs=['BTC-USD', 'ETH-USD'], channels=[TRADES, L2_BOOK], callbacks=gemini_cb))
fh.run()
Both here and on PyPi, the documentation says to use the curr
argument to set currency, but I found some of my old code not working, checked the latest updates, and it looks like curr
has been changed to currency
, with no changes in documentation.
{'BTC': {'INR': 0.04166}}
Return a wrong BTC-INR value
In the cryptocompare API, it's possible to pass the exchange via the e argument to get_historical_price_minute (hour and day), but not currently through this package. This addition needs to be made to each of those three functions, to the tests, and to the README.
I've made the (pretty straightforward) changes in this Pull Request: #32
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.