Alphafamilia Algo Help

USD-M futures

The strategy can trade perpetual futures: USD-M on Binance, USDT-M on BingX and USDT on Bybit. It works with the same grid as on spot: the entry, the averaging orders, a TP for the whole amount. The differences are in leverage, position sides, funding and liquidation. Below — Binance as the example; what differs on BingX (the account's settings, the VST demo account, the fee) — BingX, on Bybit — below and Bybit.

Binance COIN-M futures (inverse contracts, the money in BTC) work differently — see Binance COIN-M below and the path I want to trade COIN-M futures.

Preparation

  1. Open a USD-M futures account on Binance.
  2. Turn on the futures permission for the key ("Enable Futures"). If the key was created before the futures account was opened, create a new key.
  3. Switch the position mode to Hedge Mode: on the futures page — settings → "Features" → "Position Mode" → "Hedge Mode". The mode can be changed only with no open positions and orders.
  4. Choose Cross margin for the strategy's pairs.
  5. Keep the single margin asset mode (Single-Asset Mode), without Multi-Assets mode.
  6. Move USDT from the spot wallet to the futures one (USDⓈ-M): “Wallet” → “Transfer”. A Binance deposit lands on the spot wallet, and the futures strategies see only the futures one. While there is less than the budget there, the form warns and the “First steps” checklist reminds you: "Binance: move USDT from the spot wallet to the futures one (USDⓈ-M): “Wallet” → “Transfer”." (COIN-M — "move BTC to the COIN-M wallet").

Official Binance instructions: What Is Hedge Mode and How to Use It?.

The strategy checks the account's mode and switches nothing by itself. With another mode it waits and shows the reason:

  • "The account is in One-way mode: switch on Hedge Mode (futures settings → position mode)";
  • "Multi-Assets mode is on: switch to Single-Asset Mode";
  • "The pair's margin is isolated: switch to Cross".

For a BingX strategy the same reasons add where the setting is in BingX's app (BingX).

The position mode and the margin asset mode are shown by the strategy form before the start already (Binance USD-M, COIN-M and BingX): the warning "The account is in One-way mode: switch on Hedge Mode … The strategy does not start a cycle while the account is in the wrong mode." (or "Multi-Assets mode is on…"). It is a read only — the same the key's strategies read the mode with (at most once a minute); nothing is switched, the strategy can be saved. The pair's margin (Isolated / Cross) is not checked by the form before the start — the strategy shows it. Bybit switches the mode itself (Bybit).

The strategy learns the mode only from the exchange's own answer. If the exchange did not answer (an error page or an empty answer), it is not "One-way mode": the strategy skips the step, does not cancel its orders and asks again in a minute.

Binance tells a change of the Multi-Assets mode at once (in the account's event stream), and the strategy reads the mode again; if that message is lost, the strategy sees the change within 5 minutes at the latest. Binance does not let you change the position mode (Hedge Mode) while there are positions or orders; if it changed anyway, the exchange refuses the strategy's order, and the strategy reads the mode again at once.

If the key has no futures permission, a futures connection ("Binance USD-M futures", "BingX USDT-M futures") does not take it: the key check shows "Futures not allowed" (Connections and the key vault).

Bybit

On Bybit the USDT futures work on the Unified Trading Account, shared with spot (shared wallet). How it differs from Binance:

  • The strategy switches hedge mode and the price band on itself. If the account has no open USDT-perpetual positions and orders, the strategy switches the position mode to hedge and the limit orders' price protection to "reject" (otherwise Bybit silently moves an order outside the band to the nearest price). Each switch is told in Telegram: it changes the settings of the whole account, for manual trading too.
  • Margin — Regular (cross) — you switch it: Assets → Unified Trading Account → Margin Mode → Cross Margin. Portfolio margin is not supported — it has no liquidation price.
  • Leverage — one for both sides of a pair (Bybit requires it in cross margin).
  • Funding the strategy takes from Bybit's transaction log — with the position's side and size.
  • The liquidation price — Bybit's estimate for cross margin, shown in the strategy's overview.
  • The demo account — futures with virtual USDT at live prices; the TP there is planned with Bybit's base rate (the demo does not tell the account's rate).

If the strategy could not switch the mode itself (the account has open positions or orders), it does not trade and shows the reason with the path in Bybit's settings.

Creating a futures strategy

A futures strategy is made on a "Binance USD-M futures" connection: the strategy's market is the connection's. The pairs are perpetual contracts of the list the administrator allows.

  • Side. The "Mode" field (in the form's "Advanced" section) turns into "long" ("buy first", the default) or "short" ("sell first"). These are real positions. A long strategy and a short strategy on one pair can work at the same time; their positions and funding are separate.
  • Budget — on futures the field is called "Position size, USDT": the size of the position (the notional) in USDT, the grid is sized from it. The margin — your own money the account needs — = position size ÷ leverage; the line under "TP | Leverage" says "Margin ≈ X USDT (position size ÷ leverage)". On the strategy's screen this is "Position size · margin ≈ X", in the "Futures" card — "Size by the settings" (the cycle's grid after rounding the quantities to the exchange's step is a little below the size: "494.94 USDT of 500.00 USDT" and the line "The cycle's grid is below the position size: each part's quantity is rounded down to the exchange's step."). The budget is the planned size of the position: it may end a bit larger (a market entry, a manual DCA beyond the budget).
  • The warning "promised to other strategies" counts the open cycles of the connection's other strategies like this: the margin of their unfilled parts (levels and resting manual orders) plus the fee on the full size of these parts — the exchange takes the fee on the size, not on the margin. Cancelled and skipped levels are not counted. A working strategy with no cycle open "promises" the margin of its whole budget (budget ÷ leverage), without the fee.
  • Leverage — from 1 to 10, paired with the "TP, %" field. The leverage does not change the grid — only the margin (the "Margin ≈ X USDT" line). If a running strategy of the account trades this pair, its leverage is filled in and the field does not change: "A running strategy trades this pair — the leverage must be the same." Binance has one leverage per pair of an account.
  • The line "Free on the account" under "Position size" is the free margin in USDT; the form reads it from the exchange at most once every 3 seconds per key, so after a top-up the number changes within a few seconds.
  • Warnings. A leverage above 5 — "Leverage …: the liquidation is ≈ −… % from the average price. 5 or less is advised." If some DCA levels lie beyond the liquidation price of the position built before them — "At leverage … the liquidation is ≈ … DCA… — beyond it: they never fill, the exchange closes the position first. Lower the leverage, the step or the parts." (one level — "…it never fills…") The liquidation is estimated at −100 % ÷ leverage from the average price (for a short — +100 % ÷ leverage); this is an estimate for an isolated position, on Cross the exchange holds the position longer. A strategy can be saved with warnings too — see The form's warnings.
  • Profit — only in USDT. The "Profit" field is hidden.

Leverage

  • On the exchange there is one leverage per pair. Strategies of one pair must have the same leverage.
  • The strategy sets the leverage on the exchange itself, but only while the pair has no position and no orders. Otherwise it waits with the reason "another leverage on the exchange and it cannot be set: the pair has a position or orders".
  • If the pair's leverage or the account's mode is changed on the exchange in the middle of a cycle, the strategy takes off its orders that add to the position (the entry, the averaging levels) and places no new ones; the TP stays. Telegram gets "🔴 Averaging paused". Set the strategy's leverage (or Hedge Mode and cross margin) back — within a minute the strategy puts the levels back and sends "✅ Averaging resumed".
  • A new leverage in "Change settings" applies from the next cycle and under the same conditions. If another running strategy trades the pair, the leverage must be its leverage — another one is not saved.
  • If you change the leverage or the account mode by hand during a cycle, the strategy stops averaging (cancels the DCA orders) but keeps managing the TP. A leverage changed by hand is seen at once — the exchange itself tells of it, and the resting DCA orders are cancelled at the next step (a few seconds). When you set it back, the strategy goes on: after the leverage — at its next step, after the account mode — within a minute. If the exchange's event stream is not working — as before, within a minute.

Profit and funding

  • The TP price is net profit after fees and the funding already known.
  • Funding is charged on the Binance schedule (usually every 8 hours) and counted in the cycle. The strategy takes the actual payment from the Binance statement. Its share is by its quantity in the side's position at the moment of the payment.
  • A payment that comes after the TP corrects the result of the closed cycle.
  • If the strategy cannot work out its share (for example, the payment came for the time of a restart), "⚠️ Funding needs clarification" comes. Such a payment is not booked — check it against the Binance statement.
  • If the exchange has not given the funding payments for 30 minutes (for example, the request limit is busy) while a position is open, "🟠 Funding is not read" comes. Trading goes on, the TP stays. The payments of that time are booked in their cycles once the exchange answers — even if the cycle has closed by then; "✅ Funding is read again" comes.
  • Funding is shown on the strategy's screen ("Funding this cycle"), in the cycle history, in the reports (the "Funding (within the profit)" line) and in the CSV (lines with the role "funding").

The strategy's share of the shared position

  • The strategy's share is only its own fills. Your manual trades on the same pair are yours: the strategy does not count them.
  • The strategy checks the position of its own contract and side at the start and once a minute. Strategies of the same account on other contracts do not count: each checks itself.
  • If the position on the exchange became smaller than the sum of the shares of the strategies on this contract and side (you closed part of it by hand, or the exchange reduced it), every working strategy of that side with a share goes into the emergency "less asset on the account than counted". They cancel their own orders and do not touch the position — you decide: the lost strategy "Start a new cycle" or the archive, the others "Continue the cycle". A liquidation and ADL are named plainly by the reason.
  • The position and the strategies' records are not read at the same moment: if the fill of resting orders (a TP) could explain the shortage, the system first waits until every strategy of the side has read its trades and the exchange shows no execution beyond the records: up to 12 minutes on BingX and Bybit, up to 2 minutes on Binance. Still short then — an emergency. There is no dust on futures: a single contract missing is a discrepancy. What to do — see Emergencies and faults.

Liquidation

  • There is no stop-loss.
  • The liquidation price is updated every 5 minutes. The exchange works it out and the strategy cannot change it, so it does not ask for it more often. The mark price is updated all the time.
  • "Close to liquidation" is counted from the current mark price and the last liquidation price (up to 5 minutes old): when the mark price comes closer than 10 % to the liquidation price, one message per cycle comes: "🔴 Close to liquidation" with an "Open the strategy" button and the line "What to do: decide whether to close the position — by hand on the exchange (the strategy then goes into an emergency and waits for your decision)." Whether to close the position is your decision. By then the risk strip on the strategy's screen is already red.
  • If the position changed after the liquidation price was last updated (a DCA filled, a new cycle began), the old price is no longer this position's: the strategy does not count "Close to liquidation" by it, and the risk strip says "liquidation: updated at the check" — until the next update (at most 5 minutes).
  • If the exchange still liquidated the position or reduced it by ADL, the emergency says so directly: "the exchange liquidated the position" or "the exchange reduced the position by ADL (auto-deleveraging)". The same if it happened while the server was stopped: the check at the start asks the exchange about a liquidation too.

What the strategy's screen shows

The risk strip — under the strategy's title and in its card in the list of strategies. It has no percents — only prices and money, as on an exchange:

  • the side and the leverage — "Short 3×";
  • the position now of the size by the settings — "position 450.12 $ of 900.00 $";
  • your own money in it (position ÷ leverage) — "own ≈ 150.04 $";
  • the price now (the mark price) and the price at which the exchange liquidates the position — "price 1,800.00 $ · liquidation at 2,913.50 $ · far".

If the price would have to move more than 100 % to reach liquidation (a short — more than double), if the exchange counts no liquidation (cross margin with a large wallet), or names a price on the other side of the price now — "liquidation --", as the exchanges write it. The word after the price and the strip's colour go by how close the price is to liquidation (counted as for "Close to liquidation": the current mark price and the last liquidation price, up to 5 minutes old):

  • "far" — more than 25 % away; the strip is grey (green in the app is for money only);
  • "close" — from 10 to 25 %; the strip is amber;
  • "danger" — 10 % or closer; the strip is red (that is also when "Close to liquidation" comes).

The sums carry the currency's sign: "$" for USDT and USDC, "€", "₽"; COIN-M — in BTC. With no position — "no position". If the position changed after the liquidation price was last updated (an averaging, a new cycle) — "liquidation: updated at the check" (up to 5 minutes). If the strategy is not loaded (the vault is locked) or the exchange did not answer — "liquidation: no data from the exchange". If the risk data are older than a minute — "as of N min ago".

The "Futures" card: "Side", "Leverage", "Size by the settings", "Position", "Own money", "Funding this cycle", "Mark price" and "Liquidation price" with the word "far", "close" or "danger" (or "--"). If liquidation is 10 % away or less, the line is highlighted.

The line under a futures strategy's "Stop" button is "cancels its orders; the position stays without a TP", and the confirmation window names the position and says: "— stays open without a TP".

A futures strategy overview

Other

  • Not enough margin — like not enough funds on spot: a message and retries on schedule.

  • Manual averaging ("Average") on futures — the amount is the total, the position's size: the leverage does not multiply it, margin = amount ÷ leverage (shown next to the field). A "Market" purchase is for a position size too (Manual control).

  • "To budget" in the reports, the strategy's card and the traders' list — of the position size, as on spot: a TP of 1 % gives ≈ 1 % to budget at any leverage.

  • Many strategies on one key. The positions, prices and funding of all the key's contracts are read once for all the strategies. Since 2.0.20 every key has a Binance event stream: the exchange itself tells of a fill, and the strategies of that pair get their new TP in about a second, however many strategies the key has. Since sprint 23 (part B) the strategy takes fills, order states and the position straight from the stream and checks them against the exchange's trade history and positions every 5 minutes — while the stream works, the strategies hardly ask the exchange at all; funding is booked 10 seconds after the stream told of the payment, and if that message was lost — at the hourly check. Before an emergency "the position is smaller than the strategies'" the strategy always asks the exchange again: no emergency is declared on one message of the stream. If the stream is cut, the strategies check against the exchange at once and go back to asking as before (the TP within a step); if it falls silent without being cut, the strategy notices it at the check — within 5 minutes — and does the same. No fill is lost. When the exchange's request limit is tight all the same, the TP after a fill still goes at once; a new DCA may wait one step (3 s), funding is booked a step later.

  • Reports: futures strategies are a separate venue: "Binance Futures", "BingX futures", "Bybit futures".

  • Test network. For practice futures trading, Binance has demo trading with its own keys (demo.binance.com, the futures demo's "API Management"; keys of the old site testnet.binancefuture.com work too). Add such a key as a Binance connection with the environment "test network": the app checks it on the practice futures, and futures strategies work on it (spot ones do not). Before real futures trading, start with a small budget and leverage 1.

Binance COIN-M

The “Binance COIN-M futures” market — perpetual inverse contracts BTCUSD_PERP. Everything above applies here too (Hedge Mode, Cross, leverage 1–10, funding, the risk strip, the strategy's own share of the position); below — only the differences. Step by step — I want to trade COIN-M futures.

  • The connection is a separate one. The key is typed in for it; it may be the Binance key of the USD-M connection (Binance has one “Enable Futures” right for both). The key check asks the COIN-M account. The test environment — the test network (Binance's demo trading, the same key as for the USD-M test futures).
  • The COIN-M account's mode is its own. Hedge Mode and Cross are switched on in the COIN-M section apart from USD-M; the strategy checks COIN-M itself. COIN-M has no multi-asset mode.
  • The money is BTC on the COIN-M wallet: the position size, the margin, the fees (no BNB discount on COIN-M), the funding, the profit. The quantity — whole contracts of 100 USD.
  • The grid. A level's contracts = its share of the size in BTC × the level's price ÷ 100, down to a whole one; the rest is not carried over. Every level — at least 2 contracts (20 % above the exchange's minimum), otherwise the strategy is not created: “at least … BTC is needed”.
  • The average price is by BTC: the whole nominal in USD ÷ the whole value in BTC. It is below the average “by contracts”.
  • The TP — the net profit in BTC after both fees is at least TP % of the position's value at entry; the price — up to the price step. If the fees and the funding ate the profit so that there is no such price, no TP is placed: the strategy's screen says “the fees and the funding in BTC ate the profit: no TP price gives the set profit — no TP is placed”, Telegram — one message “🔴 No TP placed: the fees and the funding ate the profit”.
  • The money check. Before an opening order the strategy itself checks the free BTC on the COIN-M wallet (margin + fee); not enough — “Not enough funds” and a retry.
  • Liquidation — two prices: “Exchange: X · strategy's estimate: Y”. The exchange counts by the cross margin (the whole COIN-M wallet), the strategy — where its own margin (value at entry ÷ leverage) is gone. The distance, the strip's colour and “Close to liquidation” go by the more cautious one (for a long — the higher). The pledge is BTC itself: it loses value as the price falls, so the liquidation is closer than on USD-M at the same leverage. While the exchange's price is “updated at the check” (after an averaging, up to 5 minutes), the strategy's estimate for the new position is shown: “Exchange: — · strategy's estimate: Y · updated at the check”; the distance, the colour and “Close to liquidation” meanwhile go by the strategy's estimate — they don't wait for the exchange's price.
  • Screens and messages: quantities — “45 contracts”, sums in BTC — 8 places (on the screen — without trailing zeros), the nominal in USD — for reference. “Position” in the “Cycle” card is the value at entry before fees (contracts × 100 ÷ each trade's price), “Entry fees” — a row of its own. “Stop” names the position in contracts and BTC.
  • Reports and the summary: “Profit, BTC” — a line of its own, not in the total in the report's currency; USD — for reference, at each cycle's close price.
  • Manual control: “Average” — the amount in BTC, turned into whole contracts down; “TP” — in % from the average (by BTC) or by price; “Invested and planned” — in BTC.
  • Not yet: the short, copying trades, other …USD_PERP pairs, quarterly contracts.

An example with figures — How the grid is counted.

A COIN-M strategy: 45 contracts, two liquidation prices

Next: T-Invest shares and funds