bitcom-python-api is a lightweight Python library for bit.com API, supporting Rest requests and event streaming using Websocket.
Project description
bitcom-python-api
API Doc
https://www.bit.com/docs/en-us/#introduction
Quick Start
Prerequisite
- Python3
Install package
pip3 install bitcom
Host
You can get the latest production/testnet hosts here, including REST API and WebSocket.
https://www.bit.com/docs/en-us/#api-hosts-production
Rest public client example
from bitcom.client.market_client import MarketClient
from bitcom.utils import *
from bitcom.constant import *
market_client = MarketClient(url=USER1_HOST)
param_map = {
'instrument_id': 'BTC-PERPETUAL',
}
funding_rate_response = market_client.get_funding_rate(param_map)
LogInfo.output("Get funding rate: ", funding_rate_response)
Rest private client example
from bitcom.client.order_client import OrderClient
order_client = OrderClient(url=USER1_HOST, access_key='<your-access-key>', secret_key='<your-secret-key>')
ret = order_client.place_new_order({
'instrument_id': 'BTC-PERPETUAL',
'qty': '1500',
'side': 'buy',
'order_type': 'market',
})
print(ret)
Websocket subscribe example
from bitcom.client.ws_auth_client import WsAuthClient
from bitcom.client.subscribe_client import SubscribeClient
from bitcom.utils import *
from bitcom.constant import *
import json
import time
ws_client = WsAuthClient(url=USER1_HOST, access_key=USER1_ACCESS_KEY, secret_key=USER1_SECRET_KEY)
token_response = ws_client.get_ws_auth_token()
LogInfo.output("Get websocket token: ", token_response)
def on_wss_open(ws):
cmd = {"type": "subscribe", "instruments": ["BTC-PERPETUAL"],
"channels": ["ticker"], "interval": "raw", "token": "{your_token}"}
# convert to string
cmdStr = json.dumps(cmd)
print('send subscribe cmd: ' + cmdStr)
ws.send(cmdStr)
def on_wss_msg(ws, data):
print(data)
channel = SubscribeClient(WS_HOST, on_wss_open, on_wss_msg)
channel.start()
time.sleep(3)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bitcom-0.0.4.tar.gz.
File metadata
- Download URL: bitcom-0.0.4.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
859b720d03ca624271826c12984af602fe63089d66ecb2c516ed7f7f3bc1f090
|
|
| MD5 |
405b5f3374c5e5d67cd5943e141b4026
|
|
| BLAKE2b-256 |
c5805a83dcf7113e88d885238dd4a95c5036ccbc837a09e57c5188a7df92b170
|
File details
Details for the file bitcom-0.0.4-py3-none-any.whl.
File metadata
- Download URL: bitcom-0.0.4-py3-none-any.whl
- Upload date:
- Size: 34.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31f5a51131dc84f2a39eac4c2426191c6abd065b038a9fcf2b36e11e04335032
|
|
| MD5 |
d4025cde11b29db7ef5b360f7724f656
|
|
| BLAKE2b-256 |
27795d2235a969e833efeb32c6a17f0412e670d3b5324c029faed5ecc2ac02a1
|