# Position

{% hint style="warning" %}
**All parameters  of type INTEGER listed in the Bybit API docs need to be passed in as a string.**
{% endhint %}

## Get Position Info

{% hint style="info" %}
Please refer to the official ByBit API Docs for the required parameters.

<https://bybit-exchange.github.io/docs/v5/position>
{% endhint %}

#### Function name:

```javascript
getPositionInfo(options)
```

#### Usage:&#x20;

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myByBitAccount = createExchange({
      exchange: "bybit",
      authenticate: "true",
      key: "myKeys",
      secret: "mySecret",
      label: "bybit",
      testnet: "false"
});

async function getPositionInfo(exchange, options) {
    try {
        let result = await exchange.getPositionInfo(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getPositionInfo(myByBitAccount, 
    {
       category: 'linear',
       symbol: 'BTCUSDT'
     });
```

## Set Leverage

{% hint style="info" %}
Please refer to the official ByBit API Docs for the required parameters.

<https://bybit-exchange.github.io/docs/v5/position/leverage>
{% endhint %}

#### Function name:

```javascript
setLeverage(options)
```

#### Usage:&#x20;

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myByBitAccount = createExchange({
      exchange: "bybit",
      authenticate: "true",
      key: "myKeys",
      secret: "mySecret",
      label: "bybit",
      testnet: "false"
});

async function setLeverage(exchange, options) {
    try {
        let result = await exchange.setLeverage(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await setLeverage(myByBitAccount, 
    {
       category: 'linear',
       symbol: 'BTCUSD',
       buyLeverage: '6',
       sellLeverage: '6'
     });
```

## Switch Cross/Isolated Margin

{% hint style="info" %}
Please refer to the official ByBit API Docs for the required parameters.

<https://bybit-exchange.github.io/docs/v5/position/cross-isolate>
{% endhint %}

#### Function name:

```javascript
switchCrossIsolatedMargin(options)
```

#### Usage:&#x20;

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myByBitAccount = createExchange({
      exchange: "bybit",
      authenticate: "true",
      key: "myKeys",
      secret: "mySecret",
      label: "bybit",
      testnet: "false"
});

async function switchCrossIsolatedMargin(exchange, options) {
    try {
        let result = await exchange.switchCrossIsolatedMargin(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await switchCrossIsolatedMargin(myByBitAccount, 
    {
       category: 'linear',
       symbol: 'BTCUSD',
       tradeMode: '0',
       buyLeverage: '6',
       sellLeverage: '6'
     });
```

## Set TP/SL Mode

{% hint style="info" %}
Please refer to the official ByBit API Docs for the required parameters.

<https://bybit-exchange.github.io/docs/v5/position/tpsl-mode>
{% endhint %}

#### Function name:

```javascript
setTpslMode(options)
```

#### Usage:&#x20;

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myByBitAccount = createExchange({
      exchange: "bybit",
      authenticate: "true",
      key: "myKeys",
      secret: "mySecret",
      label: "bybit",
      testnet: "false"
});

async function setTpslMode(exchange, options) {
    try {
        let result = await exchange.setTpslMode(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await setTpslMode(myByBitAccount, 
    {
       category: 'linear',
       symbol: 'BTCUSD',
       tpSlMode: 'Full'
     });
```

## Switch Position Mode

{% hint style="info" %}
Please refer to the official ByBit API Docs for the required parameters.

<https://bybit-exchange.github.io/docs/v5/position/position-mode>
{% endhint %}

#### Function name:

```javascript
switchPositionMode(options)
```

#### Usage:&#x20;

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myByBitAccount = createExchange({
      exchange: "bybit",
      authenticate: "true",
      key: "myKeys",
      secret: "mySecret",
      label: "bybit",
      testnet: "false"
});

async function switchPositionMode(exchange, options) {
    try {
        let result = await exchange.switchPositionMode(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await switchPositionMode(myByBitAccount, 
    {
       category: 'linear',
       mode: '0'
     });
```

## Set Risk Limit

{% hint style="info" %}
Please refer to the official ByBit API Docs for the required parameters.

<https://bybit-exchange.github.io/docs/v5/position/set-risk-limit>
{% endhint %}

#### Function name:

```javascript
setRiskLimit(options)
```

#### Usage:&#x20;

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myByBitAccount = createExchange({
      exchange: "bybit",
      authenticate: "true",
      key: "myKeys",
      secret: "mySecret",
      label: "bybit",
      testnet: "false"
});

async function setRiskLimit(exchange, options) {
    try {
        let result = await exchange.setRiskLimit(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await setRiskLimit(myByBitAccount, 
    {
       category: 'linear',
       symbol: 'BTCUSDT',
       riskId: '4'
     });
```

## Set Trading Stop

{% hint style="info" %}
Please refer to the official ByBit API Docs for the required parameters.

<https://bybit-exchange.github.io/docs/v5/position/trading-stop>
{% endhint %}

#### Function name:

```javascript
setTradingStop(options)
```

#### Usage:&#x20;

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myByBitAccount = createExchange({
      exchange: "bybit",
      authenticate: "true",
      key: "myKeys",
      secret: "mySecret",
      label: "bybit",
      testnet: "false"
});

async function setTradingStop(exchange, options) {
    try {
        let result = await exchange.setTradingStop(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await setTradingStop(myByBitAccount, 
    {
       category: 'linear',
       symbol: 'BTCUSD',
       positionIdx: '0',
       takeProfit: '0'
     });
```

## Set Auto Add Margin

{% hint style="info" %}
Please refer to the official ByBit API Docs for the required parameters.

<https://bybit-exchange.github.io/docs/v5/position/add-margin>
{% endhint %}

#### Function name:

```javascript
setAutoAddMargin(options)
```

#### Usage:&#x20;

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myByBitAccount = createExchange({
      exchange: "bybit",
      authenticate: "true",
      key: "myKeys",
      secret: "mySecret",
      label: "bybit",
      testnet: "false"
});

async function setAutoAddMargin(exchange, options) {
    try {
        let result = await exchange.setAutoAddMargin(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await setAutoAddMargin(myByBitAccount, 
    {
       category: 'linear',
       symbol: 'BTCUSD',
       autoAddMargin: '0'
     });
```

## Get Execution

{% hint style="info" %}
Please refer to the official ByBit API Docs for the required parameters.

<https://bybit-exchange.github.io/docs/v5/position/execution>
{% endhint %}

#### Function name:

```javascript
getExecution(options)
```

#### Usage:&#x20;

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myByBitAccount = createExchange({
      exchange: "bybit",
      authenticate: "true",
      key: "myKeys",
      secret: "mySecret",
      label: "bybit",
      testnet: "false"
});

async function getExecution(exchange, options) {
    try {
        let result = await exchange.getExecution(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getExecution(myByBitAccount, 
    {
       category: 'linear',
       symbol: 'BTCUSD'
     });
```

## Get Closed PnL

{% hint style="info" %}
Please refer to the official ByBit API Docs for the required parameters.

<https://bybit-exchange.github.io/docs/v5/position/close-pnl>
{% endhint %}

#### Function name:

```javascript
getClosedPnl(options)
```

#### Usage:&#x20;

```javascript
import { createExchange } from "./exchanges/exchange.js";

  let myByBitAccount = createExchange({
      exchange: "bybit",
      authenticate: "true",
      key: "myKeys",
      secret: "mySecret",
      label: "bybit",
      testnet: "false"
});

async function getClosedPnl(exchange, options) {
    try {
        let result = await exchange.getClosedPnl(options);
        console.log(result);
    } catch (error) {
        console.log(error.message);
    }
}

const result = await getClosedPnl(myByBitAccount, 
    {
       category: 'linear',
       symbol: 'BTCUSD'
     });
```
