Skip to main content

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.

  1. The bot decides on a trade and calls publishForecast.
  2. The forecast appears in the room feed under the account's nickname, and members get a notification.
  3. The SpreadFighter execution engine tracks the forecast at the market price: entry, stop loss, take profit, time limit.
  4. 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.
  5. 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.

warning

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:

FieldTypeMeaning
roomSlug or roomIdstringroom address, for example public, or its id: one of the two
kindorder | gridsingle order or grid of levels
sideBuy | Sellbuy or sell
symbolstringBinance USDT-M symbol, for example BTCUSDT
slstringstop loss
orderTypemarket | limit | stoponly with kind: "order": at market, limit on a pullback, entry on a breakout. Not passed for a grid
levelsarrayentry levels. Not needed only for orderType: "market". limit and stop have exactly one level, a grid has 1 to 150

Optional fields:

FieldTypeIf omittedMeaning
tpstring or nullno take profittake profit
probabilityinteger 1–99no estimateyour estimated probability of reaching TP. Used only together with tp
entryExpiresInMsnumber, ms24 hentry time limit: 5 min to 7 days. If the entry does not fill in time, the forecast expires
maxHoldMsnumber, ms7 daysmaximum position time: 5 min to 30 days. After that the forecast is closed at market
notestringno captionforecast caption, up to 500 characters

A level in levels:

FieldRequiredMeaning
priceyeslevel price, as a string
weightyes 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%
typenolimit 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", …}.

CallWhenWhat it does
closeForecastthe forecast is in a position (active)closes it at market
cancelForecastthe entry has not filled yet (waiting)cancels the forecast
updateForecastthe forecast is in a positionmoves 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>"}.

CodeHTTPMeaningWhat to do
unauthorized401the key is wrong, revoked, expired, or the plan is Freecheck the key and the plan
room_not_found404no room with this addresscheck roomSlug
not_owner403the account is not an Author of the room, or the forecast belongs to someone elsecheck the role
not_member403the account is not a member of the roomjoin the room
room_not_active409the room is frozen or deleteddo not publish
limit_daily429100 publications per day reachedwait
bad_symbol400the symbol is not on Binance USDT-M or is not tradingskip
bad_sl, bad_tp400the stop or take is on the wrong sidefix the levels
bad_entry_side400the price jumped past the level, the entry type is wrongrecalculate and send again
bad_levels, bad_kind, bad_side, bad_order_type, bad_expiry, bad_hold, bad_note, bad_probability400invalid fieldfix the request
not_active409the forecast is already closed or not yet in a positiondo nothing
not_cancellable409the entry has already filledclose it with closeForecast
sl_increases_risk400the new SL increases riskdo not move it
market_unavailable, price_unavailable503no priceretry 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 note when 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. A not_active response 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 note that 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.