# GNSTradingCallbacks

*Facet #8: Callbacks (to execute actions after receiving median price from price aggregator)*

## constructor

```solidity
constructor() public
```

## initializeCallbacks

```solidity
function initializeCallbacks(uint8 _vaultClosingFeeP) external
```

### Parameters

| Name               | Type  | Description                         |
| ------------------ | ----- | ----------------------------------- |
| \_vaultClosingFeeP | uint8 | the % of closing fee going to vault |

## initializeTreasuryAddress

```solidity
function initializeTreasuryAddress(address _treasury) external
```

*Initialize the treasury address*

### Parameters

| Name       | Type    | Description          |
| ---------- | ------- | -------------------- |
| \_treasury | address | the treasury address |

## updateVaultClosingFeeP

```solidity
function updateVaultClosingFeeP(uint8 _valueP) external
```

*Update the % of closing fee going to vault*

### Parameters

| Name     | Type  | Description                         |
| -------- | ----- | ----------------------------------- |
| \_valueP | uint8 | the % of closing fee going to vault |

## updateTreasuryAddress

```solidity
function updateTreasuryAddress(address _treasury) external
```

*Updates the treasury address*

### Parameters

| Name       | Type    | Description              |
| ---------- | ------- | ------------------------ |
| \_treasury | address | the new treasury address |

## claimPendingGovFees

```solidity
function claimPendingGovFees() external
```

*Claim the pending gov fees for all collaterals*

## openTradeMarketCallback

```solidity
function openTradeMarketCallback(struct ITradingCallbacks.AggregatorAnswer _a) external virtual
```

*Executes a pending open trade market order*

### Parameters

