cryptomarket


Namecryptomarket JSON
Version 3.1.0 PyPI version JSON
download
home_pagehttps://github.com/cryptomkt/cryptomkt-python
SummaryCryptomarket API client library
upload_time2024-03-13 18:51:11
maintainer
docs_urlNone
authorCryptoMarket
requires_python>=3.8
license
keywords api cryptomkt cryptomarket bitcoin client
VCS
bugtrack_url
requirements requests websocket-client dacite typing_extensions
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # CryptoMarket-Python

[main page](https://www.cryptomkt.com/)

[sign up in CryptoMarket](https://www.cryptomkt.com/account/register).

# Installation

To install Cryptomarket use pip

```
pip install cryptomarket
```

# Documentation

This sdk makes use of the [api version 3](https://api.exchange.cryptomkt.com) of cryptomarket

# Quick Start

## rest client

```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)
```

## 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`.

```python
# 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

```python
# 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

```python
# 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

```python
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:

```python
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](https://github.com/cryptomkt/cryptomkt-node)

[java sdk](https://github.com/cryptomkt/cryptomkt-java)

[go sdk](https://github.com/cryptomkt/cryptomkt-go)

[ruby sdk](https://github.com/cryptomkt/cryptomkt-ruby)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cryptomkt/cryptomkt-python",
    "name": "cryptomarket",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "api,cryptomkt,cryptomarket,bitcoin,client",
    "author": "CryptoMarket",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/69/bb/59f924e5808005aa87ceba3b8bf54b984800465686101e44f1626496ae4d/cryptomarket-3.1.0.tar.gz",
    "platform": null,
    "description": "# CryptoMarket-Python\n\n[main page](https://www.cryptomkt.com/)\n\n[sign up in CryptoMarket](https://www.cryptomkt.com/account/register).\n\n# Installation\n\nTo install Cryptomarket use pip\n\n```\npip install cryptomarket\n```\n\n# Documentation\n\nThis sdk makes use of the [api version 3](https://api.exchange.cryptomkt.com) of cryptomarket\n\n# Quick Start\n\n## rest client\n\n```python\nfrom cryptomarket.client import Client\nfrom cryptomarket.args import Account, Side, OrderType\nfrom cryptomarket.exceptions import CryptomarketSDKException\n\n# instance a client\napi_key='AB32B3201'\napi_secret='21b12401'\nclient = Client(api_key, api_secret)\n\n# get currencies\ncurrencies = client.get_currencies()\n\n# get order books\norder_book = client.get_order_book_of_symbol('EOSETH')\n\n# get your wallet balances\nwallet_balance = client.get_wallet_balances()\n\n# get your spot trading balances\ntrading_balance = client.get_spot_trading_balances()\n\n# move balance from wallet account to trading account\ntransfer = client.transfer_between_wallet_and_exchange('ETH', '3.2', source=Account.WALLET, destination=Account.SPOT)\n\n# get your active spot orders\norders = client.get_all_active_spot_orders('EOSETH')\n\n# create a new spot order\norder = client.create_spot_order('EOSETH', Side.BUY, '10', type=OrderType.MARKET)\n```\n\n## Websocket Clients\n\nthere are three websocket clients, `MarketDataClient`, the `TradingClient` and the `WalletClient`. The `MarketDataClient` is public, while the others require authentication to be used.\n\nSome subscription callbacks take a second argument, indicating the type of notification, either 'snapshsot' or 'update'.\n\n### MarketDataClient\n\nThere are no unsubscriptions methods for the `MarketDataClient`. To stop recieving messages is recomended to close the `MarketDataClient`.\n\n```python\n# instance a client\nclient = MarketDataClient()\nclient.connect()\n\n# subscribe to public trades\ndef trades_callback(trades_by_symbol: Dict[str, List[WSTrade]], notification_type):\n    for symbol in trades_by_symbol:\n        trade_list = trades_by_symbol[symbol]\n        for trade in trade_list:\n            print(trade)\nclient.subscribe_to_trades(\n  callback=trades_callback,\n  symbols=['ETHBTC'],\n  limit=5,\n)\n\n# subscribe to symbol tickers\ndef ticker_callback(tikers_of_symbol: Dict[str, WSTicker]):\n    for symbol in tikers_of_symbol:\n        ticker = tikers_of_symbol[symbol]\n        print(ticker)\nclient.subscribe_to_ticker(\n    callback=ticker_callback,\n    speed=TickerSpeed._3_SECONDS,\n    result_callback=lambda err, result: print(f'err:{err}, result:{result}')\n)\n\n# run for some time\ntime.sleep(10)\n\n# close the client\nclient.close()\n```\n\n### TradingClient\n\n```python\n# instance a client with a 15 seconds window\nclient = TradingClient(api_key, api_secret, window=15_000)\nclient.connect()\n# close the client\nclient.close()\n\n# subscribe to order reports\ndef print_feed(feed, feed_type):\n    for report in feed:\n        print(report)\nclient.subscribe_to_reports(callback)\n# unsubscribe from order reports\nclient.unsubscribe_to_reports()\n\nclient_order_id = str(int(time.time()*1000))\n\n# create an order\nclient.create_spot_order(\n  client_order_id=client_order_id,\n  symbol='EOSETH',\n  side='sell',\n  quantity='0.01',\n  price='10000',\n)\n\n# candel an order\nclient.cancel_spot_order(client_order_id)\n\n```\n\n### WalletClient\n\n```python\n# instance a client\nclient = WalletClient(api_key, api_secret)\nclient.connect()\n\n# close the client\nclient.close()\n\n# subscribe to wallet transactions\ndef callback(transaction):\n  print(transaction)\nclient.subscribe_to_transactions(callback)\n\n# unsubscribe from wallet transactions\nerr = client.unsubscribe_to_transactions()\n\n# get wallet balances\ndef callback(err, balances):\n  if err:\n      print(err)\n      return\n  print(balances)\nclient.get_wallet_balances(callback)\n```\n\n## exception handling\n\n```python\nfrom cryptomarket.client import Client\nfrom cryptomarket.exceptions import CryptomarketSDKException\n\nclient = Client(api_key, secret_key)\n\n# catch a wrong argument\ntry:\n    order = client.create_order(\n        symbol='EOSETH',\n        side='selllll', # wrong\n        quantity='3'\n    )\nexcept CryptomarketSDKException as e:\n    print(f'exception catched {e}')\n\n# catch a failed transaction\ntry:\n    order = client.create_order(\n        symbol='eosehtt',  # non existant symbol\n        side='sell',\n        quantity='10',\n    )\nexcept CryptomarketSDKException as e:\n    print(f'exception catched {e}')\n\n\nclient = WalletClient(api_key, api_secret)\ntry:\n  client.connect()\nexcept Exception as e:\n  # here we are catching connection and authentication errors\n  print(e)\n```\n\nwebsocket methods take callbacks with two parameters, the first is the possible error, the second is the result of response from the server, for example:\n\n```python\ndef callback(err, balances):\n  if err:\n      print(err)\n      return\n  print(balances)\nclient.get_wallet_balances(callback)\n```\n\nwebsocket subscriptions also have this type of callback, but is called **result_callback** instead\n\n## Constants of interest\n\nAll constants required for calls are in the `cryptomarket.args` module.\n\n## Dataclasses\n\nAll classes returned by the client are in the `cryptomarket.dataclasses` module\n\n# Checkout our other SDKs\n\n[node sdk](https://github.com/cryptomkt/cryptomkt-node)\n\n[java sdk](https://github.com/cryptomkt/cryptomkt-java)\n\n[go sdk](https://github.com/cryptomkt/cryptomkt-go)\n\n[ruby sdk](https://github.com/cryptomkt/cryptomkt-ruby)\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Cryptomarket API client library",
    "version": "3.1.0",
    "project_urls": {
        "Homepage": "https://github.com/cryptomkt/cryptomkt-python"
    },
    "split_keywords": [
        "api",
        "cryptomkt",
        "cryptomarket",
        "bitcoin",
        "client"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c2ce67da493099e12fecb9820baf44615d2cff5c343c961d553046d607f0fb77",
                "md5": "5f7498e34badc252713c3842d40f571b",
                "sha256": "8675fa1d7b54a72775b32f89ae92df6c76ce397a83ddf1fa0f5718e3773368a3"
            },
            "downloads": -1,
            "filename": "cryptomarket-3.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5f7498e34badc252713c3842d40f571b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 39793,
            "upload_time": "2024-03-13T18:51:09",
            "upload_time_iso_8601": "2024-03-13T18:51:09.026380Z",
            "url": "https://files.pythonhosted.org/packages/c2/ce/67da493099e12fecb9820baf44615d2cff5c343c961d553046d607f0fb77/cryptomarket-3.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "69bb59f924e5808005aa87ceba3b8bf54b984800465686101e44f1626496ae4d",
                "md5": "68bb2425fe512167e44e0f458f3c54f9",
                "sha256": "bfec6e92e630ff5f553511131dfa00a0c9b44d6ddba4804d00760c28bdbf548e"
            },
            "downloads": -1,
            "filename": "cryptomarket-3.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "68bb2425fe512167e44e0f458f3c54f9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 35376,
            "upload_time": "2024-03-13T18:51:11",
            "upload_time_iso_8601": "2024-03-13T18:51:11.149154Z",
            "url": "https://files.pythonhosted.org/packages/69/bb/59f924e5808005aa87ceba3b8bf54b984800465686101e44f1626496ae4d/cryptomarket-3.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-13 18:51:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cryptomkt",
    "github_project": "cryptomkt-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.31.0"
                ]
            ]
        },
        {
            "name": "websocket-client",
            "specs": [
                [
                    "==",
                    "1.1.0"
                ]
            ]
        },
        {
            "name": "dacite",
            "specs": [
                [
                    "==",
                    "1.8.1"
                ]
            ]
        },
        {
            "name": "typing_extensions",
            "specs": [
                [
                    "==",
                    "4.9.0"
                ]
            ]
        }
    ],
    "lcname": "cryptomarket"
}
        
Elapsed time: 0.20352s