Skip to main content

A Set of Simple Connectors for access To Cryptocurrency Exchanges

Project description

ssc2ce

A Set of Simple Connectors for access To Cryptocurrency Exchanges via websocket based on aiohttp .

Installation

Install ssc2ce with:

$ pip install ssc2ce

Bitfinex

Description

API description look at Websocket API v2

Basic example

import asyncio

from ssc2ce import Bitfinex

conn = Bitfinex()


async def handle_subscription(data):
    print(data)

async def subscribe():
    await conn.subscribe({
        "channel": "ticker",
        "symbol": "tBTCUSD"
    }, handler=handle_subscription)


conn.on_connect_ws = subscribe

loop = asyncio.get_event_loop()

try:
    loop.run_until_complete(conn.run_receiver())
except KeyboardInterrupt:
    print("Application closed by KeyboardInterrupt.")

Deribit

Description

API description look at Deribit API v2 websocket

Basic example

import asyncio
from ssc2ce import Deribit

conn = Deribit()


async def subscribe():
    await conn.send_public(request={
        "method": "public/subscribe",
        "params": {
            "channels": ["deribit_price_index.btc_usd"]
        }
    })


async def handle_subscription(data):
    method = data.get("method")
    if method and method == "subscription":
        if data["params"]["channel"].startswith("deribit_price_index"):
            index_name = data["params"]["data"]["index_name"]
            price = data["params"]["data"]["price"]
            print(f" Deribit Price Index {index_name.upper()}: {price}")


conn.on_connect_ws = subscribe
conn.method_routes += [("subscription", handle_subscription)]

loop = asyncio.get_event_loop()


try:
    loop.run_until_complete(conn.run_receiver())
except KeyboardInterrupt:
    print("Application closed by KeyboardInterrupt.")

Run examples from a clone

If you clone repository you can run examples from the root directory.

$ PYTHONPATH=.:$PYTHONPATH python examples/basic_example.py

The deribit_private.py example uses python-dotenv, you must either install it if you want the example to work right out of the box,

$ pip install python-dotenv

or make the corresponding changes, removed followed code.

from dotenv import load_dotenv
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
load_dotenv(dotenv_path)

To run the private.py example, you must either fill in the .env file or set the environment variables DERIBIT_CLIENT_ID and DERIBIT_CLIENT_SECRET. Look at .env_default.

$ PYTHONPATH=.:$PYTHONPATH DERIBIT_CLIENT_ID=YOU_ACCESS_KEY DERIBIT_CLIENT_SECRET=YOU_ACCESS_SECRET python examples/private.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
ssc2ce-0.7.1-py3-none-any.whl (9.3 kB) Copy SHA256 hash SHA256 Wheel py3
ssc2ce-0.7.1.tar.gz (6.5 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page