Skip to main content

Simple WebSocket adapter for CoinFLEX's WebSocket API

Project description

WebSocket Adapter

This is a simple CoinFLEX WebSocket adapter.

Installation

pip install coinflex-ws

Usage

All CoinFLEX WebSocket streams and requests are available in this package.

Import the CoinFLEX WebSocket library and initialise an instance of the client:

import coinflex_ws

ws = coinflex_ws.CoinFLEXWebSocket(
    url="wss://v2stgapi.coinflex.com/v2/websocket",	# Testnet endpoint; live endpoint is "wss://v2api.coinflex.com/v2/websocket"
    api_key='',
    api_secret=''
)

API keys, api_key and api_secret, are required to access private streams and requests.

Streaming data and making requests

This wrapper supports all of the WebSocket channels on the docs (docs.coinflex.com).

When a get method, such as get_depth(), returns an empty string it indicates that no relevant data has been received by the client yet.

# Subscribe to WebSocket streams

# Public endpoints
# ws.subscribe_liquidation()
ws.subscribe_depth(25)
# ws.subscribe_trade()
# ws.subscribe_ticker()
# ws.subscribe_kline('60s')
# ws.subscribe_market()

# Private endpoints
# ws.subscribe_balance()
# ws.subscribe_position()
# ws.subscribe_order()

# Order Management
# ws.place_limit_order(1, 'BUY', 10,  0.001, 'GTC', 1)		# clientOrderId, side, price, quantity, time in force, tag
# ws.place_stop_order(1, 'BUY', 50000, 60000, 0.001, 'GTC', 2)  # clientOrderId, side, stopPrice, limitPrice, quantity, time in force, tag
# ws.place_market_order(1, 'BUY', 0.001, time.time())		# clientOrderId, side, quantity, tag
# ws.cancel_order('304397024272106384', 3)				# orderId, tag
# ws.modify_order('304397024272106383', 'BUY', 4000, 0.1, 'modify1')	# orderId, side, price, quantity, tag

# Get responses forever
while True:
    # print(ws.get_liquidation())
    print(ws.get_depth(25))
    # print(ws.get_trade())
    # print(ws.get_ticker())
    # print(ws.get_kline('60s'))
    # print(ws.get_market())

    # print(ws.get_balance())
    # print(ws.get_position())
    # print(ws.get_order())

    time.sleep(0.5)

See a full usage example in test.py at https://github.com/coinflex-exchange/api-connectors/tree/main/official-ws/python.

Project details


Download files

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

Source Distribution

coinflex-ws-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

coinflex_ws-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file coinflex-ws-0.1.0.tar.gz.

File metadata

  • Download URL: coinflex-ws-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for coinflex-ws-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8c07d6471f20d9d41065af49f0c4229356939db9126b359c238ca75dd1024103
MD5 869d1cfadabef2826b75ad93c62f1164
BLAKE2b-256 8950ac6e351c53eb54f2a0c0aa435d59c6c0c44ae7633c64fdd76359887e94bb

See more details on using hashes here.

Provenance

File details

Details for the file coinflex_ws-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: coinflex_ws-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for coinflex_ws-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07ffef1fee7ff6b4dbbd4a7233a135776b69b2f678e8f8abde9fae7586603469
MD5 c5df71ce27b1d4d50bf662ea97ab52ec
BLAKE2b-256 a0929b39d025969769722429911e3b4323652e84497516674c1065c0299519fe

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page