> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gains.trade/llms.txt
> Use this file to discover all available pages before exploring further.

# ITradingStorageUtils

*Interface for GNSTradingStorage facet (inherits types and also contains functions, events, and custom errors)*

## initializeTradingStorage

```solidity theme={null}
function initializeTradingStorage(address _gns, address _gnsStaking, address[] _collaterals, address[] _gTokens) external
```

*Initializes the trading storage facet*

### Parameters

| Name          | Type       | Description                         |
| ------------- | ---------- | ----------------------------------- |
| \_gns         | address    | address of the gns token            |
| \_gnsStaking  | address    | address of the gns staking contract |
| \_collaterals | address\[] |                                     |
| \_gTokens     | address\[] |                                     |

## updateTradingActivated

```solidity theme={null}
function updateTradingActivated(enum ITradingStorage.TradingActivated _activated) external
```

*Updates the trading activated state*

### Parameters

| Name        | Type                                  | Description                     |
| ----------- | ------------------------------------- | ------------------------------- |
| \_activated | enum ITradingStorage.TradingActivated | the new trading activated state |

## addCollateral

```solidity theme={null}
function addCollateral(address _collateral, address _gToken) external
```

*Adds a new supported collateral*

### Parameters

| Name         | Type    | Description                           |
| ------------ | ------- | ------------------------------------- |
| \_collateral | address | the address of the collateral         |
| \_gToken     | address | the gToken contract of the collateral |

## toggleCollateralActiveState

```solidity theme={null}
function toggleCollateralActiveState(uint8 _collateralIndex) external
```

*Toggles the active state of a supported collateral*

### Parameters

| Name              | Type  | Description             |
| ----------------- | ----- | ----------------------- |
| \_collateralIndex | uint8 | index of the collateral |

## updateGToken

```solidity theme={null}
function updateGToken(address _collateral, address _gToken) external
```

*Updates the contracts of a supported collateral trading stack*

### Parameters

| Name         | Type    | Description                           |
| ------------ | ------- | ------------------------------------- |
| \_collateral | address | address of the collateral             |
| \_gToken     | address | the gToken contract of the collateral |

## storeTrade

```solidity theme={null}
function storeTrade(struct ITradingStorage.Trade _trade, struct ITradingStorage.TradeInfo _tradeInfo) external returns (struct ITradingStorage.Trade)
```

*Stores a new trade (trade/limit/stop)*

### Parameters

