A client library for accessing Unusual Whales API
Project description
unusual-whales-api-client
A client library for accessing Unusual Whales API
Thank you @unusualwhales for providing an excellent api!
Example Implementation
import os
import decimal
from dotenv import load_dotenv
from unusualwhales import UnusualWhalesClient, UnusualWhalesApi
from unusualwhales.models import OffLitPriceLevelResults, OffLitPriceLevel
from unusualwhales.api.stock import get_volume_by_price_level
load_dotenv('.env')
UW_API_TOKEN = os.environ.get("UW_API_TOKEN", None)
def main():
client = UnusualWhalesClient(base_url="https://api.unusualwhales.com", token=UW_API_TOKEN)
with client as client:
data: OffLitPriceLevelResults = get_volume_by_price_level.sync(client=client, ticker="SPY", date="2024-05-03")
for row in data.data:
rec: OffLitPriceLevel = row
print(f"${rec.price}: Lit Vol:{decimal(str(rec.lit_vol))} | Dark Vol: {rec.off_vol}")
if __name__ == '__main__':
main()
API Support
This client supports all api endpoints with exception to websockets.
You can use the openapi.yaml file to generate your own clients for unusual whales in any language openapi has a generator for (and alot exist).
Async Support
This library works with async await to handle non blocking i/o for better performance!
# same code as before but with async/await note that the function changes from sync_detailed to asyncio_detailed
# alternatively you can use sync and asyncio
from unusualwhales.client import UnusualWhalesClient
async with client as client:
ticker_options_volume: TickerOptionsVolumeResults = await getTickerOptionsVolume.asyncio(client=client,ticker="AAPL",date="2024-05-03")
for option_volume in ticker_options_volume.data:
print(option_volume.strike, option_volume.volume)
Things to know:
-
Every path/method combo becomes a Python module with four functions:
sync
: Blocking request that returns parsed data (if successful) orNone
sync_detailed
: Blocking request that always returns aRequest
, optionally withparsed
set if the request was successful.asyncio
: Likesync
but async instead of blockingasyncio_detailed
: Likesync_detailed
but async instead of blocking
-
All path/query params, and bodies become method arguments.
Advanced customizations
There are more settings on the generated Client
class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying httpx.Client
or httpx.AsyncClient
(depending on your use-case):
from unusual_whales_api_client import Client
def log_request(request):
print(f"Request event hook: {request.method} {request.url} - Waiting for response")
def log_response(response):
request = response.request
print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
client = Client(
base_url="https://api.unusualwhales.com",
token="YOUR_API_TOKEN"
httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
)
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 unusualwhales_python_client-4.1.1.tar.gz
.
File metadata
- Download URL: unusualwhales_python_client-4.1.1.tar.gz
- Upload date:
- Size: 101.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.2 Darwin/23.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | adb9dd23e2bfbac912a5b01f641cdc77b754dd94d9b65ddade2d1acc1d6eabad |
|
MD5 | 0ad18627d19f82e08397acd8feb94a31 |
|
BLAKE2b-256 | bfc1e0b9be0fd904fcade2dd814c07760fc148fdfec3d3a2dd758da9f6775e5b |
File details
Details for the file unusualwhales_python_client-4.1.1-py3-none-any.whl
.
File metadata
- Download URL: unusualwhales_python_client-4.1.1-py3-none-any.whl
- Upload date:
- Size: 256.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.2 Darwin/23.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bbb4acf308c9d227ec8bd09d52287cfde6ffeaf69f91ac03dcc919e9a24c767 |
|
MD5 | 999eb3764c0efe2b094ffc11bdffc353 |
|
BLAKE2b-256 | c6c4f2b967b9f5a3730b066b7377cd68c06e31f26d703844936ea713a7341aca |