# ITradingStorage

*Contains the types for the GNSTradingStorage facet*

## TradingStorage

```solidity
struct TradingStorage {
  enum ITradingStorage.TradingActivated tradingActivated;
  uint8 lastCollateralIndex;
  uint240 __placeholder;
  mapping(uint8 => struct ITradingStorage.Collateral) collaterals;
  mapping(uint8 => address) gTokens;
  mapping(address => uint8) collateralIndex;
  mapping(address => mapping(uint32 => struct ITradingStorage.Trade)) trades;
  mapping(address => mapping(uint32 => struct ITradingStorage.TradeInfo)) tradeInfos;
  mapping(address => mapping(uint32 => mapping(enum ITradingStorage.PendingOrderType => uint256))) tradePendingOrderBlock;
  mapping(address => mapping(uint32 => struct ITradingStorage.PendingOrder)) pendingOrders;
  mapping(address => mapping(enum ITradingStorage.CounterType => struct ITradingStorage.Counter)) userCounters;
  address[] traders;
  mapping(address => bool) traderStored;
  mapping(address => mapping(uint32 => struct IPairsStorage.GroupLiquidationParams)) tradeLiquidationParams;
  uint256[38] __gap;
}
```

## PendingOrderType

```solidity
enum PendingOrderType {
  MARKET_OPEN,
  MARKET_CLOSE,
  LIMIT_OPEN,
  STOP_OPEN,
  TP_CLOSE,
  SL_CLOSE,
  LIQ_CLOSE,
  UPDATE_LEVERAGE,
  MARKET_PARTIAL_OPEN,
  MARKET_PARTIAL_CLOSE
}
```

## CounterType

```solidity
enum CounterType {
  TRADE,
  PENDING_ORDER
}
```

## TradeType

```solidity
enum TradeType {
  TRADE,
  LIMIT,
  STOP
}
```

## TradingActivated

```solidity
enum TradingActivated {
  ACTIVATED,
  CLOSE_ONLY,
  PAUSED
}
```

## ContractsVersion

```solidity
enum ContractsVersion {
  BEFORE_V9_2,
  V9_2
}
```

## Collateral

```solidity
struct Collateral {
  address collateral;
  bool isActive;
  uint88 __placeholder;
  uint128 precision;
  uint128 precisionDelta;
}
```

## Id

```solidity
struct Id {
  address user;
  uint32 index;
}
```

## Trade

```solidity
    struct Trade {
        address user; // 160 bits
        uint32 index; // max: 4,294,967,295
        uint16 pairIndex; // max: 65,535
        uint24 leverage; // 1e3; max: 16,777.215
        bool long; // 8 bits
        bool isOpen; // 8 bits
        uint8 collateralIndex; // max: 255
        TradeType tradeType; // 8 bits
        uint120 collateralAmount; // collateral precision; max: 3.402e+38
        uint64 openPrice; // 1e10; max: 1.8e19
        uint64 tp; // 1e10; max: 1.8e19
        uint64 sl; // 1e10; max: 1.8e19
        bool isCounterTrade;
        uint160 positionSizeToken; // 1e18, assuming 1e-9 collateral price, 1e-9 pair price => max value is 1.46 trillion USD (1e12)
        uint24 __placeholder;
    }
```

## TradeInfo

```solidity
struct TradeInfo {
  uint32 createdBlock;
  uint32 tpLastUpdatedBlock;
  uint32 slLastUpdatedBlock;
  uint16 maxSlippageP;
  uint48 lastOiUpdateTs;
  uint48 collateralPriceUsd;
  enum ITradingStorage.ContractsVersion contractsVersion;
  uint32 lastPosIncreaseBlock;
  uint8 __placeholder;
}
```

## PendingOrder

```solidity
struct PendingOrder {
  struct ITradingStorage.Trade trade;
  address user;
  uint32 index;
  bool isOpen;
  enum ITradingStorage.PendingOrderType orderType;
  uint32 createdBlock;
  uint16 maxSlippageP;
}
```

## Counter

```solidity
struct Counter {
  uint32 currentIndex;
  uint32 openCount;
  uint192 __placeholder;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gains.trade/developer/technical-reference/contracts/interfaces/types/itradingstorage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
