A bot publishes forecasts to a room: setup
How to connect your trading bot to a SpreadFighter trading room: the bot publishes forecasts with your API key on your behalf, and members with auto-copy repeat its trades.
What you get
The bot publishes forecasts on your behalf with an API key, using the same calls a person uses in the terminal. The room's Owner and members with the Author role can publish to the room.
- The bot decides on a trade and calls
publishForecast. - The forecast appears in the room feed under the account's nickname, and members get a notification.
- The SpreadFighter execution engine tracks the forecast at the market price: entry, stop loss, take profit, time limit.
- Members who have turned on the room's Auto-copy get a copy of the trade on their own account. Each member sets the size: as risk in % of the account.
- When the bot closes the forecast or moves SL/TP, the members' copies repeat that action.
Forecast statistics are counted per author: in R from the initial stop loss, without money or position size. If you want to keep the bot's statistics separate from your manual forecasts, create a separate account for the bot on the Pro or Max plan and make it an Author of the room.
The bot's forecasts are copied to members' real accounts. Label the forecasts honestly: say that this is an automated strategy and that it is not investment advice. Test the bot in your own room first.
Limitations
- Binance USDT-M futures only;
- stop loss is required;
- you need the Pro or Max plan: without it you cannot issue an API key;
- up to 100 publications per day per author in a room;
- no more than 10 Authors in a room.
Step 1. Room permissions
The account the bot publishes from must be the room's Owner or its Author. The Owner assigns Authors: Room settings → Members → the Author role for the member you need.
Step 2. API key
Issue a key in your profile: avatar → "Profile" → "API keys" → "Issue key". Details are in the article API for developers. The key is shown only once: keep it in a secrets manager or in a file with 600 permissions.
Every call is POST https://europe-west3-spreadfighter.cloudfunctions.net/<name> with the X-API-KEY header and JSON in the body:
curl -s -X POST https://europe-west3-spreadfighter.cloudfunctions.net/forecastModelPreview \
-H "X-API-KEY: sf_live_..." -H "Content-Type: application/json" \
-d '{"roomSlug": "public", "kind": "order", "orderType": "market", "side": "Sell", "symbol": "BTCUSDT", "sl": "200000"}'
This call publishes nothing: it checks the key, the permissions and the request body and returns the forecast calculation. Start with it.
The key stops working if it is revoked, if it expires, or if your plan drops to Free. Then the functions return unauthorized.
The room is specified by its address in the roomSlug field (as in the room link), or by its id in the roomId field.
Step 3. Publishing a forecast
publishForecast publishes a single order or a grid of levels.
Required fields:
| Field | Type | Meaning |
|---|---|---|
roomSlug or roomId | string | room address, for example public, or its id: one of the two |
kind | order | grid | single order or grid of levels |
side | Buy | Sell | buy or sell |
symbol | string | Binance USDT-M symbol, for example BTCUSDT |
sl | string | stop loss |
orderType | market | limit | stop | only with kind: "order": at market, limit on a pullback, entry on a breakout. Not passed for a grid |
levels | array | entry levels. Not needed only for orderType: "market". limit and stop have exactly one level, a grid has 1 to 150 |
Optional fields:
| Field | Type | If omitted | Meaning |
|---|---|---|---|
tp | string or null | no take profit | take profit |
probability | integer 1–99 | no estimate | your estimated probability of reaching TP. Used only together with tp |
entryExpiresInMs | number, ms | 24 h | entry time limit: 5 min to 7 days. If the entry does not fill in time, the forecast expires |
maxHoldMs | number, ms | 7 days | maximum position time: 5 min to 30 days. After that the forecast is closed at market |
note | string | no caption | forecast caption, up to 500 characters |
A level in levels:
| Field | Required | Meaning |
|---|---|---|
price | yes | level price, as a string |
weight | yes for a grid; no for an order (1 by default) | the level's share of the size, a number greater than 0. Weights are normalized: 1, 1, 2 = 25%, 25%, 50% |
type | no | limit or stop. For a grid the default is limit; for an order, if passed, it must match orderType |
Pass prices as strings: the server rounds them to the instrument's tick size.
Server-side checks. For a buy, SL is below all entry levels and TP is above; for a sell, the other way round. A limit buy level is below the current price, a breakout level is above; for a sell, the other way round. A limit or stop order has exactly one level. A grid has up to 150 levels; weights are normalized.
Example: market short
{
"roomSlug": "public",
"kind": "order",
"orderType": "market",
"side": "Sell",
"symbol": "SAHARAUSDT",
"sl": "0.006522",
"maxHoldMs": 86400000,
"note": "Automated forecast of the strategy … Not investment advice."
}
Response: {"success": true, "forecastId": "od5QaZ1jF71gchiWAJ4S"}. Save the forecastId: you use it to close and edit the forecast. The entry of a market forecast is the current price at the moment of publication, not the fill price of your order.
Example: limit buy grid
{
"roomSlug": "public",
"kind": "grid",
"side": "Buy",
"symbol": "ETHUSDT",
"levels": [
{"price": "3000", "weight": 1},
{"price": "2950", "weight": 1},
{"price": "2900", "weight": 2}
],
"sl": "2800",
"tp": "3300",
"probability": 55,
"entryExpiresInMs": 43200000
}
Step 4. Managing a forecast
The body of each call is {"roomSlug", "forecastId", …}.
| Call | When | What it does |
|---|---|---|
closeForecast | the forecast is in a position (active) | closes it at market |
cancelForecast | the entry has not filled yet (waiting) | cancels the forecast |
updateForecast | the forecast is in a position | moves SL and/or TP: fields sl, tp (null removes TP) |
Moving SL cannot increase risk: for a buy, SL can only move up; for a sell, only down. The probability does not change after publication. Members' copies repeat the bot's actions. When a forecast closes on its own by SL, TP or time limit, members with copies see it without any call from you.
forecastModelPreview takes the same body as publishForecast, publishes nothing and returns the calculation: planEntry, downsidePct, upsidePct, upsideR. It is a convenient way to check the key and the request body.
Responses and errors
Success is HTTP 200 and {"success": true, …}. An error is {"success": false, "error": "<code>"}.
| Code | HTTP | Meaning | What to do |
|---|---|---|---|
unauthorized | 401 | the key is wrong, revoked, expired, or the plan is Free | check the key and the plan |
room_not_found | 404 | no room with this address | check roomSlug |
not_owner | 403 | the account is not an Author of the room, or the forecast belongs to someone else | check the role |
not_member | 403 | the account is not a member of the room | join the room |
room_not_active | 409 | the room is frozen or deleted | do not publish |
limit_daily | 429 | 100 publications per day reached | wait |
bad_symbol | 400 | the symbol is not on Binance USDT-M or is not trading | skip |
bad_sl, bad_tp | 400 | the stop or take is on the wrong side | fix the levels |
bad_entry_side | 400 | the price jumped past the level, the entry type is wrong | recalculate and send again |
bad_levels, bad_kind, bad_side, bad_order_type, bad_expiry, bad_hold, bad_note, bad_probability | 400 | invalid field | fix the request |
not_active | 409 | the forecast is already closed or not yet in a position | do nothing |
not_cancellable | 409 | the entry has already filled | close it with closeForecast |
sl_increases_risk | 400 | the new SL increases risk | do not move it |
market_unavailable, price_unavailable | 503 | no price | retry in a minute |
How to write the bot
- One forecast per trade. Store the mapping "your trade id →
forecastId" on disk. After a restart the bot must not publish the same trade a second time. - Publish immediately. A market forecast enters at the current price. A forecast that is minutes late shows a different entry, and its result will differ from your trade. If you publish later, write in
notewhen and at what price the bot entered. - Close together with the trade. If you exit the position before the stop or the time limit, call
closeForecast. Anot_activeresponse means the forecast has already closed on its own. - SpreadFighter must not get in the way of trading. Call it in the background, write errors to the log, and do not stop the bot because of them.
- Caption. State in
notethat this is an automated strategy, its exit rules, and that it is not investment advice.
Python example
Standard library only. The key is taken from the SF_API_KEY environment variable.
import json, os, urllib.error, urllib.request
BASE = "https://europe-west3-spreadfighter.cloudfunctions.net"
KEY = os.environ["SF_API_KEY"]
ROOM = "public"
def call(name, body):
req = urllib.request.Request(f"{BASE}/{name}", json.dumps({"roomSlug": ROOM, **body}).encode(),
method="POST", headers={"Content-Type": "application/json", "X-API-KEY": KEY})
try:
with urllib.request.urlopen(req, timeout=30) as r:
return json.load(r)
except urllib.error.HTTPError as e:
return json.load(e)
# the short entry has filled
r = call("publishForecast", {"kind": "order", "orderType": "market", "side": "Sell", "symbol": "SAHARAUSDT",
"sl": "0.006522", "maxHoldMs": 24 * 3600 * 1000,
"note": "Automated strategy. Not investment advice."})
forecast_id = r.get("forecastId") # save it: "trade id → forecastId"
# … later the bot exited the trade
if forecast_id:
call("closeForecast", {"forecastId": forecast_id})
This is how the pumpfade bot works in the Public room: a service next to the trading engine reads its trade log. When the bot enters, the service publishes a forecast: a market short, stop +20%, time limit 24 h. When the bot exits, it closes the forecast.