Skip to main content

CryptoMarket-Python

main page

sign up in CryptoMarket.

Installation

To install Cryptomarket use pip

pip install cryptomarket==3.3.0

Documentation

This sdk makes use of the api version 3 of cryptomarket

Quick Start

rest client

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)

Websocket Clients

there are three websocket clients, MarketDataClient, the TradingClient and the WalletClient. The MarketDataClient is 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'.

MarketDataClient

There are no unsubscriptions methods for the MarketDataClient. To stop recieving messages is recomended to close the MarketDataClient.

# 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()

TradingClient

# instance a client with a 15 seconds window
client = TradingClient(api_key, api_secret, window=15_000)
client.connect()
# close the client
client.close()

# subscribe to order reports
def print_feed(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',
)

# candel an order
client.cancel_spot_order(client_order_id)

WalletClient

# instance a client
client = WalletClient(api_key, api_secret)
client.connect()

# close the client
client.close()

# subscribe to wallet transactions
def callback(transaction):
  print(transaction)
client.subscribe_to_transactions(callback)

# unsubscribe from wallet transactions
err = client.unsubscribe_to_transactions()

# get wallet balances
def callback(err, balances):
  if err:
      print(err)
      return
  print(balances)
client.get_wallet_balances(callback)

exception handling

from cryptomarket.client import Client
from cryptomarket.exceptions import CryptomarketSDKException

client = Client(api_key, secret_key)

# 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}')

# catch a failed transaction
try:
    order = client.create_order(
        symbol='eosehtt',  # non existant symbol
        side='sell',
        quantity='10',
    )
except CryptomarketSDKException as e:
    print(f'exception catched {e}')


client = WalletClient(api_key, api_secret)
try:
  client.connect()
except Exception as e:
  # here we are catching connection and authentication errors
  print(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:

def callback(err, balances):
  if err:
      print(err)
      return
  print(balances)
client.get_wallet_balances(callback)

websocket subscriptions also have this type of callback, but is called result_callback instead

Constants of interest

All constants required for calls are in the cryptomarket.args module.

Dataclasses

All classes returned by the client are in the cryptomarket.dataclasses module

Checkout our other SDKs

node sdk

java sdk

go sdk

ruby sdk

Metadata

Release files for cryptomarket 3.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cryptomarket 3.3.0
File Size Uploaded Provenance Actions
cryptomarket-3.3.0.tar.gz 40.4 kB Without provenance Details for cryptomarket-3.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cryptomarket 3.3.0
File Interpreter ABI Platform Actions
cryptomarket-3.3.0-py3-none-any.whl Python 3 none any Details for cryptomarket-3.3.0-py3-none-any.whl

Total release size: 94.9 kB

Release files / cryptomarket-3.3.0.tar.gz

Download URL cryptomarket-3.3.0.tar.gz
Size 40.4 kB
Tags Source
SHA-256 checksum
How to use checksums
146b417c640452b5dfd5df3f512cfabc53e0f68bb466c8ad8d01b52f541d65f4
BLAKE2b-256 checksum
How to use checksums
7c2f90dc460598c1322cb978c984aa9408e608e8f5c78a836002085ace74ecea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / cryptomarket-3.3.0-py3-none-any.whl

Download URL cryptomarket-3.3.0-py3-none-any.whl
Size 54.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a012c7a23161000ddf3f18395db63317db425c1151fc87ecdbc38be321297fcb
BLAKE2b-256 checksum
How to use checksums
26371da58c98e3e886220f6ec6cda86a2e468dcb5b4348cde011ddbee9514794
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Security for cryptomarket 3.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page