HsTrader SDK for Python
Project description
HsTrader SDK for Python
hstrader-sdk-py is the HsTrader SDK for Python.
The HsTrader SDK requires a minimum version of Python 3.7.
Installation
pip install hstrader
Documentation
You can find the latest documentation at the official HsTrader API documentation
Getting Started
Http Example
from hstrader import HsTrader
# Its recommended to use environment variables to store your credentials
CLIENT_ID = "<YOUR_CLIENT_ID>"
CLIENT_SECRET = "<YOUR_CLIENT_SECRET>"
URL = "<YOUR_BROKER_URL>"
# Create a new instance of HSTrader
client = HsTrader(CLIENT_ID, CLIENT_SECRET, URL)
try:
# Get the EURUSD symbol
eurusd = client.get_symbol("EURUSD")
print(
f"Symbol ID: {eurusd.id}, Name: {eurusd.symbol}, Last Bid: {eurusd.last_bid}, Last Ask: {eurusd.last_ask}"
)
except Exception as e:
print(e)
Websocket Example
from hstrader import HsTrader
from hstrader.models import Event, Tick
# Its recommended to use environment variables to store your credentials
CLIENT_ID = "<YOUR_CLIENT_ID>"
CLIENT_SECRET = "<YOUR_CLIENT_SECRET>"
URL = "<YOUR_BROKER_URL>"
# Create a new instance of HSTrader
client = HsTrader(CLIENT_ID, CLIENT_SECRET, URL)
# Create a callback function to handle market updates
@client.subscribe(Event.MARKET) # alternatively, you can use @client.subscribe("market")
def on_market(tick: Tick): # this function will be called whenever a new market update is received
print(
f"Received tick for symbol {tick.symbol_id}: bid = {tick.bid} ask = {tick.ask}"
)
# Start listening to real-time data
client.start()
For more examples, please refer to the examples directory.
Contributing
Contributions are welcome.
If you've found a bug within this project, please open an issue to discuss what you would like to change.
If it's an issue with the API, please open a topic at Contact Us.
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
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 hstrader-1.1.0.tar.gz.
File metadata
- Download URL: hstrader-1.1.0.tar.gz
- Upload date:
- Size: 19.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.10.12 Linux/6.8.0-40-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2635cd273e5d9cd50903faf3a4cd1ffd35437097b41d65629d18192b63933fef
|
|
| MD5 |
0d439fdc261a7d805403b67355fc6fb0
|
|
| BLAKE2b-256 |
af89d1d5eff4e6e553627be4e8bbaee2d78e5fbe13deafe83ed6be965426014e
|
File details
Details for the file hstrader-1.1.0-py3-none-any.whl.
File metadata
- Download URL: hstrader-1.1.0-py3-none-any.whl
- Upload date:
- Size: 27.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.10.12 Linux/6.8.0-40-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a957131cb54d566e7d538165d990bdc3a5f332ac3ea62f36a61c68984af4677a
|
|
| MD5 |
4dacf1c8ddbea9b370454096f04002b5
|
|
| BLAKE2b-256 |
d6be7180d34519ecd4ec3fa2442daced3bcbab94220a57ed0a0bf8a31f2f20a3
|