> For the complete documentation index, see [llms.txt](https://docs.gammaswap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gammaswap.com/developers/concepts/order-side-and-time-in-force.md).

# Order Side & Time in Force

### Order side

The `side` field is a boolean.

| Value   | Direction |
| ------- | --------- |
| `false` | Buy/Up    |
| `true`  | Sell/Down |

Buy order:

```ts
await exchange.placeOrder({
  assetId,
  epoch,
  side: false,
  price: "99.9",
  size: "10.25",
});
```

Sell order:

```ts
await exchange.placeOrder({
  assetId,
  epoch,
  side: true,
  price: "99.9",
  size: "10.25",
});
```

### Time in force

Time in force controls how an order behaves when it reaches the order book.

<table><thead><tr><th width="90.5052490234375" align="right">Value</th><th width="161.80731201171875">Constant</th><th width="178.606689453125">Name</th><th>Behavior</th></tr></thead><tbody><tr><td align="right"><code>0</code></td><td><code>TimeInForce.GTC</code></td><td>Good until cancelled</td><td>Any unfilled quantity remains open</td></tr><tr><td align="right"><code>1</code></td><td><code>TimeInForce.FOK</code></td><td>Fill or kill</td><td>The entire order must fill immediately or be cancelled</td></tr><tr><td align="right"><code>2</code></td><td><code>TimeInForce.IOC</code></td><td>Immediate or cancel</td><td>Available quantity fills immediately; the remainder is cancelled</td></tr><tr><td align="right"><code>3</code></td><td><code>TimeInForce.ALO</code></td><td>Add liquidity only</td><td>The order may only add liquidity</td></tr></tbody></table>

Import the constants from the SDK:

```ts
import {
  TimeInForce,
} from "@gammaswap/v2-exchange-sdk/constants";
```

### Good until cancelled

GTC is the default.

```ts
await exchange.placeOrder({
  assetId,
  epoch,
  side: false,
  price: "99.9",
  size: "10.25",
  timeInForce: TimeInForce.GTC,
});
```

Since GTC is the default, it can be omitted:

```ts
await exchange.placeOrder({
  assetId,
  epoch,
  side: false,
  price: "99.9",
  size: "10.25",
});
```

### Fill or kill

A FOK order must fill completely. If the full requested size is unavailable, the order is cancelled.

```ts
await exchange.placeOrder({
  assetId,
  epoch,
  side: false,
  price: "99.9",
  size: "10.25",
  timeInForce: TimeInForce.FOK,
});
```

### Immediate or cancel

An IOC order fills as much as possible immediately and cancels any remaining quantity.

```ts
await exchange.placeOrder({
  assetId,
  epoch,
  side: false,
  price: "99.9",
  size: "10.25",
  timeInForce: TimeInForce.IOC,
});
```

### Add liquidity only

An ALO order may only add liquidity to the order book.

```ts
await exchange.placeOrder({
  assetId,
  epoch,
  side: false,
  price: "99.9",
  size: "10.25",
  timeInForce: TimeInForce.ALO,
});
```

If the order would immediately match existing liquidity, it is rejected or cancelled with an `ALO` reason.

### Cancel and replace

For a cancel-and-replace request:

* The replacement order must use the same market as the cancelled order.
* The replacement side must match the side of the cancelled order.
* The order hash being cancelled cannot be the zero hash.
* Cancel-all behavior is not supported by cancel-and-replace.

```ts
await exchange.cancelReplaceOrder({
  assetId,
  epoch,
  cancelOrderHash: existingOrderId,
  side: false,
  price: "99.8",
  size: "10.25",
  timeInForce: TimeInForce.GTC,
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.gammaswap.com/developers/concepts/order-side-and-time-in-force.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