| Name        | Type                                                                                                             | Description             |
| ----------- | ---------------------------------------------------------------------------------------------------------------- | ----------------------- |
| \_trade     | [ITradingStorage.Trade](/developer/technical-reference/contracts/interfaces/types/itradingstorage#trade)         | trade to be stored      |
| \_tradeInfo | [ITradingStorage.TradeInfo](/developer/technical-reference/contracts/interfaces/types/itradingstorage#tradeinfo) | trade info to be stored |

## updateTradeMaxClosingSlippageP

```solidity theme={null}
function updateTradeMaxClosingSlippageP(struct ITradingStorage.Id _tradeId, uint16 _maxSlippageP) external
```

*Updates an existing trade max closing slippage %*

### Parameters

| Name           | Type                                                                                               | Description                        |
| -------------- | -------------------------------------------------------------------------------------------------- | ---------------------------------- |
| \_tradeId      | [ITradingStorage.Id](/developer/technical-reference/contracts/interfaces/types/itradingstorage#id) | id of the trade                    |
| \_maxSlippageP | uint16                                                                                             | new max slippage % (1e3 precision) |

## updateTradeCollateralAmount

```solidity theme={null}
function updateTradeCollateralAmount(struct ITradingStorage.Id _tradeId, uint120 _collateralAmount) external
```

*Updates an open trade collateral*

### Parameters

| Name               | Type                                                                                               | Description                                        |
| ------------------ | -------------------------------------------------------------------------------------------------- | -------------------------------------------------- |
| \_tradeId          | [ITradingStorage.Id](/developer/technical-reference/contracts/interfaces/types/itradingstorage#id) | id of updated trade                                |
| \_collateralAmount | uint120                                                                                            | new collateral amount value (collateral precision) |

## updateTradePosition

```solidity theme={null}
function updateTradePosition(struct ITradingStorage.Id _tradeId, uint120 _collateralAmount, uint24 _leverage, uint64 _openPrice, bool _isPartialIncrease, bool _isPnlPositive) external
```

*Updates an open trade collateral*

### Parameters

| Name                | Type                                                                                               | Description                                              |
| ------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
| \_tradeId           | [ITradingStorage.Id](/developer/technical-reference/contracts/interfaces/types/itradingstorage#id) | id of updated trade                                      |
| \_collateralAmount  | uint120                                                                                            | new collateral amount value (collateral precision)       |
| \_leverage          | uint24                                                                                             | new leverage value                                       |
| \_openPrice         | uint64                                                                                             | new open price value                                     |
| \_isPartialIncrease | bool                                                                                               | refreshes trade liquidation params if true               |
| \_isPnlPositive     | bool                                                                                               | whether the pnl is positive (only relevant when closing) |

## updateOpenOrderDetails

```solidity theme={null}
function updateOpenOrderDetails(struct ITradingStorage.Id _tradeId, uint64 _openPrice, uint64 _tp, uint64 _sl, uint16 _maxSlippageP) external
```

*Updates an open order details (limit/stop)*

### Parameters

| Name           | Type                                                                                               | Description                    |
| -------------- | -------------------------------------------------------------------------------------------------- | ------------------------------ |
| \_tradeId      | [ITradingStorage.Id](/developer/technical-reference/contracts/interfaces/types/itradingstorage#id) | id of updated trade            |
| \_openPrice    | uint64                                                                                             | new open price (1e10)          |
| \_tp           | uint64                                                                                             | new take profit price (1e10)   |
| \_sl           | uint64                                                                                             | new stop loss price (1e10)     |
| \_maxSlippageP | uint16                                                                                             | new max slippage % value (1e3) |

## updateTradeTp

```solidity theme={null}
function updateTradeTp(struct ITradingStorage.Id _tradeId, uint64 _newTp) external
```

*Updates the take profit of an open trade*

### Parameters

| Name      | Type                                                                                               | Description                          |
| --------- | -------------------------------------------------------------------------------------------------- | ------------------------------------ |
| \_tradeId | [ITradingStorage.Id](/developer/technical-reference/contracts/interfaces/types/itradingstorage#id) | the trade id                         |
| \_newTp   | uint64                                                                                             | the new take profit (1e10 precision) |

## updateTradeSl

```solidity theme={null}
function updateTradeSl(struct ITradingStorage.Id _tradeId, uint64 _newSl) external
```

*Updates the stop loss of an open trade*

### Parameters

| Name      | Type                                                                                               | Description                 |
| --------- | -------------------------------------------------------------------------------------------------- | --------------------------- |
| \_tradeId | [ITradingStorage.Id](/developer/technical-reference/contracts/interfaces/types/itradingstorage#id) | the trade id                |
| \_newSl   | uint64                                                                                             | the new sl (1e10 precision) |

## closeTrade

```solidity theme={null}
function closeTrade(struct ITradingStorage.Id _tradeId, bool _isPnlPositive) external
```

*Marks an open trade/limit/stop as closed*

### Parameters

| Name            | Type                                                                                               | Description                 |
| --------------- | -------------------------------------------------------------------------------------------------- | --------------------------- |
| \_tradeId       | [ITradingStorage.Id](/developer/technical-reference/contracts/interfaces/types/itradingstorage#id) | the trade id                |
| \_isPnlPositive | bool                                                                                               | whether the pnl is positive |

## storePendingOrder

```solidity theme={null}
function storePendingOrder(struct ITradingStorage.PendingOrder _pendingOrder) external returns (struct ITradingStorage.PendingOrder)
```

*Stores a new pending order*

### Parameters

| Name           | Type                                                                                                                   | Description                    |
| -------------- | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
| \_pendingOrder | [ITradingStorage.PendingOrder](/developer/technical-reference/contracts/interfaces/types/itradingstorage#pendingorder) | the pending order to be stored |

## closePendingOrder

```solidity theme={null}
function closePendingOrder(struct ITradingStorage.Id _orderId) external
```

*Closes a pending order*

### Parameters

| Name      | Type                                                                                               | Description                              |
| --------- | -------------------------------------------------------------------------------------------------- | ---------------------------------------- |
| \_orderId | [ITradingStorage.Id](/developer/technical-reference/contracts/interfaces/types/itradingstorage#id) | the id of the pending order to be closed |

## getCollateral

```solidity theme={null}
function getCollateral(uint8 _index) external view returns (struct ITradingStorage.Collateral)
```

*Returns collateral data by index*

### Parameters

| Name    | Type  | Description                           |
| ------- | ----- | ------------------------------------- |
| \_index | uint8 | the index of the supported collateral |

## isCollateralActive

```solidity theme={null}
function isCollateralActive(uint8 _index) external view returns (bool)
```

*Returns whether can open new trades with a collateral*

### Parameters

| Name    | Type  | Description                          |
| ------- | ----- | ------------------------------------ |
| \_index | uint8 | the index of the collateral to check |

## isCollateralListed

```solidity theme={null}
function isCollateralListed(uint8 _index) external view returns (bool)
```

*Returns whether a collateral has been listed*

### Parameters

| Name    | Type  | Description                          |
| ------- | ----- | ------------------------------------ |
| \_index | uint8 | the index of the collateral to check |

## getCollateralsCount

```solidity theme={null}
function getCollateralsCount() external view returns (uint8)
```

*Returns the number of supported collaterals*

## getCollaterals

```solidity theme={null}
function getCollaterals() external view returns (struct ITradingStorage.Collateral[])
```

*Returns the supported collaterals*

## getCollateralIndex

```solidity theme={null}
function getCollateralIndex(address _collateral) external view returns (uint8)
```

*Returns the index of a supported collateral*

### Parameters

| Name         | Type    | Description                   |
| ------------ | ------- | ----------------------------- |
| \_collateral | address | the address of the collateral |

## getTradingActivated

```solidity theme={null}
function getTradingActivated() external view returns (enum ITradingStorage.TradingActivated)
```

*Returns the trading activated state*

## getTraderStored

```solidity theme={null}
function getTraderStored(address _trader) external view returns (bool)
```

*Returns whether a trader is stored in the traders array*

### Parameters

| Name     | Type    | Description     |
| -------- | ------- | --------------- |
| \_trader | address | trader to check |

## getTradersCount

```solidity theme={null}
function getTradersCount() external view returns (uint256)
```

*Returns the length of the traders array*

## getTraders

```solidity theme={null}
function getTraders(uint32 _offset, uint32 _limit) external view returns (address[])
```

*Returns all traders that have open trades using a pagination system*

### Parameters

| Name     | Type   | Description                      |
| -------- | ------ | -------------------------------- |
| \_offset | uint32 | start index in the traders array |
| \_limit  | uint32 | end index in the traders array   |

## getTrade

```solidity theme={null}
function getTrade(address _trader, uint32 _index) external view returns (struct ITradingStorage.Trade)
```

*Returns open trade/limit/stop order*

### Parameters

| Name     | Type    | Description                   |
| -------- | ------- | ----------------------------- |
| \_trader | address | address of the trader         |
| \_index  | uint32  | index of the trade for trader |

## getTrades

```solidity theme={null}
function getTrades(address _trader) external view returns (struct ITradingStorage.Trade[])
```

*Returns all open trades/limit/stop orders for a trader*

### Parameters

| Name     | Type    | Description           |
| -------- | ------- | --------------------- |
| \_trader | address | address of the trader |

## getAllTradesForTraders

```solidity theme={null}
function getAllTradesForTraders(address[] _traders, uint256 _offset, uint256 _limit) external view returns (struct ITradingStorage.Trade[])
```

*Returns all trade/limit/stop orders using a pagination system*

### Parameters

| Name      | Type       | Description                          |
| --------- | ---------- | ------------------------------------ |
| \_traders | address\[] | list of traders to return trades for |
| \_offset  | uint256    | index of first trade to return       |
| \_limit   | uint256    | index of last trade to return        |

## getAllTrades

```solidity theme={null}
function getAllTrades(uint256 _offset, uint256 _limit) external view returns (struct ITradingStorage.Trade[])
```

*Returns all trade/limit/stop orders using a pagination system. Calls `getAllTradesForTraders` internally with all traders.*

### Parameters

| Name     | Type    | Description                    |
| -------- | ------- | ------------------------------ |
| \_offset | uint256 | index of first trade to return |
| \_limit  | uint256 | index of last trade to return  |

## getTradeInfo

```solidity theme={null}
function getTradeInfo(address _trader, uint32 _index) external view returns (struct ITradingStorage.TradeInfo)
```

*Returns trade info of an open trade/limit/stop order*

### Parameters

| Name     | Type    | Description                   |
| -------- | ------- | ----------------------------- |
| \_trader | address | address of the trader         |
| \_index  | uint32  | index of the trade for trader |

## getTradeInfos

```solidity theme={null}
function getTradeInfos(address _trader) external view returns (struct ITradingStorage.TradeInfo[])
```

*Returns all trade infos of open trade/limit/stop orders for a trader*

### Parameters

| Name     | Type    | Description           |
| -------- | ------- | --------------------- |
| \_trader | address | address of the trader |

## getAllTradeInfosForTraders

```solidity theme={null}
function getAllTradeInfosForTraders(address[] _traders, uint256 _offset, uint256 _limit) external view returns (struct ITradingStorage.TradeInfo[])
```

*Returns all trade infos of open trade/limit/stop orders using a pagination system*

### Parameters

| Name      | Type       | Description                             |
| --------- | ---------- | --------------------------------------- |
| \_traders | address\[] | list of traders to return tradeInfo for |
| \_offset  | uint256    | index of first tradeInfo to return      |
| \_limit   | uint256    | index of last tradeInfo to return       |

## getAllTradeInfos

```solidity theme={null}
function getAllTradeInfos(uint256 _offset, uint256 _limit) external view returns (struct ITradingStorage.TradeInfo[])
```

*Returns all trade infos of open trade/limit/stop orders using a pagination system. Calls `getAllTradeInfosForTraders` internally with all traders.*

### Parameters

| Name     | Type    | Description                        |
| -------- | ------- | ---------------------------------- |
| \_offset | uint256 | index of first tradeInfo to return |
| \_limit  | uint256 | index of last tradeInfo to return  |

## getPendingOrder

```solidity theme={null}
function getPendingOrder(struct ITradingStorage.Id _orderId) external view returns (struct ITradingStorage.PendingOrder)
```

*Returns a pending ordeer*

### Parameters

| Name      | Type                                                                                               | Description             |
| --------- | -------------------------------------------------------------------------------------------------- | ----------------------- |
| \_orderId | [ITradingStorage.Id](/developer/technical-reference/contracts/interfaces/types/itradingstorage#id) | id of the pending order |

## getPendingOrders

```solidity theme={null}
function getPendingOrders(address _user) external view returns (struct ITradingStorage.PendingOrder[])
```

*Returns all pending orders for a trader*

### Parameters

| Name   | Type    | Description           |
| ------ | ------- | --------------------- |
| \_user | address | address of the trader |

## getAllPendingOrdersForTraders

```solidity theme={null}
function getAllPendingOrdersForTraders(address[] _traders, uint256 _offset, uint256 _limit) external view returns (struct ITradingStorage.PendingOrder[])
```

*Returns all pending orders using a pagination system*

### Parameters

| Name      | Type       | Description                                |
| --------- | ---------- | ------------------------------------------ |
| \_traders | address\[] | list of traders to return pendingOrder for |
| \_offset  | uint256    | index of first pendingOrder to return      |
| \_limit   | uint256    | index of last pendingOrder to return       |

## getAllPendingOrders

```solidity theme={null}
function getAllPendingOrders(uint256 _offset, uint256 _limit) external view returns (struct ITradingStorage.PendingOrder[])
```

*Returns all pending orders using a pagination system Calls `getAllPendingOrdersForTraders` internally with all traders.*

### Parameters

| Name     | Type    | Description                           |
| -------- | ------- | ------------------------------------- |
| \_offset | uint256 | index of first pendingOrder to return |
| \_limit  | uint256 | index of last pendingOrder to return  |

## getTradePendingOrderBlock

```solidity theme={null}
function getTradePendingOrderBlock(struct ITradingStorage.Id _tradeId, enum ITradingStorage.PendingOrderType _orderType) external view returns (uint256)
```

*Returns the block number of the pending order for a trade (0 = doesn't exist)*

### Parameters

| Name        | Type                                                                                               | Description                 |
| ----------- | -------------------------------------------------------------------------------------------------- | --------------------------- |
| \_tradeId   | [ITradingStorage.Id](/developer/technical-reference/contracts/interfaces/types/itradingstorage#id) | id of the trade             |
| \_orderType | enum ITradingStorage.PendingOrderType                                                              | pending order type to check |

## getCounters

```solidity theme={null}
function getCounters(address _trader, enum ITradingStorage.CounterType _type) external view returns (struct ITradingStorage.Counter)
```

*Returns the counters of a trader (currentIndex / open count for trades/tradeInfos and pendingOrders mappings)*

### Parameters

| Name     | Type                             | Description                            |
| -------- | -------------------------------- | -------------------------------------- |
| \_trader | address                          | address of the trader                  |
| \_type   | enum ITradingStorage.CounterType | the counter type (trade/pending order) |

## getCountersForTraders

```solidity theme={null}
function getCountersForTraders(address[] _traders, enum ITradingStorage.CounterType _type) external view returns (struct ITradingStorage.Counter[])
```

*Returns the counters for a list of traders*

### Parameters

| Name      | Type                             | Description                            |
| --------- | -------------------------------- | -------------------------------------- |
| \_traders | address\[]                       | the list of traders                    |
| \_type    | enum ITradingStorage.CounterType | the counter type (trade/pending order) |

## getGToken

```solidity theme={null}
function getGToken(uint8 _collateralIndex) external view returns (address)
```

*Returns the address of the gToken for a collateral stack*

### Parameters

| Name              | Type  | Description                           |
| ----------------- | ----- | ------------------------------------- |
| \_collateralIndex | uint8 | the index of the supported collateral |

## getTradeLiquidationParams

```solidity theme={null}
function getTradeLiquidationParams(address _trader, uint32 _index) external view returns (struct IPairsStorage.GroupLiquidationParams)
```

*Returns the liquidation params for a trade*

### Parameters

| Name     | Type    | Description                   |
| -------- | ------- | ----------------------------- |
| \_trader | address | address of the trader         |
| \_index  | uint32  | index of the trade for trader |

## getTradesLiquidationParams

```solidity theme={null}
function getTradesLiquidationParams(address _trader) external view returns (struct IPairsStorage.GroupLiquidationParams[])
```

*Returns all trade liquidation params of open trade/limit/stop orders for a trader*

### Parameters

| Name     | Type    | Description           |
| -------- | ------- | --------------------- |
| \_trader | address | address of the trader |

## getAllTradesLiquidationParamsForTraders

```solidity theme={null}
function getAllTradesLiquidationParamsForTraders(address[] _traders, uint256 _offset, uint256 _limit) external view returns (struct IPairsStorage.GroupLiquidationParams[])
```

*Returns all trade liquidation params of open trade/limit/stop orders using a pagination system*

### Parameters

| Name      | Type       | Description                              |
| --------- | ---------- | ---------------------------------------- |
| \_traders | address\[] | list of traders to return liq params for |
| \_offset  | uint256    | index of first liq param to return       |
| \_limit   | uint256    | index of last liq param to return        |

## getAllTradesLiquidationParams

```solidity theme={null}
function getAllTradesLiquidationParams(uint256 _offset, uint256 _limit) external view returns (struct IPairsStorage.GroupLiquidationParams[])
```

*Returns all trade liquidation params of open trade/limit/stop orders using a pagination system Calls `getAllTradesLiquidationParamsForTraders` internally with all traders.*

### Parameters

| Name     | Type    | Description                        |
| -------- | ------- | ---------------------------------- |
| \_offset | uint256 | index of first liq param to return |
| \_limit  | uint256 | index of last liq param to return  |

## getCurrentContractsVersion

```solidity theme={null}
function getCurrentContractsVersion() external pure returns (enum ITradingStorage.ContractsVersion)
```

*Returns the current contracts version*

## TradingActivatedUpdated

```solidity theme={null}
event TradingActivatedUpdated(enum ITradingStorage.TradingActivated activated)
```

*Emitted when the trading activated state is updated*

### Parameters

| Name      | Type                                  | Description                     |
| --------- | ------------------------------------- | ------------------------------- |
| activated | enum ITradingStorage.TradingActivated | the new trading activated state |

## CollateralAdded

```solidity theme={null}
event CollateralAdded(address collateral, uint8 index, address gToken)
```

*Emitted when a new supported collateral is added*

### Parameters

| Name       | Type    | Description                           |
| ---------- | ------- | ------------------------------------- |
| collateral | address | the address of the collateral         |
| index      | uint8   | the index of the supported collateral |
| gToken     | address | the gToken contract of the collateral |

## CollateralUpdated

```solidity theme={null}
event CollateralUpdated(uint8 index, bool isActive)
```

*Emitted when an existing supported collateral active state is updated*

### Parameters

| Name     | Type  | Description                           |
| -------- | ----- | ------------------------------------- |
| index    | uint8 | the index of the supported collateral |
| isActive | bool  | the new active state                  |

## CollateralDisabled

```solidity theme={null}
event CollateralDisabled(uint8 index)
```

*Emitted when an existing supported collateral is disabled (can still close trades but not open new ones)*

### Parameters

| Name  | Type  | Description                           |
| ----- | ----- | ------------------------------------- |
| index | uint8 | the index of the supported collateral |

## GTokenUpdated

```solidity theme={null}
event GTokenUpdated(address collateral, uint8 index, address gToken)
```

*Emitted when the contracts of a supported collateral trading stack are updated*

### Parameters

| Name       | Type    | Description                           |
| ---------- | ------- | ------------------------------------- |
| collateral | address | the address of the collateral         |
| index      | uint8   | the index of the supported collateral |
| gToken     | address | the gToken contract of the collateral |

## TradeStored

```solidity theme={null}
event TradeStored(address user, uint32 index, struct ITradingStorage.Trade trade, struct ITradingStorage.TradeInfo tradeInfo, struct IPairsStorage.GroupLiquidationParams liquidationParams)
```

*Emitted when a new trade is stored*

### Parameters

| Name              | Type                                        | Description                         |
| ----------------- | ------------------------------------------- | ----------------------------------- |
| user              | address                                     | trade user                          |
| index             | uint32                                      | trade index                         |
| trade             | struct ITradingStorage.Trade                | the trade stored                    |
| tradeInfo         | struct ITradingStorage.TradeInfo            | the trade info stored               |
| liquidationParams | struct IPairsStorage.GroupLiquidationParams | the trade liquidation params stored |

## TradeMaxClosingSlippagePUpdated

```solidity theme={null}
event TradeMaxClosingSlippagePUpdated(address user, uint32 index, uint16 maxClosingSlippageP)
```

*Emitted when the max closing slippage % of an open trade is updated*

### Parameters

| Name                | Type    | Description                                      |
| ------------------- | ------- | ------------------------------------------------ |
| user                | address | trade user                                       |
| index               | uint32  | trade index                                      |
| maxClosingSlippageP | uint16  | new max closing slippage % value (1e3 precision) |

## TradeCollateralUpdated

```solidity theme={null}
event TradeCollateralUpdated(address user, uint32 index, uint120 collateralAmount)
```

*Emitted when an open trade collateral is updated*

### Parameters

| Name             | Type    | Description                                 |
| ---------------- | ------- | ------------------------------------------- |
| user             | address | trade user                                  |
| index            | uint32  | trade index                                 |
| collateralAmount | uint120 | new collateral value (collateral precision) |

## TradePositionUpdated

```solidity theme={null}
event TradePositionUpdated(address user, uint32 index, uint120 collateralAmount, uint24 leverage, uint64 openPrice, uint64 newTp, uint64 newSl, bool isPartialIncrease, bool isPnlPositive)
```

*Emitted when an open trade collateral is updated*

### Parameters

| Name              | Type    | Description                                                |
| ----------------- | ------- | ---------------------------------------------------------- |
| user              | address | trade user                                                 |
| index             | uint32  | trade index                                                |
| collateralAmount  | uint120 | new collateral value (collateral precision)                |
| leverage          | uint24  | new leverage value if present                              |
| openPrice         | uint64  | new open price value if present                            |
| newTp             | uint64  |                                                            |
| newSl             | uint64  |                                                            |
| isPartialIncrease | bool    | true if trade liquidation params were refreshed            |
| isPnlPositive     | bool    | true if trade pnl is positive (only relevant when closing) |

## OpenOrderDetailsUpdated

```solidity theme={null}
event OpenOrderDetailsUpdated(address user, uint32 index, uint64 openPrice, uint64 tp, uint64 sl, uint16 maxSlippageP)
```

*Emitted when an existing trade/limit order/stop order is updated*

### Parameters

| Name         | Type    | Description                    |
| ------------ | ------- | ------------------------------ |
| user         | address | trade user                     |
| index        | uint32  | trade index                    |
| openPrice    | uint64  | new open price value (1e10)    |
| tp           | uint64  | new take profit value (1e10)   |
| sl           | uint64  | new stop loss value (1e10)     |
| maxSlippageP | uint16  | new max slippage % value (1e3) |

## TradeTpUpdated

```solidity theme={null}
event TradeTpUpdated(address user, uint32 index, uint64 newTp)
```

*Emitted when the take profit of an open trade is updated*

### Parameters

| Name  | Type    | Description                          |
| ----- | ------- | ------------------------------------ |
| user  | address | trade user                           |
| index | uint32  | trade index                          |
| newTp | uint64  | the new take profit (1e10 precision) |

## TradeSlUpdated

```solidity theme={null}
event TradeSlUpdated(address user, uint32 index, uint64 newSl)
```

*Emitted when the stop loss of an open trade is updated*

### Parameters

| Name  | Type    | Description                 |
| ----- | ------- | --------------------------- |
| user  | address | trade user                  |
| index | uint32  | trade index                 |
| newSl | uint64  | the new sl (1e10 precision) |

## TradeClosed

```solidity theme={null}
event TradeClosed(address user, uint32 index, bool isPnlPositive)
```

*Emitted when an open trade is closed*

### Parameters

| Name          | Type    | Description                   |
| ------------- | ------- | ----------------------------- |
| user          | address | trade user                    |
| index         | uint32  | trade index                   |
| isPnlPositive | bool    | true if trade pnl is positive |

## PendingOrderStored

```solidity theme={null}
event PendingOrderStored(struct ITradingStorage.PendingOrder pendingOrder)
```

*Emitted when a new pending order is stored*

### Parameters

| Name         | Type                                | Description              |
| ------------ | ----------------------------------- | ------------------------ |
| pendingOrder | struct ITradingStorage.PendingOrder | the pending order stored |

## PendingOrderClosed

```solidity theme={null}
event PendingOrderClosed(struct ITradingStorage.Id orderId)
```

*Emitted when a pending order is closed*

### Parameters

| Name    | Type                      | Description                        |
| ------- | ------------------------- | ---------------------------------- |
| orderId | struct ITradingStorage.Id | the id of the pending order closed |

## MissingCollaterals

```solidity theme={null}
error MissingCollaterals()
```

## CollateralAlreadyActive

```solidity theme={null}
error CollateralAlreadyActive()
```

## CollateralAlreadyDisabled

```solidity theme={null}
error CollateralAlreadyDisabled()
```

## TradePositionSizeZero

```solidity theme={null}
error TradePositionSizeZero()
```

## TradeOpenPriceZero

```solidity theme={null}
error TradeOpenPriceZero()
```

## TradePairNotListed

```solidity theme={null}
error TradePairNotListed()
```

## TradeTpInvalid

```solidity theme={null}
error TradeTpInvalid()
```

## TradeSlInvalid

```solidity theme={null}
error TradeSlInvalid()
```

## MaxSlippageZero

```solidity theme={null}
error MaxSlippageZero()
```

## TradeInfoCollateralPriceUsdZero

```solidity theme={null}
error TradeInfoCollateralPriceUsdZero()
```
