feat(#261): add tpsl params missing from position endpoints. add new endpoint for add/reduce margin. add doc examples
This commit is contained in:
3
examples/apidoc/V5/Position/README.md
Normal file
3
examples/apidoc/V5/Position/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# V5 - REST - Position
|
||||
|
||||
https://bybit-exchange.github.io/docs/v5/position
|
||||
20
examples/apidoc/V5/Position/add-or-reduce-margin.js
Normal file
20
examples/apidoc/V5/Position/add-or-reduce-margin.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const { RestClientV5 } = require('bybit-api');
|
||||
|
||||
const client = new RestClientV5({
|
||||
testnet: true,
|
||||
key: 'apikey',
|
||||
secret: 'apisecret',
|
||||
});
|
||||
|
||||
client
|
||||
.addOrReduceMargin({
|
||||
category: 'linear',
|
||||
symbol: 'BTCUSDT',
|
||||
margin: '10',
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
19
examples/apidoc/V5/Position/get-closed-pnl.js
Normal file
19
examples/apidoc/V5/Position/get-closed-pnl.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const { RestClientV5 } = require('bybit-api');
|
||||
|
||||
const client = new RestClientV5({
|
||||
testnet: true,
|
||||
key: 'apikey',
|
||||
secret: 'apisecret',
|
||||
});
|
||||
|
||||
client
|
||||
.getClosedPnL({
|
||||
category: 'linear',
|
||||
limit: 1,
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
20
examples/apidoc/V5/Position/get-execution.js
Normal file
20
examples/apidoc/V5/Position/get-execution.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const { RestClientV5 } = require('bybit-api');
|
||||
|
||||
const client = new RestClientV5({
|
||||
testnet: true,
|
||||
key: 'apikey',
|
||||
secret: 'apisecret',
|
||||
});
|
||||
|
||||
client
|
||||
.addOrReduceMargin({
|
||||
category: 'linear',
|
||||
symbol: 'BTCUSDT',
|
||||
margin: '10',
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
19
examples/apidoc/V5/Position/get-position-info.js
Normal file
19
examples/apidoc/V5/Position/get-position-info.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const { RestClientV5 } = require('bybit-api');
|
||||
|
||||
const client = new RestClientV5({
|
||||
testnet: true,
|
||||
key: 'apikey',
|
||||
secret: 'apisecret',
|
||||
});
|
||||
|
||||
client
|
||||
.getPositionInfo({
|
||||
category: 'inverse',
|
||||
symbol: 'BTCUSD',
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
20
examples/apidoc/V5/Position/set-auto-add-margin.js
Normal file
20
examples/apidoc/V5/Position/set-auto-add-margin.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const { RestClientV5 } = require('bybit-api');
|
||||
|
||||
const client = new RestClientV5({
|
||||
testnet: true,
|
||||
key: 'apikey',
|
||||
secret: 'apisecret',
|
||||
});
|
||||
|
||||
client
|
||||
.setAutoAddMargin({
|
||||
category: 'linear',
|
||||
symbol: 'BTCUSDT',
|
||||
autoAddMargin: 1,
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
21
examples/apidoc/V5/Position/set-leverage.js
Normal file
21
examples/apidoc/V5/Position/set-leverage.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const { RestClientV5 } = require('bybit-api');
|
||||
|
||||
const client = new RestClientV5({
|
||||
testnet: true,
|
||||
key: 'apikey',
|
||||
secret: 'apisecret',
|
||||
});
|
||||
|
||||
client
|
||||
.setLeverage({
|
||||
category: 'linear',
|
||||
symbol: 'BTCUSDT',
|
||||
buyLeverage: '6',
|
||||
sellLeverage: '6',
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
20
examples/apidoc/V5/Position/set-risk-limit.js
Normal file
20
examples/apidoc/V5/Position/set-risk-limit.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const { RestClientV5 } = require('bybit-api');
|
||||
|
||||
const client = new RestClientV5({
|
||||
testnet: true,
|
||||
key: 'apikey',
|
||||
secret: 'apisecret',
|
||||
});
|
||||
|
||||
client
|
||||
.setRiskLimit({
|
||||
category: 'linear',
|
||||
symbol: 'BTCUSDT',
|
||||
riskId: 4,
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
20
examples/apidoc/V5/Position/set-tpsl-mode.js
Normal file
20
examples/apidoc/V5/Position/set-tpsl-mode.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const { RestClientV5 } = require('bybit-api');
|
||||
|
||||
const client = new RestClientV5({
|
||||
testnet: true,
|
||||
key: 'apikey',
|
||||
secret: 'apisecret',
|
||||
});
|
||||
|
||||
client
|
||||
.setTPSLMode({
|
||||
symbol: 'XRPUSDT',
|
||||
category: 'linear',
|
||||
tpSlMode: 'Full',
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
31
examples/apidoc/V5/Position/set-trading-stop.js
Normal file
31
examples/apidoc/V5/Position/set-trading-stop.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const { RestClientV5 } = require('bybit-api');
|
||||
|
||||
const client = new RestClientV5({
|
||||
testnet: true,
|
||||
key: 'apikey',
|
||||
secret: 'apisecret',
|
||||
});
|
||||
|
||||
client
|
||||
.setTradingStop({
|
||||
category: 'linear',
|
||||
symbol: 'XRPUSDT',
|
||||
takeProfit: '0.5',
|
||||
stopLoss: '0.2',
|
||||
tpTriggerBy: 'MarkPrice',
|
||||
slTriggerBy: 'IndexPrice',
|
||||
tpslMode: 'Partial',
|
||||
tpOrderType: 'Limit',
|
||||
slOrderType: 'Limit',
|
||||
tpSize: '50',
|
||||
slSize: '50',
|
||||
tpLimitPrice: '0.49',
|
||||
slLimitPrice: '0.21',
|
||||
positionIdx: 0,
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
22
examples/apidoc/V5/Position/switch-cross-isolated-margin.js
Normal file
22
examples/apidoc/V5/Position/switch-cross-isolated-margin.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const { RestClientV5 } = require('bybit-api');
|
||||
|
||||
const client = new RestClientV5({
|
||||
testnet: true,
|
||||
key: 'apikey',
|
||||
secret: 'apisecret',
|
||||
});
|
||||
|
||||
client
|
||||
.switchIsolatedMargin({
|
||||
category: 'linear',
|
||||
symbol: 'ETHUSDT',
|
||||
tradeMode: 1,
|
||||
buyLeverage: '10',
|
||||
sellLeverage: '10',
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
20
examples/apidoc/V5/Position/switch-position-mode.js
Normal file
20
examples/apidoc/V5/Position/switch-position-mode.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const { RestClientV5 } = require('bybit-api');
|
||||
|
||||
const client = new RestClientV5({
|
||||
testnet: true,
|
||||
key: 'apikey',
|
||||
secret: 'apisecret',
|
||||
});
|
||||
|
||||
client
|
||||
.switchPositionMode({
|
||||
category: 'inverse',
|
||||
symbol: 'BTCUSDH23',
|
||||
mode: 0,
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
@@ -6,6 +6,8 @@ import {
|
||||
AccountMarginModeV5,
|
||||
AccountOrderV5,
|
||||
AccountTypeV5,
|
||||
AddOrReduceMarginParamsV5,
|
||||
AddOrReduceMarginResultV5,
|
||||
AllCoinsBalanceV5,
|
||||
AllowedDepositCoinInfoV5,
|
||||
AmendOrderParamsV5,
|
||||
@@ -618,6 +620,18 @@ export class RestClientV5 extends BaseRestClient {
|
||||
return this.postPrivate('/v5/position/set-auto-add-margin', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually add or reduce margin for isolated margin position
|
||||
*
|
||||
* Unified account covers: USDT perpetual / USDC perpetual / USDC futures / Inverse contract
|
||||
* Normal account covers: USDT perpetual / Inverse contract
|
||||
*/
|
||||
addOrReduceMargin(
|
||||
params: AddOrReduceMarginParamsV5,
|
||||
): Promise<APIResponseV3WithTime<AddOrReduceMarginResultV5>> {
|
||||
return this.postPrivate('/v5/position/add-margin', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query users' execution records, sorted by execTime in descending order
|
||||
*
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
CategoryV5,
|
||||
ExecTypeV5,
|
||||
OrderTriggerByV5,
|
||||
OrderTypeV5,
|
||||
PositionIdx,
|
||||
TPSLModeV5,
|
||||
} from '../v5-shared';
|
||||
@@ -51,16 +52,21 @@ export interface SetRiskLimitParamsV5 {
|
||||
}
|
||||
|
||||
export interface SetTradingStopParamsV5 {
|
||||
symbol: string;
|
||||
category: CategoryV5;
|
||||
symbol: string;
|
||||
takeProfit?: string;
|
||||
stopLoss?: string;
|
||||
trailingStop?: string;
|
||||
tpTriggerBy?: OrderTriggerByV5;
|
||||
slTriggerBy?: OrderTriggerByV5;
|
||||
activePrice?: string;
|
||||
tpslMode?: TPSLModeV5;
|
||||
tpSize?: string;
|
||||
slSize?: string;
|
||||
tpLimitPrice?: string;
|
||||
slLimitPrice?: string;
|
||||
tpOrderType?: OrderTypeV5;
|
||||
slOrderType?: OrderTypeV5;
|
||||
positionIdx: PositionIdx;
|
||||
}
|
||||
|
||||
@@ -71,6 +77,13 @@ export interface SetAutoAddMarginParamsV5 {
|
||||
positionIdx?: PositionIdx;
|
||||
}
|
||||
|
||||
export interface AddOrReduceMarginParamsV5 {
|
||||
category: 'linear' | 'inverse';
|
||||
symbol: string;
|
||||
margin: string;
|
||||
positionIDex?: PositionIdx;
|
||||
}
|
||||
|
||||
export interface GetExecutionListParamsV5 {
|
||||
category: CategoryV5;
|
||||
symbol?: string;
|
||||
|
||||
@@ -43,6 +43,32 @@ export interface SetRiskLimitResultV5 {
|
||||
riskLimitValue: string;
|
||||
}
|
||||
|
||||
export interface AddOrReduceMarginResultV5 {
|
||||
category: CategoryV5;
|
||||
symbol: string;
|
||||
positionIdx: PositionIdx;
|
||||
riskId: number;
|
||||
riskLimitValue: string;
|
||||
size: string;
|
||||
avgPrice: string;
|
||||
liqPrice: string;
|
||||
bustPrice: string;
|
||||
markPrice: string;
|
||||
positionValue: string;
|
||||
leverage: string;
|
||||
autoAddMargin: 0 | 1;
|
||||
positionStatus: 'Normal' | 'Liq' | 'Adl';
|
||||
positionIM: string;
|
||||
positionMM: string;
|
||||
takeProfit: string;
|
||||
stopLoss: string;
|
||||
trailingStop: string;
|
||||
unrealisedPnl: string;
|
||||
cumRealisedPnl: string;
|
||||
createdTime: string;
|
||||
updatedTime: string;
|
||||
}
|
||||
|
||||
export interface ExecutionV5 {
|
||||
symbol: string;
|
||||
orderId: string;
|
||||
|
||||
Reference in New Issue
Block a user