xjrb10 / cpro.py

Clear and concise CoinsPro API library written in Python for coins.ph

Home Page:https://coins-docs.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cpro.py 🐍

Clear and concise CoinsPro API library written in Python for coins.ph

Features / TO-DO:

Quirks:

For precision purposes, we store decimals as python standard Decimal objects, this is to prevent any inherent rounding errors. These Decimal objects should then be cast into a float or an int in order to do arithmetic operations.

Not Implemented:

  • Rate limit management
  • Enums for symbols (would require frequent updates)

Example Usage:

import os

from cpro.client.rest import BlockingHTTPClient, AsyncIOHTTPClient, APICredentials
from cpro.models.rest.request import CoinsInformationRequest
from cpro.models.rest.response import CoinsInformationResponse
from cpro.models.rest.endpoints import APIEndpoints

credentials = APICredentials(
    api_key=os.getenv("API_KEY"),
    api_secret=os.getenv("API_SECRET")
)

# blocking/non-async example:
client = BlockingHTTPClient(credentials)
response: CoinsInformationResponse = APIEndpoints.GET_ALL_USER_COINS.execute(
    client,
    CoinsInformationRequest()
)

# non-blocking/async example:
async_client = AsyncIOHTTPClient(credentials)
response: CoinsInformationResponse = await APIEndpoints.GET_ALL_USER_COINS.execute_async(
# diff:                              ^^^^^                                        ^^^^^^
    client,
    CoinsInformationRequest()
)

# >>> response: CoinsInformationResponse(coins=[Coin(coin='PHP', name='PHP', ... )])

Development

NOTE: Guide assumes you have the repository locally cloned.

Running tests:

  1. Install required test dependencies:

    pip install -e "cpro.py[test]"

  2. **Create a ./tests/.env file with your API key and secret, example in ./tests/.env.example **
  3. Run unit tests

    python -m pytest


Made as a submission for Coins.ph Hackathon 2023 ❤️

Project start: August 9, 2023

About

Clear and concise CoinsPro API library written in Python for coins.ph

https://coins-docs.github.io/

License:GNU General Public License v3.0


Languages

Language:Python 100.0%