Coinmetrics: Release 0.2.4
Coinmetrics: Release 0.2.4
Coinmetrics: Release 0.2.4
Release 0.2.4
Robert Rice
1 Installation 3
1.1 Install with pip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Manual Install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 API Reference 5
2.1 Base . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Community . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3 Pro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.4 Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3 Usage 15
3.1 Fetching Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2 Transforming Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4 Thanks 17
Index 21
i
ii
coinmetrics, Release 0.2.4
Note: This module only impliments the Community API (i.e. anything without an API key).
This API for Python 3 provides a convenient interface for developers wanting to use Coin Metrics data.
• The code supporting this can be on Github.
• Batteries (i.e. Python API Reference and Usage examples) are included.
• Setup instructions are provided on the Installation page.
CONTENTS: 1
coinmetrics, Release 0.2.4
2 CONTENTS:
CHAPTER
ONE
INSTALLATION
Now that you have everything installed, you can refer to the Usage page for some code snippets.
3
coinmetrics, Release 0.2.4
4 Chapter 1. Installation
CHAPTER
TWO
API REFERENCE
The Coin Metrics API provides discovery mechanisms, network, exchange, and asset data via a direct JSON REST
API. This module acts as a client interface.
The Base and Community APIs are available to all users without an API key. The Pro API does require an API key
that is only obtainable though CM Network Data Pro.
Note: The following arguments can consist of a single element or a comma delimited list within a string. A Python
list is not valid at this time.
• Asset: btc or btc,ltc,eth
• Metric: PriceUSD or NVTAdj,NVTAdj90,PriceUSD
• Exchange: coinbase or bitfinex,coinbase,kraken
• Market: bitfinex-btc-usd-spot or bitfinex-btc-usd-spot, bitfinex-eth-usd-spot,
kraken-btc-usd-spot
2.1 Base
This is the core definition for all v2+ Coinmetrics APIs, both Community and Pro. This object includes the primary
query device, all *_checker functions and the necessary discovery methods to enable the them.
class coinmetrics.base.Base(api_key=”)
Coin Metrics API Base Object
__init__(api_key=”)
Initialize API to use the Base API endpoints by default. An optional api_key can be supplied.
Parameters api_key (str, optional) – API key to be used for the Pro API.
_api_query(endpoint, options=None)
Execute the raw API query and return the raw JSON output.
Parameters
• endpoint (string) – URL Path the query will be sent to. This includes any URL
based parameters.
5
coinmetrics, Release 0.2.4
A group of alternative methods that function identically to the references functions above. This is to support any
legacy API method names.
class coinmetrics.base.Base(api_key=”)
Coin Metrics API Base Object
get_supported_assets()
An alias for get_assets()
assets()
An alias for get_assets()
getmetrics()
An alias for get_metrics()
metrics()
An alias for get_metrics()
getexchanges()
An alias for get_exchanges()
exchange()
An alias for get_exchanges()
getmarkets()
An alias for get_markets()
markets()
An alias for get_markets()
2.2 Community
The Community class is an extension of the the Base class and in inherits all of the Base class’ functionality.
class coinmetrics.community.Community(api_key=”)
Coin Metrics API Community Object
__init__(api_key=”)
Initialize the Community API exactly the same way as the same way as coinmetrics.base.Base.
__init__(). An optional api_key can be supplied.
Parameters api_key (str, optional) – API key to be used for the Pro API.
get_asset_info(assets=”)
Fetch asset(s) information. Including exchanges the asset is in, friendly name, markets, metrics, and most
recent and oldest data timestamps. No specified asset will return all available asset info.
Parameters assets (str, optional) – Unique ID corresponding to the asset’s ticker.
2.2. Community 7
coinmetrics, Release 0.2.4
The methods are designed to provide a simple way to get a single metric, and essentially extend the coinmetrics.
community.Community.get_asset_metric_data() method.
class coinmetrics.community.Community(api_key=”)
Coin Metrics API Community Object
get_available_data_types_for_asset(asset)
An alias for get_asset_metrics() (backwards compatibility)
get_asset_data_for_time_range(asset, metrics, start, end, time_agg=’day’)
An alias for get_asset_metric_data() (backwards compatibility)
2.2. Community 9
coinmetrics, Release 0.2.4
by 365), and divided by the current supply on that day. Also referred to as the annual inflation rate. See:
Data Dictionary.
Parameters See see get_asset_metric_data() for parameter and return details.
get_units_issued_usd(assets, start, end)
The sum USD value of all new native units issued that day. See: Data Dictionary.
Parameters See see get_asset_metric_data() for parameter and return details.
get_nvt_adj(assets, start, end)
The ratio of the network value (or market capitalization, current supply) divided by the adjusted transfer
value. Also referred to as NVT. See: Data Dictionary.
Parameters See see get_asset_metric_data() for parameter and return details.
get_nvt_adj_90(assets, start, end)
The ratio of the network value (or market capitalization, current supply) to the 90-day moving average of
the adjusted transfer value. Also referred to as NVT. See: Data Dictionary.
Parameters See see get_asset_metric_data() for parameter and return details.
get_price_btc(assets, start, end)
The fixed closing price of the asset as of 00:00 UTC the following day (i.e., midnight UTC of the current
day) denominated in USD. This price is generated by Coin Metrics’ fixing/reference rate service. See:
Data Dictionary.
Parameters See see get_asset_metric_data() for parameter and return details.
get_price_usd(assets, start, end)
The fixed closing price of the asset as of 00:00 UTC the following day (i.e., midnight UTC of the current
day) denominated in BTC. See: Data Dictionary.
Parameters See see get_asset_metric_data() for parameter and return details.
get_cur_sply(assets, start, end)
The sum of all native units ever created and visible on the ledger (i.e., issued) as of that day. For account-
based protocols, only accounts with positive balances are counted. See: Data Dictionary.
Parameters See see get_asset_metric_data() for parameter and return details.
get_tx_count(assets, start, end)
The sum count of transactions that day. Transactions represent a bundle of intended actions to alter the
ledger initiated by a user (human or machine). See: Data Dictionary.
Parameters See see get_asset_metric_data() for parameter and return details.
get_txtfr_count(assets, start, end)
The sum count of transfers that day. Transfers represent movements of native units from one ledger entity
to another distinct ledger entity. See: Data Dictionary.
Parameters See see get_asset_metric_data() for parameter and return details.
get_txtfr_val_adj(assets, start, end)
The sum of native units transferred that day removing noise and certain artifacts. See: Data Dictionary.
Parameters See see get_asset_metric_data() for parameter and return details.
get_txtfr_val_adj_usd(assets, start, end)
The USD value of the sum of native units transferred that day removing noise and certain artifacts. See:
Data Dictionary.
Parameters See see get_asset_metric_data() for parameter and return details.
Note: The conveniance methods are not explicitly included in the coverage testing at this time.
There are a very large number of aliases for the Conveniance Methods above, that can be found in the code under each
method definition. Below is an example of the aliases for get_active_addresses().
2.2. Community 11
coinmetrics, Release 0.2.4
# Method definition:
def get_active_addresses(self, assets, start, end):
return self.get_asset_metric_data(assets, "AdrActCnt", start, end)
# Alias definition:
active_addresses, activeaddresses, AdrActCnt = [get_active_addresses] * 3
The complete list of available aliases can be found using the following lines of code.
2.3 Pro
Note: The Pro class of APIs are planned but not currently available through this API library. For information
regarding the development of the ProAPIs, please see the related GitHub Issue.
2.4 Utilities
2.4. Utilities 13
coinmetrics, Release 0.2.4
THREE
USAGE
# Initialize a reference object, in this case `cm` for the Community API
cm = coinmetrics.Community()
# Fetch the `PriceUSD` and `ROI30d` data for BTC from 2019-01-01 to 2019-01-08.
asset = "btc"
metric = "PriceUSD,ROI30d"
begin_timestamp = "2019-01-01" # The `datetime` type is also accepted
end_timestamp = "2019-01-08" # The `datetime` type is also accepted
asset_data = cm.get_asset_data_for_time_range(asset, metric, begin_timestamp, end_
˓→timestamp)
# Convert the data object we recieved to a Pandas DataFrame for further processing.
# We are reusing the `asset_data` from the previous step.
pandas_data_frame = coinmetrics.cm_to_pandas(asset_data)
print("pandas data frame:\n", pandas_data_frame)
15
coinmetrics, Release 0.2.4
From here, the sky is the limit. Apply your logic and profit.
16 Chapter 3. Usage
CHAPTER
FOUR
THANKS
A huge thanks to Coin Metrics (coinmetrics.io) for providing a community edition of the API and providing the world
with a bit more trustworthy data in an age of misinformation.
The official API reference that this project is based on can be found on Coin Metrics’ API Reference
17
coinmetrics, Release 0.2.4
18 Chapter 4. Thanks
PYTHON MODULE INDEX
c
coinmetrics.utils, 12
19
coinmetrics, Release 0.2.4
21
coinmetrics, Release 0.2.4
metrics.community.Community method), 11
10 getexchanges() (coinmetrics.base.Base method), 7
get_real_cap() (coin- getmarkets() (coinmetrics.base.Base method), 7
metrics.community.Community method), getmetrics() (coinmetrics.base.Base method), 7
9
get_supported_assets() (coinmetrics.base.Base M
method), 7 market_checker() (coinmetrics.base.Base method),
get_tx_count() (coin- 6
metrics.community.Community method), markets() (coinmetrics.base.Base method), 7
10 metric_checker() (coinmetrics.base.Base method),
get_txtfr_count() (coin- 6
metrics.community.Community method), metrics() (coinmetrics.base.Base method), 7
10
get_txtfr_val() (coin- N
metrics.community.Community method), normalize() (in module coinmetrics.utils), 12
11
get_txtfr_val_adj() (coin- T
metrics.community.Community method),
timestamp_checker() (coinmetrics.base.Base
10
method), 6
get_txtfr_val_adj_usd() (coin-
metrics.community.Community method),
10
get_txtfr_val_mean() (coin-
metrics.community.Community method),
10
get_txtfr_val_mean_usd() (coin-
metrics.community.Community method),
11
get_txtfr_val_med() (coin-
metrics.community.Community method),
11
get_txtfr_val_med_usd() (coin-
metrics.community.Community method),
11
get_txtfr_val_usd() (coin-
metrics.community.Community method),
11
get_units_issued() (coin-
metrics.community.Community method),
9
get_units_issued_ann_pct() (coin-
metrics.community.Community method),
9
get_units_issued_usd() (coin-
metrics.community.Community method),
10
get_vty_ret_180d() (coin-
metrics.community.Community method),
11
get_vty_ret_30d() (coin-
metrics.community.Community method),
11
get_vty_ret_60d() (coin-
metrics.community.Community method),
22 Index