Bybit
Bybit (Spot): Bybit spot, plus spot margin (borrowing on order). Both unified trading accounts (UTA) and classic accounts are supported, using the Bybit V5 API; a Bybit API key (Access Key, Secret Key) is required.
Futures_Bybit (Futures): Bybit USDT and USDC perpetual and delivery contracts (linear), coin-margined perpetual and delivery contracts (inverse), and USDT-settled options. Both unified trading accounts (UTA) and classic accounts are supported, using the Bybit V5 API; a Bybit API key (Access Key, Secret Key) is required.
Names and Configuration
exchange.GetName() | Type |
|---|---|
Bybit | Spot |
Futures_Bybit | Futures |
| Field | Required |
| - | - |
| Access Key | Yes |
| Secret Key | Yes |
| Version | Yes |
| Simulate | No |
Trading Pairs and Contract Codes
Bybit (Spot)
Pair examples: BTC_USDT, ETH_BTC
Pairs are written as BTC_USDT without a contract code; use a Futures_Bybit exchange object for contracts.
Futures_Bybit (Futures)
Pair examples: BTC_USDT, BTC_USDC, BTC_USD
The quote currency selects the contract family: BTC_USDT and BTC_USDC are linear contracts, BTC_USD is inverse (coin-margined). The USDC perpetual is Bybit's BTCPERP.
| Contract code | Description |
|---|---|
swap | Perpetual contract (the default). |
delivery | The nearest-expiry delivery contract. |
this_week | Current-week delivery contract. |
next_week | Next-week delivery contract. |
third_week | Third-week delivery contract. |
month | Monthly delivery contract. |
next_month | Next-month delivery contract. |
quarter | Quarterly delivery contract. |
next_quarter | Next-quarter delivery contract. |
third_quarter | Third-quarter delivery contract. |
Delivery contracts are picked from the expiries actually listed in the Bybit instrument list: the week tiers map to contracts expiring in each of the next three seven-day windows, month tiers take month-end expiries, and quarter tiers take month-end expiries in March, June, September or December. A tier the exchange has not listed is rejected.
One contract often belongs to several tiers (a month-end contract is also a third-week contract, a coin-margined quarterly contract is also the monthly one); exchange.GetMarkets and the symbols of tickers, orders and positions use only one of them, taken in the order quarter tiers, month tiers, week tiers. A delivery contract outside every tier uses its native code as the contract code, such as BTC_USDT.BTCUSDT-24SEP27. Each contract appears once in exchange.GetMarkets; delivery always coincides with another tier and therefore does not appear. Tier codes and native codes that do not appear there still work, both exchange.SetContractType("delivery") and exchange.GetTicker("BTC_USDT.delivery").
Native contract code examples: BTCUSDU26, ETHUSDT-04APR25
Delivery contracts can also be given by their Bybit native code. Some Bybit delivery contracts have no clear cycle and are used by their native code, for example pair ETH_USDT with contract code ETHUSDT-04APR25.
Exchange-specific IO Commands
Bybit (Spot)
| Command | Arguments | Description | Returns |
|---|---|---|---|
trade_margin | — | Spot margin; subsequent orders (conditional orders included) carry isLeverage=1 and borrow automatically. Kept locally; no request is made. | The command name itself. |
trade_normal | — | Switch back to normal spot (the default). | The command name itself. |
accountType | string | Set the account type (which wallet asset queries read): UNIFIED (unified trading account) or SPOT (the spot wallet of a classic account). Detected automatically on the first asset query when not set. | The account type set. |
For the common commands api, base and currency see exchange.IO.
Futures_Bybit (Futures)
| Command | Arguments | Description | Returns |
|---|---|---|---|
cross | bool[, symbol] | Cross (true) / isolated (false) margin; sends a per-contract switch request to the exchange that also sets buy and sell leverage (the contract's last exchange.SetMarginLevel() value, or 10x if never set). No request is sent when this command already switched to the same mode. Not available for options. | Null also on success; check GetLastError() afterwards when needed. |
dual | bool[, symbol] | Hedge (true) / one-way (false) position mode; sends a switch request to the exchange (carrying the contract's symbol). No request is sent when this command already switched to the same mode. Not available for options. | Null also on success; check GetLastError() afterwards when needed. |
accountType | string | Set the wallet that asset queries read: UNIFIED (unified trading account), CONTRACT (the contract wallet of a classic account); auto restores auto-detection (the default). | The account type set (auto for auto-detection). |
For the common commands api, base and currency see exchange.IO.
Common Usage
Choose the wallet read by asset queries (Bybit only)
javascript
function main() {
// Unified trading account; use SPOT for the spot wallet of a classic account.
// Once set, the account type is no longer detected automatically
Log(exchange.IO("accountType", "UNIFIED")) // UNIFIED
Log(exchange.GetAssets())
}
Choose the wallet read by asset queries, then restore auto-detection (Futures_Bybit only)
javascript
function main() {
// Unified trading account; use CONTRACT for the contract wallet of a classic account
Log(exchange.IO("accountType", "UNIFIED")) // UNIFIED
Log(exchange.GetAssets())
// Restore auto-detection (the default)
Log(exchange.IO("accountType", "auto")) // auto
}
Function Support
All exchange objects
No unsupported standard functions.
Bybit (Spot)
Served through a fallback:
exchange.GetRecords: Native periods are 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d, 1w, 1M; other periods are synthesized by the docker.
Futures_Bybit (Futures)
Served through a fallback:
exchange.GetRecords: Native periods are 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d, 1w, 1M; other periods are synthesized by the docker. Options have no K-line endpoint; their bars are synthesized by the docker from trades.
Margin, Account and Simulation
All exchange objects
Simulation: The Simulate box uses Bybit Demo Trading (api-demo.bybit.com); the API key must be created on the Bybit main site after switching to Demo Trading mode. It is not the same environment as testnet.
Bybit (Spot)
Account: Spot assets of unified trading accounts and classic accounts live in different wallets; the connector queries the account type on the first asset query (or set it with exchange.IO("accountType", ...)). Spot margin is enabled with exchange.IO("trade_margin"), after which orders borrow when placed.
Futures_Bybit (Futures)
Margin mode: Switch cross/isolated margin per contract with exchange.IO("cross", bool); set leverage (the same for buy and sell) with exchange.SetMarginLevel().
Position mode: The contract's position mode is queried automatically before orders, and positionIdx is added in hedge mode; positionIdx can also be passed explicitly in the order's extra parameters, or the mode switched with exchange.IO("dual", bool).
Account: The account type is detected on the first asset query. Under unified trading account 1.0, linear assets are in the unified wallet and inverse assets in the contract wallet; exchange.GetAssets() queries both.
Options
Futures_Bybit (Futures)
Bybit USDT-settled options are supported (Bybit currently lists USDT-settled options only).
- The result of
exchange.GetMarkets()includes option contracts. - Conditional orders and
exchange.SetMarginLevel()are not supported, andcrossanddualcannot switch the margin or position mode.
Option code examples: ETH-25JUN27-2800-C-USDT
Option codes are Bybit native codes: underlying-expiry-strike-C/P-settlement coin. Bybit options settle in USDT; set the pair to ETH_USDT, the full symbol looks like ETH_USDT.ETH-25JUN27-2800-C-USDT; the pair's quote currency must match the settlement coin.
Notes
All exchange objects
- Conditional orders support take-profit and stop-loss only, not OCO; create a take-profit order and a stop-loss order separately when needed.
exchange.ModifyOrder()andexchange.ModifyConditionOrder()amend in place; the order ID does not change.
Bybit (Spot)
- Market-order quantities follow the Bybit API default (a market buy is a quote-currency amount); pass
marketUnit(baseCoinorquoteCoin) in the order's extra parameters to choose the unit; extra parameters are passed to the exchange as is.
Futures_Bybit (Futures)
- The result of
exchange.GetMarkets()includes pre-launch (PreLaunch) contracts. - Order quantity units: linear contracts and options are in base coin; inverse (coin-margined) contracts are in contracts of 1 USD each; see
CtValandCtValCcyinexchange.GetMarkets().