### Install CryptoMarket SDK Source: https://github.com/cryptomkt/cryptomkt-python/blob/master/README.md Installs the cryptomarket-python SDK using pip. It's recommended to use a specific version for stability. ```bash pip install cryptomarket==3.3.0 ``` -------------------------------- ### REST Client - Basic Operations Source: https://github.com/cryptomkt/cryptomkt-python/blob/master/README.md Demonstrates how to instantiate the REST client and perform common operations like fetching currencies, order books, wallet balances, and creating/managing spot orders. ```python from cryptomarket.client import Client from cryptomarket.args import Account, Side, OrderType from cryptomarket.exceptions import CryptomarketSDKException # instance a client api_key='AB32B3201' api_secret='21b12401' client = Client(api_key, api_secret) # get currencies currencies = client.get_currencies() # get order books order_book = client.get_order_book_of_symbol('EOSETH') # get your wallet balances wallet_balance = client.get_wallet_balances() # get your spot trading balances trading_balance = client.get_spot_trading_balances() # move balance from wallet account to trading account transfer = client.transfer_between_wallet_and_exchange('ETH', '3.2', source=Account.WALLET, destination=Account.SPOT) # get your active spot orders orders = client.get_all_active_spot_orders('EOSETH') # create a new spot order order = client.create_spot_order('EOSETH', Side.BUY, '10', type=OrderType.MARKET) ``` -------------------------------- ### Wallet Connection and Authentication Errors Source: https://github.com/cryptomkt/cryptomkt-python/blob/master/README.md Shows how to establish a connection using the WalletClient and handle potential connection or authentication errors. It catches general exceptions during the connection process. ```python client = WalletClient(api_key, api_secret) try: client.connect() except Exception as e: # here we are catching connection and authentication errors print(e) ``` -------------------------------- ### Catching CryptomarketSDKException Source: https://github.com/cryptomkt/cryptomkt-python/blob/master/README.md Demonstrates how to catch specific exceptions from the SDK, such as when attempting to create an order with a non-existent symbol. This ensures robust error handling for API calls. ```python try: order = client.create_order( symbol='eosehtt', # non existant symbol side='sell', quantity='10', ) except CryptomarketSDKException as e: print(f'exception catched {e}') ``` -------------------------------- ### CryptoMarket API v3 - Core Endpoints Source: https://github.com/cryptomkt/cryptomkt-python/blob/master/README.md Provides an overview of key REST API endpoints for fetching market data, account information, and managing orders. This documentation is based on the Python SDK client methods. ```APIDOC GET /public/currencies - Retrieves a list of available currencies on the exchange. - Returns: List of currency objects, each with details like id, name, and withdrawal/deposit status. GET /public/symbols - Retrieves a list of all trading symbols available on the exchange. - Returns: List of symbol objects, including base/quote currencies and trading rules. GET /public/orderbook/{symbol} - Retrieves the order book for a specific trading symbol. - Parameters: - symbol: The trading symbol (e.g., 'EOSETH'). - Returns: Order book data with bids and asks. GET /account/wallet - Retrieves the user's wallet balances across all currencies. - Requires authentication. - Returns: List of wallet balance objects. GET /account/spot/trading-balances - Retrieves the user's available balances for spot trading. - Requires authentication. - Returns: List of spot trading balance objects. POST /account/transfer - Transfers funds between wallet and trading accounts. - Requires authentication. - Parameters: - currency: The currency to transfer (e.g., 'ETH'). - amount: The amount to transfer. - source: The source account ('wallet' or 'spot'). - destination: The destination account ('wallet' or 'spot'). - Returns: Transfer confirmation details. GET /orders/spot - Retrieves a list of active spot orders for the authenticated user. - Parameters: - symbol: Optional. Filter orders by trading symbol. - Requires authentication. - Returns: List of active spot order objects. POST /orders/spot - Creates a new spot order. - Requires authentication. - Parameters: - client_order_id: Unique identifier for the order. - symbol: The trading symbol (e.g., 'EOSETH'). - side: Order side ('buy' or 'sell'). - quantity: The amount of the base currency to trade. - type: Order type ('market', 'limit', 'stop-limit'). - price: Required for limit orders; the price at which to execute. - stop_price: Required for stop orders; the price that triggers the order. - Returns: Details of the created order. DELETE /orders/spot/{client_order_id} - Cancels a specific spot order by its client order ID. - Requires authentication. - Parameters: - client_order_id: The unique identifier of the order to cancel. - Returns: Confirmation of order cancellation. ``` -------------------------------- ### CryptoMarket API v3 - WebSocket Subscriptions Source: https://github.com/cryptomkt/cryptomkt-python/blob/master/README.md Details on subscribing to real-time market data and trading events via WebSockets. This documentation is based on the Python SDK client methods. ```APIDOC MarketDataClient: connect() - Establishes a connection to the market data WebSocket server. subscribe_to_trades(callback, symbols, limit) - Subscribes to real-time trade data for specified symbols. - Parameters: - callback: Function to process incoming trade data. - symbols: List of symbols to subscribe to (e.g., ['ETHBTC']). - limit: Maximum number of trades to return per symbol in snapshot. subscribe_to_ticker(callback, speed, result_callback) - Subscribes to real-time ticker updates for symbols. - Parameters: - callback: Function to process incoming ticker data. - speed: The update frequency (e.g., TickerSpeed._3_SECONDS). - result_callback: Callback for subscription confirmation or errors. close() - Closes the WebSocket connection. TradingClient: connect() - Establishes a connection to the trading WebSocket server. subscribe_to_reports(callback) - Subscribes to real-time order and trade reports. - Parameters: - callback: Function to process incoming report data. unsubscribe_to_reports() - Unsubscribes from order and trade reports. create_spot_order(client_order_id, symbol, side, quantity, price, type) - Creates a spot order via WebSocket. - Parameters are similar to the REST API POST /orders/spot. cancel_spot_order(client_order_id) - Cancels a spot order via WebSocket. - Parameters: - client_order_id: The unique identifier of the order to cancel. close() - Closes the WebSocket connection. WalletClient: connect() - Establishes a connection to the wallet WebSocket server. subscribe_to_transactions(callback) - Subscribes to real-time wallet transaction notifications. - Parameters: - callback: Function to process incoming transaction data. unsubscribe_to_transactions() - Unsubscribes from wallet transaction notifications. get_wallet_balances(callback) - Requests the user's wallet balances. - Parameters: - callback: Function to process the returned balances or errors. close() - Closes the WebSocket connection. ``` -------------------------------- ### Exception Handling Source: https://github.com/cryptomkt/cryptomkt-python/blob/master/README.md Demonstrates how to catch specific SDK exceptions, such as `CryptomarketSDKException`, when invalid arguments or API errors occur. ```python from cryptomarket.client import Client from cryptomarket.exceptions import CryptomarketSDKException api_key='AB32B3201' api_secret='21b12401' client = Client(api_key, api_secret) # catch a wrong argument try: order = client.create_order( symbol='EOSETH', side='selllll', # wrong quantity='3' ) except CryptomarketSDKException as e: print(f'exception catched {e}') ``` -------------------------------- ### Websocket TradingClient Source: https://github.com/cryptomkt/cryptomkt-python/blob/master/README.md Connects to the TradingClient for authenticated trading operations. Supports subscribing to order reports and creating/canceling spot orders. ```python from cryptomarket.ws.trading import TradingClient import time # instance a client with a 15 seconds window api_key='AB32B3201' api_secret='21b12401' client = TradingClient(api_key, api_secret, window=15_000) client.connect() # subscribe to order reports def callback(feed, feed_type): for report in feed: print(report) client.subscribe_to_reports(callback) # unsubscribe from order reports client.unsubscribe_to_reports() client_order_id = str(int(time.time()*1000)) # create an order client.create_spot_order( client_order_id=client_order_id, symbol='EOSETH', side='sell', quantity='0.01', price='10000', ) # cancel an order client.cancel_spot_order(client_order_id) # close the client client.close() ``` -------------------------------- ### Websocket Callback for Data Retrieval Source: https://github.com/cryptomkt/cryptomkt-python/blob/master/README.md Illustrates the pattern for handling responses from websocket methods. Callbacks receive an error object as the first argument and the result as the second, allowing for asynchronous data processing. ```python def callback(err, balances): if err: print(err) return print(balances) client.get_wallet_balances(callback) ``` -------------------------------- ### Websocket WalletClient Source: https://github.com/cryptomkt/cryptomkt-python/blob/master/README.md Connects to the WalletClient for authenticated wallet operations. Supports subscribing to transactions and fetching wallet balances. ```python from cryptomarket.ws.wallet import WalletClient # instance a client api_key='AB32B3201' api_secret='21b12401' client = WalletClient(api_key, api_secret) client.connect() # subscribe to wallet transactions def callback(transaction): print(transaction) client.subscribe_to_transactions(callback) # unsubscribe from wallet transactions client.unsubscribe_to_transactions() # get wallet balances def callback(err, balances): if err: print(err) return print(balances) client.get_wallet_balances(callback) # close the client client.close() ``` -------------------------------- ### Websocket Subscription Callback Source: https://github.com/cryptomkt/cryptomkt-python/blob/master/README.md Explains that websocket subscriptions also utilize callbacks, similar to data retrieval methods. These callbacks are specifically named `result_callback` and handle incoming subscription data. ```python # websocket subscriptions also have this type of callback, but is called result_callback instead ``` -------------------------------- ### Websocket MarketDataClient Source: https://github.com/cryptomkt/cryptomkt-python/blob/master/README.md Connects to the MarketDataClient to subscribe to public market data streams like trades and tickers. Requires closing the client to stop receiving messages. ```python from cryptomarket.ws.marketdata import MarketDataClient from cryptomarket.ws.models import WSTrade, WSTicker from cryptomarket.ws.enums import TickerSpeed from typing import Dict, List import time # instance a client client = MarketDataClient() client.connect() # subscribe to public trades def trades_callback(trades_by_symbol: Dict[str, List[WSTrade]], notification_type): for symbol in trades_by_symbol: trade_list = trades_by_symbol[symbol] for trade in trade_list: print(trade) client.subscribe_to_trades( callback=trades_callback, symbols=['ETHBTC'], limit=5, ) # subscribe to symbol tickers def ticker_callback(tikers_of_symbol: Dict[str, WSTicker]): for symbol in tikers_of_symbol: ticker = tikers_of_symbol[symbol] print(ticker) client.subscribe_to_ticker( callback=ticker_callback, speed=TickerSpeed._3_SECONDS, result_callback=lambda err, result: print(f'err:{err}, result:{result}') ) # run for some time time.sleep(10) # close the client client.close() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.