Add Or Reduce Margin
Manually add or reduce margin for isolated margin position
HTTP Request
POST /v5/position/add-margin
Request Parameters
| Parameter | Required | Type | Comments |
|---|---|---|---|
| category | true | string | Product type |
| symbol | true | string | Symbol name, like BTCUSDT, uppercase only |
| margin | true | string | Add or reduce. To add, then 10; To reduce, then -10. Support up to 4 decimal |
| positionIdx | false | integer | Used to identify positions in different position modes. For hedge mode position, this param is required
|
Response Parameters
| Parameter | Type | Comments |
|---|---|---|
| category | string | Product type |
| symbol | string | Symbol name |
| positionIdx | integer | Position idx, used to identify positions in different position modes
|
| riskId | integer | Risk limit ID |
| riskLimitValue | string | Risk limit value |
| size | string | Position size |
| avgPrice | string | Average entry price |
| liqPrice | string | Liquidation price |
| bustPrice | string | Bankruptcy price |
| markPrice | string | Last mark price |
| positionValue | string | Position value |
| leverage | string | Position leverage |
| autoAddMargin | integer | Whether to add margin automatically. 0: false, 1: true |
| positionStatus | String | Position status. Normal, Liq, Adl |
| positionIM | string | Initial margin |
| positionMM | string | Maintenance margin |
| takeProfit | string | Take profit price |
| stopLoss | string | Stop loss price |
| trailingStop | string | Trailing stop (The distance from market price) |
| unrealisedPnl | string | Unrealised PnL |
| cumRealisedPnl | string | Cumulative realised pnl |
| createdTime | string | Timestamp of the first time a position was created on this symbol (ms) |
| updatedTime | string | Position updated timestamp (ms) |
Request Example
- HTTP
- Python
- Java
- Node.js
POST /v5/position/add-margin HTTP/1.1
Host: api-testnet.bybit.com
X-BAPI-SIGN: XXXXXX
X-BAPI-API-KEY: xxxxxxxxxxxxxxxxxx
X-BAPI-TIMESTAMP: 1684234363665
X-BAPI-RECV-WINDOW: 5000
Content-Type: application/json
Content-Length: 97
{
"category": "inverse",
"symbol": "ETHUSD",
"margin": "0.01",
"positionIdx": 0
}
from pybit.unified_trading import HTTP
session = HTTP(
testnet=True,
api_key="xxxxxxxxxxxxxxxxxx",
api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
)
print(session.add_or_reduce_margin(
category="linear",
symbol="BTCUSDT",
margin="10"
))
import com.bybit.api.client.domain.*;
import com.bybit.api.client.domain.position.*;
import com.bybit.api.client.domain.position.request.*;
import com.bybit.api.client.service.BybitApiClientFactory;
var client = BybitApiClientFactory.newInstance().newAsyncPositionRestClient();
var updateMarginRequest = PositionDataRequest.builder().category(CategoryType.INVERSE).symbol("ETHUSDT").margin("0.0001").build();
client.modifyPositionMargin(updateMarginRequest, System.out::println);
const { RestClientV5 } = require('bybit-api');
const client = new RestClientV5({
testnet: true,
key: 'xxxxxxxxxxxxxxxxxx',
secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
});
client
.addOrReduceMargin({
category: 'linear',
symbol: 'BTCUSDT',
margin: '10',
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});
Response Example
{
"retCode": 0,
"retMsg": "OK",
"result": {
"category": "inverse",
"symbol": "ETHUSD",
"positionIdx": 0,
"riskId": 11,
"riskLimitValue": "500",
"size": "200",
"positionValue": "0.11033265",
"avgPrice": "1812.70004844",
"liqPrice": "1550.80",
"bustPrice": "1544.20",
"markPrice": "1812.90",
"leverage": "12",
"autoAddMargin": 0,
"positionStatus": "Normal",
"positionIM": "0.01926611",
"positionMM": "0",
"unrealisedPnl": "0.00001217",
"cumRealisedPnl": "-0.04618929",
"stopLoss": "0.00",
"takeProfit": "0.00",
"trailingStop": "0.00",
"createdTime": "1672737740039",
"updatedTime": "1684234363788"
},
"retExtInfo": {},
"time": 1684234363789
}