> ## 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.

# Trading Contracts

> How to interact with Gains trading contracts.

<Info>
  To interact with trading contracts, call the relevant methods on the `GNSMultiCollatDiamond` contract. Each facet method can be accessed through this central contract. Network-specific `GNSMultiCollatDiamond` addresses are listed on the [Active Contracts page](/what-is-gains-network/contract-addresses#active-contracts).
</Info>

## Addresses

For the latest addresses, see [Contract Addresses](/what-is-gains-network/contract-addresses#active-contracts).

If you are using testnet, the [Arbitrum Sepolia address](https://louper.dev/diamond/0xd659a15812064C79E189fd950A189b15c75d3186?network=arbitrumSepolia) for `GNSMultiCollatDiamond` is `0xd659a15812064C79E189fd950A189b15c75d3186`.

## Interactions

Below is a list of available actions, consisting of market & limit orders, as well as updates. Where possible, NatSpec documentation is linked to. For full reference, see the [ITradingInteractionsUtils](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils) natspec.

* Place a trade\*
* Place a limit order
* Update a trade
* Update a limit order
* Cancel a limit order
* Close a trade\*
* Update leverage (decrease/increase)
* Increase position size
* Decrease position size

\**Requires order fulfillment. Integrators make requests, and oracles fulfill them.*

### Place a Trade

Place a trade using the following functions. Use tradeType = 0.

[`openTrade`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#opentrade)

[`openTradeNative`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#opentradenative)

If an order hasn't been fulfilled in 60 seconds, collateral can be claimed back using the timeout function:

[`cancelOrderAfterTimeout`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#cancelorderaftertimeout)

### Place a Limit Order

Same as market order, but provided tradeType of 1 or 2.

\
**Limit**: To be used when you want to go long at a lower price than present, or to go short if the price reaches a higher price than present. Executes at exact price set if price reaches threshold + spread.

**Stop:** To be used when you want to go long if the price reaches a higher price than present, or to go short if the price reaches a lower price than present. You might want to use this to long a breakout, or short a breakdown. The execution price is the current market price + spread.

### Update Active Trade

Supports updating take profit (TP) and stop loss (SL).

[`updateSl`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#updatesl)

[`updateTp`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#updatetp)

### Update Pending Limit Order

If a limit order hasn't been fulfilled yet, it can be updated

[`updateOpenOrder`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#updateopenorder)

### Cancel Pending Limit Order

If a limit order hasn't been fulfilled yet, it can be canceled

[`cancelOpenOrder`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#cancelopenorder)

### Close a Trade

Market close a trade

[`closeTradeMarket`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#closetrademarket)

If the trade hasn't been closed in 60 seconds, a timeout may be initiated, allowing for another close attempt:

[`cancelOrderAfterTimeout`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#cancelorderaftertimeout)

### Update Leverage

Update leverage for a trade

[`updateLeverage`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#updateleverage)

### Update Position Size

Decrease position size (by decreasing collateral amount or leverage)

[`decreasePositionSize`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#decreasepositionsize)

Increase position size (by increasing collateral amount or leverage or both)

[`increasePositionSize`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#increasepositionsize)

## Events

Events are emitted to allow off-chain services to stay updated. You can subscribe to these directly, or review the [Backend](/developer/integrators/backend) page for instructions on receiving events from a WebSocket stream. We recommend using the backend.

**Core Events**

For opening or closing a trade: `MarketOrderInitiated` -> `MarketExecuted`

For placing a limit order: `OpenOrderPlaced`

For updating a trade: `TradeSlUpdated` or `TradeTpUpdated`

For fulfilling a limit order (SL, TP, Open limit): `LimitExecuted`

For updating leverage: `LeverageUpdateInitiated`-> `LeverageUpdateExecuted`

For  updating position size (increase): `PositionSizeUpdateInitiated`-> `PositionSizeIncreaseExecuted`

For  updating position size (decrease): `PositionSizeUpdateInitiated`-> `PositionSizeDeccreaseExecuted`

**All Lifecycle Events**

[`MarketOrderInitiated`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#marketorderinitiated)

[`TriggerOrderInitiated`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#triggerorderinitiated)

[`OpenLimitUpdated`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#openlimitupdated)

[`OpenLimitCanceled`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#openlimitcanceled)

[`ChainlinkCallbackTimeout`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#chainlinkcallbacktimeout)

[`OpenOrderPlaced`](/developer/technical-reference/contracts/interfaces/libraries/itradinginteractionsutils#openorderplaced)

[`TradeSlUpdated`](/developer/technical-reference/contracts/interfaces/libraries/itradingstorageutils#tradeslupdated)

[`TradeTpUpdated`](/developer/technical-reference/contracts/interfaces/libraries/itradingstorageutils#tradetpupdated)

[`MarketExecuted`](/developer/technical-reference/contracts/interfaces/libraries/itradingcallbacksutils#marketexecuted)

[`LimitExecuted`](/developer/technical-reference/contracts/interfaces/libraries/itradingcallbacksutils#limitexecuted)

[`LeverageUpdateInitiated`](/developer/technical-reference/contracts/interfaces/libraries/iupdateleverageutils#leverageupdateinitiated)

[`PositionSizeUpdateInitiated`](/developer/technical-reference/contracts/interfaces/libraries/iupdatepositionsizeutils#positionsizeupdateinitiated)

[`LeverageUpdateExecuted`](/developer/technical-reference/contracts/interfaces/libraries/iupdateleverageutils#leverageupdateexecuted)

[`PositionSizeDecreaseExecuted`](/developer/technical-reference/contracts/interfaces/libraries/iupdatepositionsizeutils#positionsizedecreaseexecuted)

[`PositionSizeIncreaseExecuted`](/developer/technical-reference/contracts/interfaces/libraries/iupdatepositionsizeutils#positionsizeincreaseexecuted)
