Fugle Realtime API 1.0 client library for Python
Project description
Fugle MarketData
Fugle MarketData API client library for Python
Installation
$ pip install fugle-marketdata
Importing
from fugle_marketdata import WebSocketClient, RestClient
Usage
The library is an isomorphic Python client that supports REST API and WebSocket.
REST API
client = RestClient(api_key = 'YOUR_API_KEY')
stock = client.stock # Stock REST API client
print(stock.intraday.quote(symbol="2330"))
WebSocket API
from fugle_marketdata import WebSocketClient, RestClient
def handle_message(message):
print(f'message: {message}')
def handle_connect():
print('connected')
def handle_disconnect(code, message):
print(f'disconnect: {code}, {message}')
def handle_error(error):
print(f'error: {error}')
def main():
client = WebSocketClient(api_key='YOUR_API_KEY')
stock = client.stock
stock.on("connect", handle_connect)
stock.on("message", handle_message)
stock.on("disconnect", handle_disconnect)
stock.on("error", handle_error)
stock.connect()
stock.subscribe({
"channel": 'trades',
"symbol": '2330'
})
if __name__ == "__main__":
main()
Error Handling
The library provides a custom FugleAPIError exception for API-related errors, which includes detailed debugging information.
Catching API Errors
from fugle_marketdata import RestClient, FugleAPIError
client = RestClient(api_key='YOUR_API_KEY')
try:
data = client.stock.intraday.quote(symbol="2330")
except FugleAPIError as e:
# Access error details for debugging
print(f"Error: {e.message}")
print(f"URL: {e.url}")
print(f"Status Code: {e.status_code}")
print(f"Request Params: {e.params}")
print(f"Response: {e.response_text}")
Error Attributes
The FugleAPIError exception provides the following attributes:
message: Error descriptionurl: The API endpoint that was calledstatus_code: HTTP status code (if available)params: Request parameters that were sentresponse_text: Raw response text from the API (truncated to 200 chars)
Common Error Scenarios
HTTP Errors (4xx, 5xx):
try:
data = client.stock.intraday.quote(symbol="INVALID_SYMBOL")
except FugleAPIError as e:
if e.status_code == 404:
print("Symbol not found")
elif e.status_code >= 500:
print("Server error, please try again later")
Network Errors:
try:
data = client.stock.intraday.quote(symbol="2330")
except FugleAPIError as e:
if e.status_code is None:
print("Network error occurred")
License
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 fugle_marketdata-2.4.1.tar.gz.
File metadata
- Download URL: fugle_marketdata-2.4.1.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.14.2 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1f0dfb594f2dfa24afae639c4764f8d5923cb915af43f53e16648973e5529e6
|
|
| MD5 |
be477360ea8de6c16944e38b360e2809
|
|
| BLAKE2b-256 |
a0464170b81dd7025b3ac87529cbf2d8bebe7648cc1411d986f87926555fe59d
|
File details
Details for the file fugle_marketdata-2.4.1-py3-none-any.whl.
File metadata
- Download URL: fugle_marketdata-2.4.1-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.14.2 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33ebafbcf49f614d6b699aa54c9e36c6a9882a017300333dcbde065ae9236832
|
|
| MD5 |
cf718df9701d344e16f9d3b017b83b6c
|
|
| BLAKE2b-256 |
d56f0dfe30eab4877f2b444b8f6944de190d564414ef394fe812bf663f848763
|