Skip to main content

CoinAPI Python REST Client

Project description

CoinAPI REST

Coverage Status Ruff image image

Installation

pip install coinapi-rest

Example Usage

Example

import coinapi

s = coinapi.CoinAPI(
    api_key="<YOUR_API_KEY_HERE>",
)


res = s.metadata.get_v1_assets(filter_asset_id='<value>', include_supply=False)

if res.content is not None:
    # handle response
    pass

Available Resources and Operations

metadata

exchange_rates

indexes

metrics

order_book

order_book_l3

quotes

ohlcv

trades

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an error. If Error objects are specified in your OpenAPI Spec, the SDK will raise the appropriate Error type.

Error Object Status Code Content Type
errors.CoinAPIError 4x-5xx /

Example

import coinapi
from coinapi.models import errors

s = coinapi.CoinAPI(
    api_key="<YOUR_API_KEY_HERE>",
)

res = None
try:
    res = s.metadata.get_v1_assets(filter_asset_id='<value>', include_supply=False)
except errors.CoinAPIError as e:
    # handle exception
    raise (e)

if res.content is not None:
    # handle response
    pass

Server Selection

Select Server by Index

You can override the default server globally by passing a server index to the server_idx: int optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

# Server Variables
0 https://rest.coinapi.io None

Example

import coinapi

s = coinapi.CoinAPI(
    server_idx=0,
    api_key="<YOUR_API_KEY_HERE>",
)


res = s.metadata.get_v1_assets(filter_asset_id='<value>', include_supply=False)

if res.content is not None:
    # handle response
    pass

Override Server URL Per-Client

The default server can also be overridden globally by passing a URL to the server_url: str optional parameter when initializing the SDK client instance. For example:

import coinapi

s = coinapi.CoinAPI(
    server_url="https://rest.coinapi.io",
    api_key="<YOUR_API_KEY_HERE>",
)


res = s.metadata.get_v1_assets(filter_asset_id='<value>', include_supply=False)

if res.content is not None:
    # handle response
    pass

Custom HTTP Client

The CoinAPI SDK makes API calls using the httpx HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom httpx.Client object.

For example, you could specify a header for every request that this sdk makes as follows:

import coinapi
import httpx

http_client = httpx.Client(headers={'x-custom-header': 'someValue'})
s = coinapi.CoinAPI(api_key="<YOUR_API_KEY_HERE>", client=http_client)

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme
api_key apiKey API key

To authenticate with the API the api_key parameter must be set when initializing the SDK client instance. For example:

import coinapi

s = coinapi.CoinAPI(
    api_key="<YOUR_API_KEY_HERE>",
)


res = s.metadata.get_v1_assets(filter_asset_id='<value>', include_supply=False)

if res.content is not None:
    # handle response
    pass

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coinapi_rest-0.0.5.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

coinapi_rest-0.0.5-py3-none-any.whl (97.0 kB view details)

Uploaded Python 3

File details

Details for the file coinapi_rest-0.0.5.tar.gz.

File metadata

  • Download URL: coinapi_rest-0.0.5.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.19.2 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for coinapi_rest-0.0.5.tar.gz
Algorithm Hash digest
SHA256 465938ebc5f9cb005b5b389a724c9e2f9c34e81731a174425edc81f4edda1d8d
MD5 6a3defa2fde2312e5bb8ba5487823973
BLAKE2b-256 be13149c13142f69ccba07fee738d4c68b382201b099342a64b707a5dbc55d95

See more details on using hashes here.

File details

Details for the file coinapi_rest-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: coinapi_rest-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 97.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.19.2 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for coinapi_rest-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 cade70e414753dad7465f873ce9205d39673e692ce79903dfddc3eedee3e5320
MD5 bd7d40d61a980bc78a09ed44b6ba8f7c
BLAKE2b-256 09a83dc4166f5de4b963818ccc64f81446229dde8e732da6f457dee740940420

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page