Package: cryptomarket
CryptoMarket-Pythonmain pagesign up in CryptoMarket.InstallationTo install Cryptomarket use pippip install cryptomarketDocumentationThis sdk makes use of theapi version 3of cryptomarketQuick Startrest clientfromcryptomarket.clientimportClientfromcryptomarket.argsimportAccount,Side,OrderTypefromcryptomarket.exceptionsimportCryptomarketSDKException# instance a clientapi_key='AB32B3201'api_secret='21b12401'client=Client(api_key,api_secret)# get currenciescurrencies=client.get_currencies()# get order booksorder_book=client.get_order_book_of_symbol('EOSETH')# get your wallet balanceswallet_balance=client.get_wallet_balances()# get your spot trading balancestrading_balance=client.get_spot_trading_balances()# move balance from wallet account to trading accounttransfer=client.transfer_between_wallet_and_exchange('ETH','3.2',source=Account.WALLET,destination=Account.SPOT)# get your active spot ordersorders=client.get_all_active_spot_orders('EOSETH')# create a new spot orderorder=client.create_spot_order('EOSETH',Side.BUY,'10',type=OrderType.MARKET)Websocket Clientsthere are three websocket clients,MarketDataClient, theTradingClientand theWalletClient. TheMarketDataClientis public, while the others require authentication to be used.Some subscription callbacks take a second argument, indicating the type of notification, either 'snapshsot' or 'update'.MarketDataClientThere are no unsubscriptions methods for theMarketDataClient. To stop recieving messages is recomended to close theMarketDataClient.# instance a clientclient=MarketDataClient()client.connect()# subscribe to public tradesdeftrades_callback(trades_by_symbol:Dict[str,List[WSTrade]],notification_type):forsymbolintrades_by_symbol:trade_list=trades_by_symbol[symbol]fortradeintrade_list:print(trade)client.subscribe_to_trades(callback=trades_callback,symbols=['ETHBTC'],limit=5,)# subscribe to symbol tickersdefticker_callback(tikers_of_symbol:Dict[str,WSTicker]):forsymbolintikers_of_symbol:ticker=tikers_of_symbol[symbol]print(ticker)client.subscribe_to_ticker(callback=ticker_callback,speed=TickerSpeed._3_SECONDS,result_callback=lambdaerr,result:print(f'err:{err}, result:{result}'))# run for some timetime.sleep(10)# close the clientclient.close()TradingClient# instance a client with a 15 seconds windowclient=TradingClient(api_key,api_secret,window=15_000)client.connect()# close the clientclient.close()# subscribe to order reportsdefprint_feed(feed,feed_type):forreportinfeed:print(report)client.subscribe_to_reports(callback)# unsubscribe from order reportsclient.unsubscribe_to_reports()client_order_id=str(int(time.time()*1000))# create an orderclient.create_spot_order(client_order_id=client_order_id,symbol='EOSETH',side='sell',quantity='0.01',price='10000',)# candel an orderclient.cancel_spot_order(client_order_id)WalletClient# instance a clientclient=WalletClient(api_key,api_secret)client.connect()# close the clientclient.close()# subscribe to wallet transactionsdefcallback(transaction):print(transaction)client.subscribe_to_transactions(callback)# unsubscribe from wallet transactionserr=client.unsubscribe_to_transactions()# get wallet balancesdefcallback(err,balances):iferr:print(err)returnprint(balances)client.get_wallet_balances(callback)exception handlingfromcryptomarket.clientimportClientfromcryptomarket.exceptionsimportCryptomarketSDKExceptionclient=Client(api_key,secret_key)# catch a wrong argumenttry:order=client.create_order(symbol='EOSETH',side='selllll',# wrongquantity='3')exceptCryptomarketSDKExceptionase:print(f'exception catched{e}')# catch a failed transactiontry:order=client.create_order(symbol='eosehtt',# non existant symbolside='sell',quantity='10',)exceptCryptomarketSDKExceptionase:print(f'exception catched{e}')client=WalletClient(api_key,api_secret)try:client.connect()exceptExceptionase:# here we are catching connection and authentication errorsprint(e)websocket methods take callbacks with two parameters, the first is the possible error, the second is the result of response from the server, for example:defcallback(err,balances):iferr:print(err)returnprint(balances)client.get_wallet_balances(callback)websocket subscriptions also have this type of callback, but is calledresult_callbackinsteadConstants of interestAll constants required for calls are in thecryptomarket.argsmodule.DataclassesAll classes returned by the client are in thecryptomarket.dataclassesmoduleCheckout our other SDKsnode sdkjava sdkgo sdkruby sdk