Bybit Trade Connector
Features
crypto-bybitwsConnector KeyNotes
Bybit Server Location
AWS Singapore, Availability Zone ID: apse1-az3
Commission
Rate Limits
Price and Quantity
Both price and quantity should be adjusted according to price_filter and lot_size_filter.
Non-adjusted price or quantity will be silently adjusted on exchange side.
Post Only
In Bybit API Post Only orders are represented via Bybit Time In Force.
When Post Only flag is defined in an order request, it takes precedence over the specified Time In Force.
If the Post Only flag is present, the request's Time In Force is ignored and the order is placed as Post Only.
Client Order ID
Client Order ID (orderLinkId) should be unique, with a maximum length of 36 characters.
Source and format of the Client Order ID are controlled by the orderMapperType setting:
| Order Mapper Type | Client Order ID source | Rules and Restrictions |
|---|---|---|
SEQUENCE | Order request's sequence number | sequence is numeric. clientOrderIdPrefix setting can be used for customization. |
COMPOSITE | Order request's sourceId and orderId | sourceId and orderId are concatenated with : delimiter. |
Market Maker Protection
Market Maker Protection (MMP) is an automated mechanism designed to protect market makers against liquidity risks and over-exposure. It prevents simultaneous trade executions on quotes provided by the market maker within a short time span.
Spot Margin Trading
Spot Margin Trading (leverageMode = MARGIN) is available only for Unified Trading Account.
Position Mode
Position mode can be switched for USDT perpetual and Inverse futures. In one-way mode, only one position (Buy or Sell) can be open at a time. In hedge mode, both Buy and Sell positions can be open simultaneously.
There are two ways to set position mode:
- Per order - via custom order attribute:
6340 - Per connector - via
positionModesettings
| Mode | positionMode settings | Tag 6340 |
|---|---|---|
| One-Way Mode | ONE_WAY_MODE | 0 |
| Buy side of both side mode | BUY_BOTH_SIDE_MODE | 1 |
| Sell side of both side mode | SELL_BOTH_SIDE_MODE | 2 |
Position mode support by account and contract type:
| Product | Classic account | UTA1.0 | UTA2.0 |
|---|---|---|---|
| USDT perpetual | Support one-way & hedge-mode | Support one-way & hedge-mode | Support one-way & hedge-mode |
| USDC perpetual | Support one-way only | Support one-way only | Support one-way only |
| USDC futures | Support one-way only | Support one-way only | Support one-way only |
| Inverse perpetual | Support one-way only | Support one-way only | Support one-way only |
| Inverse futures | Support one-way & hedge-mode | Support one-way & hedge-mode | Support one-way only |
Clock Sync Issue
Bybit can respond with "Params Error" if machine clock is not synchronized.
{"type":"WS Message","content":{"success":false,"ret_msg":"Params Error","op":"auth","conn_id":"chled4kpqfhcpr4memcg-5zwa"}}
Symbology
Instruments can be requested by category: spot, linear, inverse, option:
https://api.bybit.com/v5/market/instruments-info?limit=1000&category=spot
Configuration
Connector settings
| Parameter | Default Value | Description |
|---|---|---|
| restUrl | wss://stream.bybit.com/v5/trade | Trade request WebSocket URL. |
| websocketUrl | wss://stream.bybit.com/v5/private | Order event WebSocket URL. |
| tradeWebsocketUrl | wss://stream.bybit.com/v5/trade | Trade request WebSocket URL. |
| submitRecvWindow | 1s | The interval (in milliseconds) to specify how long an HTTP request is valid. Default is 1 second. |
| reduceOnly | false | Reduce Only flag. |
| leverageMode | SPOT | Leverage Mode. Valid for spot only. Valid values: SPOT - spot trading, MARGIN: - margin trading. |
| positionMode | NONE | Position Mode. Valid values: NONE, ONE_WAY_MODE, BUY_BOTH_SIDE_MODE, SELL_BOTH_SIDE_MODE. |
| clientOrderIdPrefix | Optional prefix for Client Order ID (aka orderLinkId). Applied only when orderMapperType is SEQUENCE. | |
| orderMapperType | SEQUENCE | Type of the mapper which is used to map order to Client Order ID. Supported values: COMPOSITE, SEQUENCE. See Client Order ID section for detailed explanation. |
| useRPI | false | Flag to use RPI (Retail Price Improvement) as the Time In Force for Post Only orders. |
Supported order attributes
| Key | Description |
|---|---|
| 18 | 6 value used for Post Only orders submission |
| 6201 | Reduce Only flag. See Reduce Only Order |
| 6470 | Offset attribute to determine offset direction. Possible values: OPEN or CLOSE. CLOSE means that order will be send with ReduceOnly flag. |
| 6231 | Market Maker Protection flag, true means this order is a market maker protection order. |
| 6241 | Leverage Mode. Whether to borrow. Valid for spot only. 0 - spot trading, 1: - margin trading. |
| 6340 | Position Mode. Possible values: 0 - One-Way Mode, 1 - Buy side of both side mode, 2 - Sell side of both side mode. |
Config sample
connectors {
BYBIT: ${template.connector.crypto.bybitws} {
settings {
restUrl = "https://api.bybit.com"
websocketUrl = "wss://stream.bybit.com/v5/private"
tradeWebsocketUrl = "wss://stream.bybit.com/v5/trade"
apiKeys: [
{
apiKey = "<API_KEY>"
apiSecret = "<API_SECRET>"
}
]
leverageMode = SPOT # SPOT - spot trading, MARGIN: - margin trading.
positionMode = NONE # NONE, ONE_WAY_MODE, BUY_BOTH_SIDE_MODE, SELL_BOTH_SIDE_MODE
}
}
}