Skip to content

Commit 3f340f9

Browse files
authored
Merge pull request #10 from donbagger/update-endpoints
Add contract, mapping, key info, and changelog endpoints (v1.1.0)
2 parents 5df2bdf + 7bef073 commit 3f340f9

File tree

6 files changed

+259
-5
lines changed

6 files changed

+259
-5
lines changed

.github/workflows/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
15+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
1616

1717
steps:
1818
- uses: actions/checkout@v3

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,62 @@ client = Coinpaprika.Client(api_key="YOUR-API-KEY")
3333
```
3434
API KEY can be generated [https://coinpaprika.com/api/](https://coinpaprika.com/api/).
3535

36+
## API Coverage
37+
38+
### Market Data
39+
```python
40+
client.global_market() # Global market overview
41+
client.coins() # List all coins
42+
client.coin("btc-bitcoin") # Coin details
43+
client.tickers() # All tickers
44+
client.ticker("btc-bitcoin") # Ticker for specific coin
45+
client.historical("btc-bitcoin", start="2024-01-01") # Historical tickers (Pro)
46+
```
47+
48+
### OHLCV
49+
```python
50+
client.candle("btc-bitcoin") # Latest 24h OHLCV
51+
client.ohlcv("btc-bitcoin", start="2024-01-01") # Historical OHLCV
52+
client.today("btc-bitcoin") # Today's OHLCV (updates until close)
53+
```
54+
55+
### Exchanges
56+
```python
57+
client.exchange_list() # List exchanges
58+
client.exchange("binance") # Exchange details
59+
client.exchange_markets("binance") # Markets on exchange
60+
```
61+
62+
### Contracts
63+
```python
64+
client.platforms() # List contract platforms
65+
client.contracts("eth-ethereum") # Contracts on Ethereum
66+
client.ticker_by_contract("eth-ethereum", "0xdac1...") # Ticker by contract
67+
client.historical_by_contract("eth-ethereum", "0xdac1...", start="2024-01-01") # Historical by contract
68+
```
69+
70+
### Other
71+
```python
72+
client.search(q="bitcoin") # Search coins, exchanges, people, tags
73+
client.price_converter(base_currency_id="btc-bitcoin", quote_currency_id="usd-us-dollars", amount=1)
74+
client.coin_mappings() # ID mappings to CoinGecko, CMC, etc. (Pro)
75+
client.people("vitalik-buterin") # Person details
76+
client.tags() # List tags
77+
client.tag("blockchain-service") # Tag details
78+
client.twitter("btc-bitcoin") # Twitter timeline
79+
client.events("btc-bitcoin") # Coin events
80+
client.exchanges("btc-bitcoin") # Exchanges for coin
81+
client.markets("btc-bitcoin") # Markets for coin
82+
client.key_info() # API key usage info (requires key)
83+
client.changelog_ids() # Recent changelog IDs (Pro)
84+
```
85+
3686
## Examples
3787
Check out the [./examples](./examples) directory.
3888

3989
## Tests
4090

41-
```test
91+
```bash
4292
pip install -r test_requirements.txt
4393

4494
pytest tests/test_api_request.py

coinpaprika/client.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,34 @@ def search(self, **params):
147147

148148
def price_converter(self, **params):
149149
return self._get("price-converter", data=params)
150+
151+
def coin_mappings(self, **params):
152+
"""Get ID mappings to other data providers (CoinGecko, CoinMarketCap, etc.)."""
153+
return self._get("coins/mappings", data=params)
154+
155+
def platforms(self):
156+
"""Get list of contract platforms (blockchains that support smart contracts)."""
157+
return self._get("contracts")
158+
159+
def contracts(self, platform_id):
160+
"""Get all contracts/tokens on a given platform."""
161+
return self._get("contracts/{}".format(platform_id))
162+
163+
def ticker_by_contract(self, platform_id, contract_address):
164+
"""Get ticker data for a token by its contract address on a given platform."""
165+
return self._get("contracts/{}/{}".format(platform_id, contract_address))
166+
167+
def historical_by_contract(self, platform_id, contract_address, **params):
168+
"""Get historical ticker data for a token by contract address."""
169+
return self._get(
170+
"contracts/{}/{}/historical".format(platform_id, contract_address),
171+
data=params,
172+
)
173+
174+
def key_info(self):
175+
"""Get API key usage information (requires API key)."""
176+
return self._get("key/info")
177+
178+
def changelog_ids(self):
179+
"""Get recent changelog IDs for coins that changed recently."""
180+
return self._get("changelog/ids")

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ build-backend="setuptools.build_meta"
77

88
[project]
99
name = "coinpaprika-sdk"
10-
version = "1.0.0"
10+
version = "1.1.0"
1111
authors = [
1212
{ name="coinpaprika", email="it@coinpaprika.com" },
1313
]
1414
description = "Official coinpaprika API Python client"
1515
readme = "README.md"
16-
requires-python = ">=3.7"
16+
requires-python = ">=3.9"
1717
classifiers = [
1818
"Programming Language :: Python :: 3",
1919
"License :: OSI Approved :: Apache Software License",

setup.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22

33
setup(
44
name='coinpaprika-sdk',
5-
version='1.0.0',
5+
version='1.1.0',
66
author='Coinpaprika',
77
author_email='it@coinpaprika.com',
88
description='Official coinpaprika API Python client',
99
packages=['coinpaprika'],
1010
url='https://github.com/coinpaprika/coinpaprika-api-python-client',
1111
license='Apache License 2.0',
1212
install_requires=['requests'],
13+
python_requires='>=3.9',
1314
keywords='coinpaprika api cryptocurrency',
1415
classifiers=[
1516
'Programming Language :: Python :: 3',
17+
'Programming Language :: Python :: 3.9',
18+
'Programming Language :: Python :: 3.10',
19+
'Programming Language :: Python :: 3.11',
20+
'Programming Language :: Python :: 3.12',
21+
'Programming Language :: Python :: 3.13',
1622
'License :: OSI Approved :: Apache Software License',
1723
'Operating System :: OS Independent',
1824
'Intended Audience :: Developers',

tests/test_api_request.py

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,3 +474,170 @@ def test_api_exchange_markets():
474474
result = client.exchange_markets(exchange_id="coinbase", quotes="USD")
475475

476476
assert result == expected
477+
478+
479+
def test_api_search():
480+
expected = {"currencies": [{"id": "btc-bitcoin", "name": "Bitcoin"}]}
481+
with requests_mock.mock() as m:
482+
m.get(
483+
"https://api.coinpaprika.com/v1/search?q=btc&c=currencies&limit=5",
484+
status_code=200,
485+
json=expected,
486+
)
487+
result = client.search(q="btc", c="currencies", limit=5)
488+
489+
assert result == expected
490+
491+
492+
def test_api_price_converter():
493+
expected = {
494+
"base_currency_id": "btc-bitcoin",
495+
"quote_currency_id": "usd-us-dollars",
496+
"amount": 1337,
497+
"price": 37508969,
498+
}
499+
with requests_mock.mock() as m:
500+
m.get(
501+
"https://api.coinpaprika.com/v1/price-converter?base_currency_id=btc-bitcoin&quote_currency_id=usd-us-dollars&amount=1337",
502+
status_code=200,
503+
json=expected,
504+
)
505+
result = client.price_converter(
506+
base_currency_id="btc-bitcoin",
507+
quote_currency_id="usd-us-dollars",
508+
amount=1337,
509+
)
510+
511+
assert result == expected
512+
513+
514+
def test_api_ticker():
515+
expected = {
516+
"id": "btc-bitcoin",
517+
"name": "Bitcoin",
518+
"symbol": "BTC",
519+
"quotes": {"USD": {"price": 28000}},
520+
}
521+
with requests_mock.mock() as m:
522+
m.get(
523+
"https://api.coinpaprika.com/v1/tickers/btc-bitcoin?quotes=USD",
524+
status_code=200,
525+
json=expected,
526+
)
527+
result = client.ticker(coin_id="btc-bitcoin", quotes="USD")
528+
529+
assert result == expected
530+
531+
532+
def test_api_platforms():
533+
expected = ["btc-bitcoin", "eth-ethereum", "sol-solana"]
534+
with requests_mock.mock() as m:
535+
m.get(
536+
"https://api.coinpaprika.com/v1/contracts",
537+
status_code=200,
538+
json=expected,
539+
)
540+
result = client.platforms()
541+
542+
assert result == expected
543+
544+
545+
def test_api_contracts():
546+
expected = [
547+
{
548+
"address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
549+
"type": "ERC20",
550+
"id": "usdt-tether",
551+
"active": True,
552+
},
553+
]
554+
with requests_mock.mock() as m:
555+
m.get(
556+
"https://api.coinpaprika.com/v1/contracts/eth-ethereum",
557+
status_code=200,
558+
json=expected,
559+
)
560+
result = client.contracts(platform_id="eth-ethereum")
561+
562+
assert result == expected
563+
564+
565+
def test_api_ticker_by_contract():
566+
expected = {
567+
"id": "usdt-tether",
568+
"name": "Tether",
569+
"symbol": "USDT",
570+
"quotes": {"USD": {"price": 1.0}},
571+
}
572+
with requests_mock.mock() as m:
573+
m.get(
574+
"https://api.coinpaprika.com/v1/contracts/eth-ethereum/0xdac17f958d2ee523a2206206994597c13d831ec7",
575+
status_code=200,
576+
json=expected,
577+
)
578+
result = client.ticker_by_contract(
579+
platform_id="eth-ethereum",
580+
contract_address="0xdac17f958d2ee523a2206206994597c13d831ec7",
581+
)
582+
583+
assert result == expected
584+
585+
586+
def test_api_historical_by_contract():
587+
expected = [
588+
{"timestamp": "2024-01-01T00:00:00Z", "price": 1.0, "volume_24h": 50000000000},
589+
]
590+
with requests_mock.mock() as m:
591+
m.get(
592+
"https://api.coinpaprika.com/v1/contracts/eth-ethereum/0xdac17f958d2ee523a2206206994597c13d831ec7/historical?start=2024-01-01",
593+
status_code=200,
594+
json=expected,
595+
)
596+
result = client.historical_by_contract(
597+
platform_id="eth-ethereum",
598+
contract_address="0xdac17f958d2ee523a2206206994597c13d831ec7",
599+
start="2024-01-01",
600+
)
601+
602+
assert result == expected
603+
604+
605+
def test_api_coin_mappings():
606+
expected = [
607+
{"id": "btc-bitcoin", "coingecko": "bitcoin", "coinmarketcap": 1},
608+
]
609+
with requests_mock.mock() as m:
610+
m.get(
611+
"https://api.coinpaprika.com/v1/coins/mappings",
612+
status_code=200,
613+
json=expected,
614+
)
615+
result = client.coin_mappings()
616+
617+
assert result == expected
618+
619+
620+
def test_api_key_info():
621+
expected = {"plan": "free", "usage": {"current_month": {"requests": 500}}}
622+
with requests_mock.mock() as m:
623+
m.get(
624+
"https://api.coinpaprika.com/v1/key/info",
625+
status_code=200,
626+
json=expected,
627+
)
628+
result = client.key_info()
629+
630+
assert result == expected
631+
632+
633+
def test_api_changelog_ids():
634+
expected = ["btc-bitcoin", "eth-ethereum"]
635+
with requests_mock.mock() as m:
636+
m.get(
637+
"https://api.coinpaprika.com/v1/changelog/ids",
638+
status_code=200,
639+
json=expected,
640+
)
641+
result = client.changelog_ids()
642+
643+
assert result == expected

0 commit comments

Comments
 (0)