Skip to main content

Python wrapper around Live Coin Watch API

Project description

LiveCoinWatch API wrapper

Python3 wrapper around the LiveCoinWatch API

PyPi Version Downloads GitHub

Installation

PyPI

pip install pylivecoinwatch

or from source

git clone https://github.com/PlayErphil/pylivecoinwatch.git
cd pylivecoinwatch
python3 setup.py install

Usage

Create the class.

from pylivecoinwatch import LiveCoinWatchAPI
lcw = LiveCoinWatchAPI("<YOUR_API_KEY>")

The package has no API key, so make sure to get one from the API playground and pass it as a parameter when creating the class.

API Key Error

If your API key is wrong or you didn't specify one, the class will raise 401 Error.

401 Error example:

>>> from pylivecoinwatch import LiveCoinWatchAPI
>>> lcw = LiveCoinWatchAPI()
>>> lcw.overview()

Traceback (most recent call last):

raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.livecoinwatch.com/overview

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

ValueError: {'error': {'code': 401, 'status': 'Unauthorized', 'description': 'The requester is not authorized to access the resource. This is similar to 403 but is used in cases where authentication is expected but has failed or has not been provided.'}}

If you wished to change your API key at any point you can use the following function:

lcw.set_api_key("<NEW_API_KEY>")
# This will change your API key to <NEW_API_KEY>

Usage

The required parameters for each endpoint are defined as required (mandatory) parameters for the corresponding functions. Any optional parameters can be passed using same names, as defined in LiveCoinWatch API Documentation

Booleans are supported as input for boolean type parameters; they can be str ('true', 'false') or bool (True, False) (e.g. see /coins/single usage examples).

Usage examples:

# /coins/single endpoint without the required parameters
>>> lcw.coins_single()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: coins_single() missing 1 required positional argument: 'code'


# same endpoint with the required parameters
>>> lcw.coins_single(code="BTC")
{'rate': 49810.12848625034, 'volume': 18780569901, 'cap': 942054277908}


# optional parameters can be passed as defined in the API doc (https://livecoinwatch.github.io/lcw-api-docs/)
>>> lcw.coins_single(currency="EUR", code="BTC", meta='true')
# OR (also booleans can be used for boolean type arguments)
>>> lcw.coins_single(currency="EUR", code="BTC", meta=True)
{'name': 'Bitcoin', 'symbol': '₿', 'color': '#fa9e32', 'png32': 'https://lcw.nyc3.cdn.digitaloceanspaces.com/production/currencies/32/btc.png', 'png64': 'https://lcw.nyc3.cdn.digitaloceanspaces.com/production/currencies/64/btc.png', 'webp32': 'https://lcw.nyc3.cdn.digitaloceanspaces.com/production/currencies/32/btc.webp', 'webp64': 'https://lcw.nyc3.cdn.digitaloceanspaces.com/production/currencies/64/btc.webp', 'exchanges': 171, 'markets': 4483, 'pairs': 1604, 'allTimeHighUSD': 68780.77475755227, 'circulatingSupply': 18912906, 'totalSupply': 18912906, 'maxSupply': 21000000, 'rate': 43399.258910010154, 'volume': 17172466006, 'cap': 820806104234}

API Documentation

https://livecoinwatch.github.io/lcw-api-docs/

Enpoints included

