-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
369e762
commit bdf638c
Showing
5 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from .client import Client | ||
from .integrations.api_interfaces import ApiResponse | ||
from .integrations.exchange_api import get_all_tickers, get_ticker_by_instrument | ||
|
||
|
||
class Exchange: | ||
""" | ||
Exchange class for managing Crypto.com Exchange-related operations like retrieving ticker information (Chain agnostic). | ||
""" | ||
|
||
_client: Client | ||
|
||
@classmethod | ||
def init(cls, client: Client) -> None: | ||
""" | ||
Initialize the Exchange class with a Client instance. | ||
:param client: An instance of the Client class. | ||
""" | ||
cls._client = client | ||
|
||
@classmethod | ||
def get_all_tickers(cls) -> ApiResponse: | ||
""" | ||
Get all tickers from the Crypto.com Exchange (Chain agnostic). | ||
:return: A list of all available tickers and their information. | ||
""" | ||
return get_all_tickers() | ||
|
||
@classmethod | ||
def get_ticker_by_instrument(cls, instrument_name: str) -> ApiResponse: | ||
""" | ||
Get ticker information for a specific instrument from the Crypto.com Exchange (Chain agnostic). | ||
:param instrument_name: The name of the instrument to get ticker information for. | ||
:return: Ticker information for the specified instrument. | ||
:raises ValueError: If instrument_name is None or empty. | ||
""" | ||
if not instrument_name: | ||
raise ValueError("Instrument name is required") | ||
|
||
return get_ticker_by_instrument(instrument_name) |
50 changes: 50 additions & 0 deletions
50
crypto_com_developer_platform_client/integrations/exchange_api.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import requests | ||
|
||
from .api_interfaces import ApiResponse | ||
|
||
|
||
def get_all_tickers() -> ApiResponse: | ||
""" | ||
Get all tickers from the Crypto.com Exchange (Chain agnostic). | ||
:return: A list of all available tickers and their information. | ||
:raises Exception: If the ticker retrieval fails or the server responds with an error. | ||
""" | ||
url = f"""https://developer-platform-api.crypto.com/v1/cdc-developer-platform/exchange/tickers""" | ||
|
||
response = requests.get(url, headers={'Content-Type': 'application/json'}) | ||
|
||
if response.status_code not in (200, 201): | ||
error_body = response.json() | ||
server_error_message = ( | ||
error_body.get('error') or | ||
f"HTTP error! status: {response.status_code}" | ||
) | ||
raise Exception(f"Failed to fetch all tickers: {server_error_message}") | ||
|
||
return response.json() | ||
|
||
|
||
def get_ticker_by_instrument(instrument_name: str) -> ApiResponse: | ||
""" | ||
Get ticker information for a specific instrument from the Crypto.com Exchange (Chain agnostic). | ||
:param instrument_name: The name of the instrument to get ticker information for. | ||
:return: Ticker information for the specified instrument. | ||
:raises Exception: If the ticker retrieval fails, does not exist or the server responds with an error. | ||
""" | ||
url = f"""https://developer-platform-api.crypto.com/v1/cdc-developer-platform/exchange/tickers/{ | ||
instrument_name}""" | ||
|
||
response = requests.get(url, headers={'Content-Type': 'application/json'}) | ||
|
||
if response.status_code not in (200, 201): | ||
error_body = response.json() | ||
server_error_message = ( | ||
error_body.get('error') or | ||
f"HTTP error! status: {response.status_code}" | ||
) | ||
raise Exception(f"""Failed to fetch ticker for instrument { | ||
instrument_name}: {server_error_message}""") | ||
|
||
return response.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "crypto-com-developer-platform-client" | ||
version = "1.0.5" | ||
version = "1.0.6" | ||
description = "A python client to interact with @cryptocom/developer-platform-service" | ||
authors = ["Ric Arcifa <[email protected]>"] | ||
license = "MIT" | ||
|