A Set of Simple Connectors for access To Cryptocurrency Exchanges via websocket based on aiohttp .
This is more of a pilot project, if you have any wishes for adding exchanges or expanding functionality, please register issues
Install ssc2ce with:
$ pip install ssc2ceYou can run some examples with
API description look at Websocket API v2
import asyncio
from ssc2ce import Bitfinex
conn = Bitfinex()
async def handle_subscription(data, connector: Bitfinex):
print(data, f"received:{connector.receipt_time}")
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.")API description look at Deribit API v2 websocket
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"]
}
})
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.")If you clone repository you can run examples from the root directory.
$ PYTHONPATH=.:$PYTHONPATH python examples/bitfinex_basic_example.pyTo run some examples, you may need additional modules, you can install them from the requirements.txt file.
$ pip install -r requirements.txtTo 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/deribit_private.py