| Name | Type                                                                                                                                             | Description                                         |
| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------- |
| \_a  | [ITradingCallbacks.AggregatorAnswer](https://docs.gains.trade/developer/technical-reference/interfaces/types/itradingcallbacks#aggregatoranswer) | the price aggregator answer (order id, price, etc.) |

## closeTradeMarketCallback

```solidity
function closeTradeMarketCallback(struct ITradingCallbacks.AggregatorAnswer _a) external virtual
```

*Executes a pending close trade market order*

### Parameters

| Name | Type                                                                                                                                             | Description                                         |
| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------- |
| \_a  | [ITradingCallbacks.AggregatorAnswer](https://docs.gains.trade/developer/technical-reference/interfaces/types/itradingcallbacks#aggregatoranswer) | the price aggregator answer (order id, price, etc.) |

## executeTriggerOpenOrderCallback

```solidity
function executeTriggerOpenOrderCallback(struct ITradingCallbacks.AggregatorAnswer _a) external virtual
```

*Executes a pending open trigger order (for limit/stop orders)*

### Parameters

| Name | Type                                                                                                                                             | Description                                         |
| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------- |
| \_a  | [ITradingCallbacks.AggregatorAnswer](https://docs.gains.trade/developer/technical-reference/interfaces/types/itradingcallbacks#aggregatoranswer) | the price aggregator answer (order id, price, etc.) |

## executeTriggerCloseOrderCallback

```solidity
function executeTriggerCloseOrderCallback(struct ITradingCallbacks.AggregatorAnswer _a) external virtual
```

*Executes a pending close trigger order (for tp/sl/liq orders)*

### Parameters

| Name | Type                                                                                                                                             | Description                                         |
| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------- |
| \_a  | [ITradingCallbacks.AggregatorAnswer](https://docs.gains.trade/developer/technical-reference/interfaces/types/itradingcallbacks#aggregatoranswer) | the price aggregator answer (order id, price, etc.) |

## getVaultClosingFeeP

```solidity
function getVaultClosingFeeP() external view returns (uint8)
```

*Returns the current vaultClosingFeeP value (%)*

## getPendingGovFeesCollateral

```solidity
function getPendingGovFeesCollateral(uint8 _collateralIndex) external view returns (uint256)
```

*Returns the current pending gov fees for a collateral index (collateral precision)*

## updateLeverageCallback

```solidity
function updateLeverageCallback(struct ITradingCallbacks.AggregatorAnswer _a) external virtual
```

*Executes a pending update leverage order*

### Parameters

| Name | Type                                                                                                                                             | Description                                         |
| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------- |
| \_a  | [ITradingCallbacks.AggregatorAnswer](https://docs.gains.trade/developer/technical-reference/interfaces/types/itradingcallbacks#aggregatoranswer) | the price aggregator answer (order id, price, etc.) |

## increasePositionSizeMarketCallback

```solidity
function increasePositionSizeMarketCallback(struct ITradingCallbacks.AggregatorAnswer _a) external virtual
```

*Executes a pending increase position size market order*

### Parameters

| Name | Type                                                                                                                                             | Description                                         |
| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------- |
| \_a  | [ITradingCallbacks.AggregatorAnswer](https://docs.gains.trade/developer/technical-reference/interfaces/types/itradingcallbacks#aggregatoranswer) | the price aggregator answer (order id, price, etc.) |

## decreasePositionSizeMarketCallback

```solidity
function decreasePositionSizeMarketCallback(struct ITradingCallbacks.AggregatorAnswer _a) external virtual
```

*Executes a pending decrease position size market order*

### Parameters

| Name | Type                                                                                                                                             | Description                                         |
| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------- |
| \_a  | [ITradingCallbacks.AggregatorAnswer](https://docs.gains.trade/developer/technical-reference/interfaces/types/itradingcallbacks#aggregatoranswer) | the price aggregator answer (order id, price, etc.) |

## validateTriggerOpenOrderCallback

```solidity
function validateTriggerOpenOrderCallback(struct ITradingStorage.Id _tradeId, enum ITradingStorage.PendingOrderType _orderType, uint64 _open, uint64 _high, uint64 _low) external view returns (struct ITradingStorage.Trade t, enum ITradingCallbacks.CancelReason cancelReason, struct ITradingCallbacks.Values v)
```

*Makes open trigger (STOP/LIMIT) checks like slippage, price impact, missed targets and returns cancellation reason if any*

### Parameters

| Name        | Type                                                                                                             | Description                                |
| ----------- | ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| \_tradeId   | [ITradingStorage.Id](https://docs.gains.trade/developer/technical-reference/interfaces/types/itradingstorage#id) | the id of the trade                        |
| \_orderType | enum ITradingStorage.PendingOrderType                                                                            | the pending order type                     |
| \_open      | uint64                                                                                                           | the `open` value from an aggregator answer |
| \_high      | uint64                                                                                                           | the `high` value from an aggregator answer |
| \_low       | uint64                                                                                                           | the `low` value from an aggregator answer  |

## validateTriggerCloseOrderCallback

```solidity
function validateTriggerCloseOrderCallback(struct ITradingStorage.Id _tradeId, enum ITradingStorage.PendingOrderType _orderType, uint64 _open, uint64 _high, uint64 _low) external view returns (struct ITradingStorage.Trade t, enum ITradingCallbacks.CancelReason cancelReason, struct ITradingCallbacks.Values v)
```

*Makes close trigger (SL/TP/LIQ) checks like slippage and price impact and returns cancellation reason if any*

### Parameters

| Name        | Type                                                                                                             | Description                                |
| ----------- | ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| \_tradeId   | [ITradingStorage.Id](https://docs.gains.trade/developer/technical-reference/interfaces/types/itradingstorage#id) | the id of the trade                        |
| \_orderType | enum ITradingStorage.PendingOrderType                                                                            | the pending order type                     |
| \_open      | uint64                                                                                                           | the `open` value from an aggregator answer |
| \_high      | uint64                                                                                                           | the `high` value from an aggregator answer |
| \_low       | uint64                                                                                                           | the `low` value from an aggregator answer  |
