# Trading Contracts

{% hint style="info" %}
To interact with trading contracts, you should call the respective methods on the `GNSMultiCollatDiamond` contract. Each method within the facets can be accessed through this central contract, ensuring a streamlined approach to contract interactions. You can find network-specific `GNSMultiCollatDiamond` address in [Active Contracts page](https://gains-network.gitbook.io/docs-home/what-is-gains-network/contract-addresses#active-contracts)
{% endhint %}

## Addresses

For latest addresses, refer to:\
[Contract Addresses](/what-is-gains-network/contract-addresses.md#active-contracts)

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

## 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 [Technical Reference](/developer/technical-reference.md).

* Place a trade\*
* Place a limit order
* Update a trade
* Update a limit order
* Cancel a limit order
* Close a trade\*&#x20;
* 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.&#x20;

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#opentrade)

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#opentradenative)

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

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#opentrademarkettimeout)

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

Support updating take profit (TP) and stop loss (SL).&#x20;

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#updatesl)

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#updatetp)

### Update Pending Limit Order

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

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#updateopenorder)&#x20;

### Cancel Pending Limit Order

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

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#cancelopenorder)

### Close a Trade

Market close a trade

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#closetrademarket)

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

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#closetrademarkettimeout)

### Update Leverage

Update leverage for a trade

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#updateleverage)

### Update Position Size

Decrease position size (by decreasing collateral amount or leverage)

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#decreasepositionsize)

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

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#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.md)page for instructions on receiving from a WebSocket stream. It is recommended to use 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**

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#marketorderinitiated)&#x20;

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#triggerorderinitiated)

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#openlimitupdated)

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#openlimitcanceled)

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#chainlinkcallbacktimeout)

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#openorderplaced)

[Broken mention](broken://pages/LtzqEsvptX8Ou8ITxiuV#tradeslupdated)

[Broken mention](broken://pages/LtzqEsvptX8Ou8ITxiuV#tradetpupdated)

[Broken mention](broken://pages/6vrt4TuSolyaAcxCAXhz#marketexecuted)

[Broken mention](broken://pages/6vrt4TuSolyaAcxCAXhz#limitexecuted)

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#leverageupdateinitiated)

[Broken mention](broken://pages/cchSai4zOamX0UXoCWyw#positionsizeupdateinitiated)

[Broken mention](broken://pages/6vrt4TuSolyaAcxCAXhz#leverageupdateexecuted)

[Broken mention](broken://pages/6vrt4TuSolyaAcxCAXhz#positionsizedecreaseexecuted)

[Broken mention](broken://pages/6vrt4TuSolyaAcxCAXhz#positionsizeincreaseexecuted)


---

# 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/integrators/trading-contracts.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.
