Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nomics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
Currencies,
ExchangeRates,
Markets,
Volume
Volume,
Usage
)

class Nomics:
Expand All @@ -19,6 +20,7 @@ def __init__(self, key):
self.ExchangeRates = ExchangeRates(self)
self.Markets = Markets(self)
self.Volume = Volume(self)
self.Usage = Usage(self)

def get_url(self, endpoint):
return "https://api.nomics.com/v1/{}?key={}".format(endpoint, self.key)
Expand Down
3 changes: 2 additions & 1 deletion nomics/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
from .currencies import Currencies
from .exchange_rates import ExchangeRates
from .markets import Markets
from .volume import Volume
from .volume import Volume
from .usage import Usage
106 changes: 47 additions & 59 deletions nomics/api/currencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@

from .api import API


class Currencies(API):
def get_currencies(self, ids, interval = None, convert = None, status = None, filter = None, sort = None,
include_transparency = False, per_page = None, page = None):
'''
def get_currencies(
self,
ids,
interval=None,
convert=None,
status=None,
filter=None,
platform_currency=None,
sort=None,
include_transparency=False,
per_page=None,
page=None,
):
"""
Returns price, volume, market cap, and rank for all currencies

:param str ids: Comma separated list of Nomics Currency IDs
Expand All @@ -29,6 +41,8 @@ def get_currencies(self, ids, interval = None, convert = None, status = None, fi
active.
Available options: "any" "new"

:param str platform-currency: Filter the results by parent platform.

:param str sort: How to sort the returned currencies. rank sorts by rank ascending and
first_priced_at sorts by when each currency was first priced by Nomics
descending.
Expand All @@ -41,98 +55,72 @@ def get_currencies(self, ids, interval = None, convert = None, status = None, fi

:param int page: Which page of items to get. Only applicable when per-page is also
supplied.
'''
"""

if type(ids) != str:
raise ValueError("ids must be a comma separated string. E.g. ids=BTC,ETH,XRP")
if interval and type(interval) != str:
raise ValueError("interval must be a comma separated string. E.g. 1d,7d,30d,365d,ytd")

raise ValueError(
"interval must be a comma separated string. E.g. 1d,7d,30d,365d,ytd"
)

url = self.client.get_url('currencies/ticker')
url = self.client.get_url("currencies/ticker")
params = {
'ids': ids,
'interval': interval,
'convert': convert,
'status': status,
'filter': filter,
'sort': sort,
'include-transparency': include_transparency or None,
'per-page': per_page,
'page': page
"ids": ids,
"interval": interval,
"convert": convert,
"status": status,
"filter": filter,
"platform-currency": platform_currency,
"sort": sort,
"include-transparency": include_transparency or None,
"per-page": per_page,
"page": page,
}

resp = requests.get(url, params = params)
resp = requests.get(url, params=params)

if resp.status_code == 200:
return resp.json()
else:
return resp.text

def get_metadata(self, ids = None, attributes = None):
'''
def get_metadata(self, ids=None, attributes=None):
"""
Returns all the currencies and their metadata that Nomics supports

:param [str] ids: Comma separated list of Nomics Currency IDs
:param [str] ids: Comma separated list of Nomics Currency IDs
to filter result rows. Optional

:param [str] attributes: Comma separated list of currency attributes to filter result columns
Optional
'''

url = self.client.get_url('currencies')
params = {
'ids': ids,
'attributes': attributes
}

resp = requests.get(url, params = params)

if resp.status_code == 200:
return resp.json()
else:
return resp.text

def get_sparkline(self, start, end = None):
'''
Returns prices for all currencies within a customizable time interval suitable for sparkline charts.
"""

:param str start: Start time of the interval in RFC3339 format
url = self.client.get_url("currencies")
params = {"ids": ids, "attributes": attributes}

:param str end: End time of the interval in RFC3339 format. If not provided, the current time is used.
'''

url = self.client.get_url('currencies/sparkline')
params = {
'start': start,
'end': end
}

resp = requests.get(url, params = params)
resp = requests.get(url, params=params)

if resp.status_code == 200:
return resp.json()
else:
return resp.text

def get_supplies_interval(self, start, end = None):
'''
def get_supplies_interval(self, start, end=None):
"""
Returns the open and close suplly information for all currencies between a customizable time interval

:param str start: Start time of the interval in RFC3339 format

:param str end: End time of the interval in RFC3339 format. If not provided, the current time is used.
'''
"""

url = self.client.get_url('supplies/interval')
params = {
'start': start,
'end': end
}
url = self.client.get_url("supplies/interval")
params = {"start": start, "end": end}

resp = requests.get(url, params = params)
resp = requests.get(url, params=params)

if resp.status_code == 200:
return resp.json()
else:
return resp.text
return resp.text
51 changes: 51 additions & 0 deletions nomics/api/usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import requests

from .api import API


class Usage(API):
def API_History(self, start=None, end=None):
"""
Returns historical API usage data for metered API keys.

:param [str] start: Start time in IS8601 format.
Optional

:param [str] end: End time in IS8601 format. At most 30 days past start.
Optional

"""

url = self.client.get_url("meta/usage")
if (start and end) == None:
params = {
"start": start,
"end": end,
}
else:
params = {
}

resp = requests.get(url, params=params)

if resp.status_code == 200:
return resp.json()
else:
return resp.text

def API_Summary(self):
"""
Returns summary of the API calls made during the current billing period.

"""

url = self.client.get_url("meta/overage")
params = {
}

resp = requests.get(url, params=params)

if resp.status_code == 200:
return resp.json()
else:
return resp.text
5 changes: 0 additions & 5 deletions tests/test_currencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ def test_get_metadata(nomics):
assert isinstance(data, list)
assert len(data) > 0

def test_get_sparkline(nomics):
data = nomics.Currencies.get_sparkline(start = "2020-04-01T00:00:00Z")
assert isinstance(data, list)
assert len(data) > 0

def test_get_supplies_interval(nomics):
data = nomics.Currencies.get_supplies_interval(start = "2018-04-14T00:00:00Z")
assert isinstance(data, list)
Expand Down
19 changes: 19 additions & 0 deletions tests/test_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import logging
import pytest

from config import NOMICS_API_KEY
from nomics import Nomics

@pytest.fixture
def nomics():
return Nomics(NOMICS_API_KEY)

def test_API_History(nomics):
data = nomics.Usage.API_History(start = "2022-04-14T00:00:00Z", end = "2022-04-20T00:00:00Z")
assert isinstance(data, list)
assert len(data) > 0

def test_API_Summary(nomics):
data = nomics.Usage.API_Summary()
assert isinstance(data, dict)
assert len(data) > 0