Skip to main content

Python client for the Alpha API (/v1)

Project description

market-stack-sdk (Python)

HTTP client for Alpha API (/v1).

Install

From this directory:

pip install .

Usage

from market_stack_sdk import MarketStackClient

with MarketStackClient(api_key="YOUR_API_KEY") as client:
    # Defaults to https://developers.manasija.in
    from market_stack_sdk import AnnouncementsQueryParams, DailySummaryRequest, NewsQueryParams

    print(client.get_news(NewsQueryParams(symbols=["RELIANCE"], limit=10)))
    print(client.get_announcements(AnnouncementsQueryParams(symbols=["RELIANCE"])))
    print(
        client.get_earnings_detail(
            {"symbol": "MEDIASSIST", "quarter": "q4_26", "detailed": True}
        )
    )
    print(
        client.post_daily_summary(
            {
                "body": DailySummaryRequest(
                    portfolio=[{"symbol": "RELIANCE", "exposure": 10}]
                )
            }
        )
    )

All calls automatically send X-API-Key from the provided api_key.

Use get, post, put, patch, delete, or request for any public /v1 endpoint.

WebSocket (/v1/ws)

Requires the websockets package (installed with this SDK).

import asyncio
from market_stack_sdk import MarketStackClient, SubscribeOptions

async def main() -> None:
    client = MarketStackClient(api_key="YOUR_API_KEY")
    async with client.websocket() as ws:
        await ws.subscribe(
            SubscribeOptions(product="announcements", symbols=["RELIANCE"], detailed=False)
        )
        async for event in ws.events():
            if event.kind == "subscribed":
                print("ready", event.product, event.tier)
            elif event.kind == "data":
                print(event.channel, event.data.get("symbol"))

asyncio.run(main())

Direct session import (without creating MarketStackClient):

import asyncio
from market_stack_sdk import AlphaWebSocketSession, SubscribeOptions

async def main() -> None:
    async with AlphaWebSocketSession(api_key="YOUR_API_KEY", auto_reconnect=True) as ws:
        await ws.subscribe(
            SubscribeOptions(product="news", symbols=["RELIANCE"], detailed=True)
        )
        await ws.run()

asyncio.run(main())

Callback style:

async with client.websocket(on_data=lambda e: print(e.data)) as ws:
    await ws.subscribe(product="alerts", symbols=["RELIANCE"])
    await ws.run()

# Optional resilience hooks:
# async with client.websocket(
#     auto_reconnect=True,
#     reconnect_initial_delay=1.0,
#     reconnect_max_delay=30.0,
#     on_reconnect_attempt=lambda attempt, delay, reason: print(attempt, delay, reason),
#     on_open=lambda reason: print("connected", reason),
#     on_close=lambda reason: print("closed", reason),
# ) as ws:
#     ...

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

market_stack_sdk-0.2.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

market_stack_sdk-0.2.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file market_stack_sdk-0.2.0.tar.gz.

File metadata

  • Download URL: market_stack_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for market_stack_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 beeae5b72b8bf2794d028fa458ed8207029d6fc08c7788a0854202752e763c07
MD5 44c80e60aea9d88e595289ef5df42300
BLAKE2b-256 57bfef8f433d1510982755514a0c9bd74a4c34492fbd2e2c04919b3d644a02b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for market_stack_sdk-0.2.0.tar.gz:

Publisher: publish-pypi.yml on manasijatech/Market-Stack-SDK

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file market_stack_sdk-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for market_stack_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4588027d754f9af052edb5789ba3f9cd7874293fdfbd3811f72545ec8ea6947
MD5 241e854b70a32d8c2a73ff69f73ccc93
BLAKE2b-256 9fa57f53d9f8b9b6dd3f3bc814900cce6f7fdc8be2a39f459e68c01020bff6b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for market_stack_sdk-0.2.0-py3-none-any.whl:

Publisher: publish-pypi.yml on manasijatech/Market-Stack-SDK

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page