:warning: Endpoints documentation: To make sure that your are using properly each endpoint you should check the API documentation. Return behaviour and parameters of the endpoints, such as pagination, might have changed.
Any optional parameters defined in LiveCoinWatch API doc can be passed as function parameters using same parameters names with the API (see Examples above).

  • status

    • /status (Check API server status)

      lcw.status()
      

      Example:

      >>> lcw.status()
      {}
      
  • credits

    • /credits (Get your API key related information.)

      lcw.credits()
      

      Example:

      >>> lcw.credits()
      
      {'dailyCreditsRemaining': 9995, 'dailyCreditsLimit': 10000}
      
  • overview

    • /overview (Get current aggregated data for all coins.)

      lcw.overview()
      

      Example:

      >>> lcw.overview()
      
      {'cap': 2401907143522, 'volume': 70680847315, 'liquidity': 5779984192, 'btcDominance': 0.3927240083177512}
      
    • /overview/history (Get historical aggregated data of entire market.)

      lcw.overview_history()
      

      Example:

      >>> lcw.overview_history(start="1606232700000", end="1606232700000")
      
      [{'date': 1606232700000, 'cap': 581171117946, 'volume': 56158051529, 'liquidity': 1295845494, 'btcDominance': 0.6144324552690166}]
      
  • coins

    • /coins/single (Get all information about a single coin at latest moment in time.)

      lcw.coins_single()
      

      Example:

      >>> lcw.coins_single(code="BTC")
      
      {'rate': 49810.12848625034, 'volume': 18780569901, 'cap': 942054277908}
      
    • /coins/single/history (Get historical information about a single coin.)

      lcw.coins_single_history()
      

      Example:

      >>> lcw.coins_single_history(start=1617035100000, end=1617035400000, code="ETH")
      
      {'history': [{'date': 1617035100000, 'rate': 1783.635049099136, 'volume': 7615440037, 'cap': 205564989970}, {'date': 1617035400000, 'rate': 1785.1535622292442, 'volume': 7682072359, 'cap': 205741029536}]}
      
    • /coins/map (Assorted information for a custom map of coins.)

      lcw.coins_map()
      

      Example:

      >>> lcw.coins_map(currency="USD", codes=["ETH", "BTC"], code="ETH", sort="rank", order="ascending", offset=0, limit=0, meta=False)
      
      [{'code': 'BTC', 'rate': 20179.546446594384, 'volume': 21739986652, 'cap': 387234256303, 'delta': {'hour': 0.999, 'day': 1.0437, 'week': 1.0461, 'month': 1.0641, 'quarter': 0.8685, 'year': 0.3216}}, {'code': 'ETH', 'rate': 1480.8660158628147, 'volume': 17513723105, 'cap': 181219294947, 'delta': {'hour': 0.9999, 'day': 1.1029, 'week': 1.1356, 'month': 1.131, 'quarter': 0.8946, 'year': 0.3496}}]
      
    • /coins/list (Get assorted information for a list of coins.)

      lcw.coins_list()
      

      Example:

      >>> lcw.coins_list(limit=2, sort="rank", order="ascending")
      
      [{'code': 'BTC', 'rate': 49741.45295774467, 'volume': 18786805838, 'cap': 940755424093}, {'code': 'ETH', 'rate': 3944.8091570473284, 'volume': 10458770693, 'cap': 469117284843}]
      
    • /coins/contract (Get all information about a single coin at latest moment in time, based on its platform identifier and contract address.)

      lcw.coins_contract()
      

      Example:

      >>> lcw.coins_contract(currency="USD", platform="ETH", address="0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", meta=False)
      
      {'rate': 1487.490793378846, 'volume': 17716229188, 'cap': 182029994563, 'liquidity': 665137261, 'delta': {'hour': 1.0014, 'day': 1.1056, 'week': 1.1406, 'month': 1.1301, 'quarter': 0.895, 'year': 0.3517}, 'code': 'ETH'}
      
  • fiats

    • /fiats/all (Get list of all the fiats.)

      lcw.fiats_all()
      

      Example:

      >>> lcw.fiats_all()
      
      [{'code': 'PAB', 'countries': ['PAN'], 'flag': 'PAN', 'name': 'Panamanian Balboa', 'symbol': 'B/.'}, {'code': 'AZN', 'countries': ['AZE'], 'flag': 'AZE', 'name': 'Azerbaijani Manat', 'symbol': '₼'}    ...............    {'code': 'PKR', 'countries': ['PAK'], 'flag': 'PAK', 'name': 'Pakistani Rupee', 'symbol': '₨'}]
      
  • exchanges

    • /exchanges/single (Get assorted exchange information.)

      lcw.exchanges_single()
      

      Example:

      >>> lcw.exchanges_single(code="kucoin")
      
      {'code': 'kucoin', 'markets': 947, 'volume': 2916293370, 'bidTotal': 40050156.01994438, 'askTotal': 45237792.80490364, 'depth': 85287948.82484803, 'visitors': 94003, 'volumePerVisitor': 31023.407444443263}
      
    • /exchanges/list (Get assorted information on list of exchanges.)

      lcw.exchanges_list()
      

      Example:

      >>> lcw.exchanges_list(sort="visitors", order="descending", limit=2, offset=1)
      
      [{'code': 'binance', 'markets': 1302, 'volume': 16969814270, 'bidTotal': 360409773.5276142, 'askTotal': 307530423.509523, 'depth': 667940197.0371372, 'visitors': 1303774, 'volumePerVisitor': 13015.91707611902}, {'code': 'pancakeswapv2', 'markets': 3416, 'volume': 337585574, 'bidTotal': None, 'askTotal': None, 'depth': 0, 'visitors': 501047, 'volumePerVisitor': 673.7602939444803}]
      
  • platforms

    • /platforms/all (Get a list of all the coin platforms.)

      lcw.platforms_all()
      

      Example:

      >>> lcw.platforms_all()
      
      [{'code': 'BSC', 'name': 'BNB Smart Chain'}, {'name': 'Ethereum', 'code': 'ETH'}, {'name': 'BNB Beacon Chain', 'code': 'BC'}, {'name': 'Polygon', 'code': 'MATIC'}, {'name': 'Solana', 'code': 'SOL'}, {'name': 'Tron (TRC20)', 'code': 'TRX'}, {'name': 'Fantom', 'code': 'FTM'}, {'name': 'Avalanche C-Chain', 'code': 'AVAX'}, {'name': 'Huobi Eco Chain', 'code': 'HECO'}]
      

Test

Run unit tests with:

# after installing pytest using pip3
pytest tests
Make sure you add an API key for tests.

License

MIT

VERSION 1.2

  • Documentation updated
  • coins/map enpoint added
  • plataforms/all enpoint added
  • coins/contract enpoint added

VESION 1.0.1

  • Some test fixed
  • Changes in the Readme and the test documentation

VESION 1.0

  • Readme finished
  • Functions fixed to endpoints names

VERSION 0.2

  • Functions now return dict
  • Tests implemented with new API

VERSION 0.1

  • All endpoints added
  • Tests implemented
  • First release

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

pylivecoinwatch-1.2.3.tar.gz (8.6 kB view hashes)

Uploaded Source

Built Distribution

pylivecoinwatch-1.2.3-py3-none-any.whl (8.7 kB view hashes)

Uploaded Python 3

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