Start freeSign in
Developers

Build a Telegram trading bot on Sonar Lab

Telegram is one of the largest homes for trading bots. With the Sonar Lab API and the official SDK, a few command handlers turn a chat into a way to route a maintained strategy to the user's own broker account and read back what it traded.

The complete Telegram examplePython SDK

What a Telegram trading bot does here

A Telegram bot is a relay between a person and the API. A user sends a command, your bot calls the Sonar Lab API on their behalf, and the reply carries the result in plain language. Commands map cleanly onto the endpoints: list the strategies, route one at a chosen size, check the connected account, stop a strategy. The bot never places an order and never sees the user's broker password.

Well-written status back to the user

A chat bot has to carry the meaning, because the person never sees the HTTP status. Every error the API returns is written for a human and safe to show: it names what went wrong and the next step to take. The SDK maps each one to a typed error, so your handler branches on a class and relays the message. Never echo the key into a chat, and back off quietly when the API asks you to slow down.

One key per user

A Lab API key acts for exactly one Sonar account. To serve many people from one bot, each user generates their own key in the app and sends it to your bot once, in a direct message; you store it against their chat id and use it only for their calls. On removal, revoke it. Never route one user's strategy with another user's key.

Build it

Telegram walkthrough
A complete python-telegram-bot example.
Status and errors
Relay every failure as a written sentence.
Python SDK
Typed client, tested against a mock transport.
Developers overview
The whole integration, four calls.