# UpdatePositionSizeLifecycles

*This is an external library for position size updates lifecycles Used by GNSTrading and GNSTradingCallbacks facets*

## requestIncreasePositionSize

```solidity
function requestIncreasePositionSize(struct IUpdatePositionSize.IncreasePositionSizeInput _input) external
```

*Initiate increase position size order, done in 2 steps because position size changes*

### Parameters

| Name    | Type                                                                                                                                                        | Description                                 |
| ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- |
| \_input | [IUpdatePositionSize.IncreasePositionSizeInput](/developer/technical-reference/contracts/interfaces/types/iupdatepositionsize.md#increasepositionsizeinput) | request increase position size input struct |

## requestDecreasePositionSize

```solidity
function requestDecreasePositionSize(struct IUpdatePositionSize.DecreasePositionSizeInput _input) external
```

*Initiate decrease position size order, done in 2 steps because position size changes*

### Parameters

| Name    | Type                                                                                                                                                        | Description                                 |
| ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- |
| \_input | [IUpdatePositionSize.DecreasePositionSizeInput](/developer/technical-reference/contracts/interfaces/types/iupdatepositionsize.md#decreasepositionsizeinput) | request decrease position size input struct |

## executeIncreasePositionSizeMarket

```solidity
function executeIncreasePositionSizeMarket(struct ITradingStorage.PendingOrder _order, struct ITradingCallbacks.AggregatorAnswer _answer) external
```

*Execute increase position size market callback*

### Parameters

| Name     | Type                                                                                                                                  | Description                 |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
| \_order  | [ITradingStorage.PendingOrder](/developer/technical-reference/contracts/interfaces/types/itradingstorage.md#pendingorder)             | corresponding pending order |
| \_answer | [ITradingCallbacks.AggregatorAnswer](/developer/technical-reference/contracts/interfaces/types/itradingcallbacks.md#aggregatoranswer) | price aggregator answer     |

## executeDecreasePositionSizeMarket

```solidity
function executeDecreasePositionSizeMarket(struct ITradingStorage.PendingOrder _order, struct ITradingCallbacks.AggregatorAnswer _answer) external
```

*Execute decrease position size market callback*

### Parameters

| Name     | Type                                                                                                                                  | Description                 |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
| \_order  | [ITradingStorage.PendingOrder](/developer/technical-reference/contracts/interfaces/types/itradingstorage.md#pendingorder)             | corresponding pending order |
| \_answer | [ITradingCallbacks.AggregatorAnswer](/developer/technical-reference/contracts/interfaces/types/itradingcallbacks.md#aggregatoranswer) | price aggregator answer     |

## \_getMultiCollatDiamond

```solidity
function _getMultiCollatDiamond() internal view returns (contract IGNSMultiCollatDiamond)
```

*Returns current address as multi-collateral diamond interface to call other facets functions.*

## \_baseValidateRequest

```solidity
function _baseValidateRequest(address _trader, uint32 _index) internal view returns (struct ITradingStorage.Trade trade)
```

*Basic validation for increase/decrease position size request*

### Parameters

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

## \_initiateRequest

```solidity
function _initiateRequest(struct ITradingStorage.Trade _trade, bool _isIncrease, uint120 _collateralAmount, uint24 _leverage, uint256 _positionSizeCollateralDelta, uint64 _expectedPrice, uint16 _maxSlippageP) internal returns (struct ITradingStorage.Id orderId)
```

*Creates pending order, makes price aggregator request, and returns corresponding pending order id*

### Parameters

| Name                          | Type                                                                                                        | Description                                                                           |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
| \_trade                       | [ITradingStorage.Trade](/developer/technical-reference/contracts/interfaces/types/itradingstorage.md#trade) | trade to update                                                                       |
| \_isIncrease                  | bool                                                                                                        | whether is increase or decrease position size order                                   |
| \_collateralAmount            | uint120                                                                                                     | partial trade collateral amount (collateral precision)                                |
| \_leverage                    | uint24                                                                                                      | partial trade leverage (1e3)                                                          |
| \_positionSizeCollateralDelta | uint256                                                                                                     | position size delta in collateral tokens (collateral precision)                       |
| \_expectedPrice               | uint64                                                                                                      | reference price for max slippage check (1e10), only useful for increase position size |
| \_maxSlippageP                | uint16                                                                                                      | max slippage % (1e3), only useful for increase position size                          |

## \_validateBaseFulfillment

```solidity
function _validateBaseFulfillment(struct ITradingStorage.Trade _trade, struct ITradingCallbacks.AggregatorAnswer _answer) internal pure returns (enum ITradingCallbacks.CancelReason)
```

*Basic validation for callbacks, returns corresponding cancel reason*

### Parameters

| Name     | Type                                                                                                                                  | Description            |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- |
| \_trade  | [ITradingStorage.Trade](/developer/technical-reference/contracts/interfaces/types/itradingstorage.md#trade)                           | trade struct           |
| \_answer | [ITradingCallbacks.AggregatorAnswer](/developer/technical-reference/contracts/interfaces/types/itradingcallbacks.md#aggregatoranswer) | price aggegator answer |


---

# 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/libraries/updatepositionsize/updatepositionsizelifecycles.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.
