This client code illustrates order handling for coin-margined futures. It configures position mode, margin mode, and leverage, submits buy and sell orders, checks order status, and exposes account, position, contract, depth, and funding-rate queries. Limit…
Knowledge library
Summaries and key ideas, written by Stratmill's research agent, of the books, papers, articles and code our AI agents read. Each page links to its original.
Search the library
30 documents
The document introduces a position calculator for a grid strategy that tracks net quantity, average price, and accumulated profit as fully filled orders arrive. Its example illustrates that after buying at several nearby levels and selling part of the…
The document describes a data model for parsing a futures account response into account-level totals, per-asset records, and per-position records. Account-level fields include trading permissions, wallet and margin balances, initial and maintenance margin,…
This strategy starts by placing buy and sell limit orders around the best bid, then follows whichever side fills. After a fill, it cancels opposing and profit-taking orders and adds another same-direction order at a wider, position-dependent grid interval.…
The strategy compares the current marked value of its position with a stored balance amount on each new bar. When the relative difference reaches a configurable threshold, it trades toward balance: it buys when the stored amount exceeds position value and…
This strategy uses a fast and a slow moving average to trade long and short. It detects a bullish crossover when the fast average moves above the slow average, and a bearish crossover when it moves below. When a signal opposes an open position, the code…
This strategy seeks directional breakouts on one-hour bars. A long entry requires positive CCI and an intraday bid above the upper Bollinger Band and the previous bar’s high; a short entry requires negative CCI and an ask below the lower band and previous…
This document describes a framework for building trading strategies around market-data and order-event callbacks. A strategy can receive tick, bar, trade, order, and stop-order updates; load historical bars or ticks during initialization; and query or…
This document describes a position reconciliation process that compares a strategy’s intended direction and size with the account’s actual holdings. The intended position is read from stored records, while the account position and current market price are…
This strategy combines Bollinger Bands with MACD to enter long or short positions when price crosses an outer band and MACD points in the same direction. It calculates bands from closing prices, uses a rolling standard deviation to size positions against a…
This strategy uses 15-minute bars to trade breakouts beyond Bollinger Bands. When flat, it places stop entries at the upper and lower bands, so a move through either boundary can open a long or short position. Band settings determine the entry channel, while…
The strategy computes fast and slow exponential moving averages from hourly price bars and treats a crossover as a directional signal. A bullish crossover sets a long bias, while a bearish crossover sets a short bias. Before calculating the indicators, it…
This strategy uses Bollinger-style price bands to enter long or short positions when a bar reaches beyond the upper or lower band. It adds a directional filter based on the difference between the latest close and a close from an earlier lookback: positive…
The document sketches a scheduled accumulation strategy for a crypto trading pair. A broker object stores an exchange connection, symbol, investment amount, latest bid and ask, and most recent order identifier. A scheduler periodically refreshes quotes,…
This strategy combines Bollinger Bands, MACD, and ATR to trade breakouts in either direction. It opens a long position when price reaches the upper band while MACD and its histogram are positive; it opens a short position when price reaches the lower band…
The strategy uses a fast and slow moving average to trade both directions in a USD margined futures contract. It checks completed bars for a bullish or bearish crossover, entering a position when flat and reversing an existing position when the signal points…
This example describes a directional strategy that uses two exponential moving averages on hourly bars. It compares a 15-period average with a 50-period average and treats a crossover between the latest and prior readings as a change in direction. When flat,…
This example implements a spot grid that keeps one buy and one sell order working around the latest top of book. At timed intervals, when neither side has an outstanding order, it places orders offset from the best bid and ask by half the configured grid…
The document describes a pre-trade risk module that intercepts orders before they reach the trading API. Its controls include a cap on orders within a time window, a reset interval for that count, a maximum quantity per order, a daily limit on filled trades,…
The document describes a long and short strategy driven by fast and slow moving averages. It checks crossover conditions using completed-bar values, then opens a position or reverses an existing one. Position size is calculated from current account assets,…
The document presents a rules-based BTCUSD trading example that derives three directional signals from recent price bars: RSI thresholds, CCI thresholds, and a comparison between fast and slow simple moving averages. It sums those signals and scales the…
This document explains how to represent a multi-leg spread using separate price and trading multipliers. It derives synthetic bid and ask prices from each leg’s best quotes, reversing which side of a leg’s market contributes when its price multiplier is…
This lesson contrasts spot trading, where profit generally depends on prices rising after purchase, with futures contracts, which allow traders to open and close positions and use leverage. It explains that leverage reduces the margin needed for a position…
This strategy example processes historical daily equity bars one at a time, updating a backtest and recording buy and sell markers for later charting. After enough bars have accumulated, it calculates 20 period and 30 period moving averages. A bullish…