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"
market='BTC-USD-SWAP-LIN', # Change markets here
api_key='', # API public key generated by coinflex.com
api_secret='' # API secret key generated by coinflex.com
)
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file coinflex-ws-0.1.1.tar.gz
.
File metadata
- Download URL: coinflex-ws-0.1.1.tar.gz
- Upload date:
- Size: 5.9 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | f82535686e7fee02ba8738dcc341b0444018efef51cde6c6bf1505bda1a45cc6 |
|
MD5 | 91598c41c5be8664d751bca395a7f8ec |
|
BLAKE2b-256 | 4fae159397d032be3cf13392fe08722cb49d3424035c4819ba6e6364e306ab44 |
Provenance
File details
Details for the file coinflex_ws-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: coinflex_ws-0.1.1-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99b20b08eb6b1296f8fa5af749f125aaf7cead356064f20825edb4533987cd8e |
|
MD5 | 7c5a86b1c5d8336f59b41a1d9cfcac62 |
|
BLAKE2b-256 | 760e8644e1141c46dbb55e78960ac7b6d5d5507588a3ba27630ad14a59816f19 |