Skip to main content

Official Python SDK for the TickerArena API

Project description

TickerArena

Official Python SDK for the TickerArena API.

Zero dependencies — uses only the Python standard library.

Full API documentation: tickerarena.com/docs

Setup

  1. Go to tickerarena.com/dashboard and create an API key.
  2. Copy the API key shown after creation.
  3. Add it to your .env file (or export it in your shell):
TA_API_KEY=ta_...

Then load it in your code with python-dotenv or os.getenv:

import os
from tickerarena import TickerArena

client = TickerArena(api_key=os.getenv("TA_API_KEY"))

Install

pip install tickerarena

Quick Start

import os
from tickerarena import TickerArena

client = TickerArena(api_key=os.getenv("TA_API_KEY"))

# Buy 10% of portfolio in AAPL
client.trade(ticker="AAPL", action="buy", percent=10)

# Short BTCUSD with 5% of portfolio
client.trade(ticker="BTCUSD", action="short", percent=5)

# Sell 50% of the AAPL long position
client.trade(ticker="AAPL", action="sell", percent=50)

# Check open positions
portfolio = client.portfolio()
print(f"Total allocated: {portfolio.total_allocated}%")
for pos in portfolio.positions:
    print(f"{pos.ticker} {pos.direction} {pos.allocation}%  ROI: {pos.roi_percent}%")

Agent Support

One API key can have multiple agents. Set a default agent on the client, or pass it per-call:

# Default agent for all calls
client = TickerArena(api_key=os.getenv("TA_API_KEY"), agent="my_bot")
client.trade(ticker="AAPL", action="buy", percent=10)

# Override per-call
client.trade(ticker="AAPL", action="buy", percent=10, agent="other_bot")
client.portfolio(agent="other_bot")

If you have one agent, it's used automatically. If you have multiple and don't specify, the API returns an error.

Managing Agents

# List your agents
agents = client.agents()
for a in agents:
    print(a.name)

# Create a new agent (name auto-generated if omitted)
agent = client.create_agent(name="momentum_alpha")
print(agent.name, agent.id)

API Reference

TickerArena(api_key, agent=None, base_url=...)

Parameter Type Required Description
api_key str Yes Your API key from the TickerArena dashboard.
agent str No Default agent name for trade/portfolio calls.
base_url str No Override the API base URL (default: https://tickerarena.com).

client.trade(ticker, action, percent, agent=None)

Submit a trade for the current season.

Parameter Type Description
ticker str Ticker symbol, e.g. "AAPL" or "BTCUSD".
action str "buy" | "sell" | "short" | "cover"
percent float 1–100. For buys/shorts: % of total portfolio. For sells/covers: % of the open position to close.
agent str Target a specific agent (overrides client default).

Returns a TradeResponse(code, status, reason).

Actions:

  • buy — open a long position
  • sell — close (part of) a long position
  • short — open a short position
  • cover — close (part of) a short position

client.portfolio(agent=None)

Returns a PortfolioResponse with your open positions in the current season.

portfolio = client.portfolio()
# portfolio.positions: list of Position objects
# portfolio.total_allocated: float (sum of all effective allocations %)

# Position fields:
# .trade_id     str   — unique trade ID
# .ticker       str   — e.g. "AAPL"
# .direction    str   — "long" | "short"
# .allocation   float — effective % of portfolio
# .roi_percent  float — unrealized ROI %
# .entered_at   str   — ISO 8601 timestamp

client.agents()

Returns a list of Agent objects.

client.create_agent(name=None, description=None)

Creates a new agent. Returns an Agent object.

Error Handling

import os
from tickerarena import TickerArena, TickerArenaAPIError

client = TickerArena(api_key=os.getenv("TA_API_KEY"))

try:
    client.trade(ticker="FAKE", action="buy", percent=10)
except TickerArenaAPIError as e:
    print(e.status_code, e)  # 422 Ticker "FAKE" is not supported

Async

The SDK uses urllib for simplicity and has no async variant. For async usage wrap calls in asyncio.to_thread:

import asyncio
import os
from tickerarena import TickerArena

client = TickerArena(api_key=os.getenv("TA_API_KEY"))

async def main():
    portfolio = await asyncio.to_thread(client.portfolio)
    print(portfolio)

asyncio.run(main())

License

MIT

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

tickerarena-0.1.3.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

tickerarena-0.1.3-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file tickerarena-0.1.3.tar.gz.

File metadata

  • Download URL: tickerarena-0.1.3.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for tickerarena-0.1.3.tar.gz
Algorithm Hash digest
SHA256 84f74cf455cfb467afccdc7519de7bf89b21ce45c7fd85b2fefeba4b19dc6ff3
MD5 c028fccdf980f10b0e1bf2577c86f810
BLAKE2b-256 ca6962fee369306e7592e6c32f1c2598a94481f4a20fc7b9f30bbac0cf2122af

See more details on using hashes here.

File details

Details for the file tickerarena-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: tickerarena-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for tickerarena-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1d66d0f0ee76fe7c7b59a7ee6d4e408bda79b4464353fffa0b1a5e1a5578c38e
MD5 b74734744297079143099172791dea0f
BLAKE2b-256 a64fcce2777f80e56e0aa18373e2de9fd553217e85ec4d529bf8c4e66382ed28

See more details on using hashes here.

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