> For the complete documentation index, see [llms.txt](https://docs.symm.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.symm.io/trader-documentation/building-a-trading-bot/part-2-trading.md).

# Part 2: trading

## Part 2: Trading

From here every action is signed by your session key, submitted through the SDK to the Enigma solver, and confirmed over the notifications WebSocket. You never prompt the Owner wallet again.

### Load markets and stream prices

```typescript
import { getMarkets, watchEnigmaPrices } from "@symmio/trading-core";

const markets = await getMarkets(config);

const unwatch = watchEnigmaPrices(config, {
  onPrices: (ticks) => {
    for (const tick of ticks) {
      // tick.name is the price-service symbol name — NOT the display symbol
      console.log(tick.name, tick.markPrice, tick.time);
    }
  },
  onStatusChange: (s) => console.log("price stream:", s),
  onError: (e) => console.error(e),
});
```

> Enigma is both your solver and your price feed on HyperEVM. Prices key on `SymbolContractSymbol.name`, which can differ from the display symbol. Pass `market.name` (not the ticker) when you open, or mark-price lookups fail silently.

### Open a position

`instantOpenAuto` is the one-call orchestrator: it prepares parameters and submits in a single step. Internally it resolves the trade into an `InstantOpenParameters` bag (`requestedOpenPrice`, `quantity`, `cva`, `lf`, `partyAmm`, `partyBmm`, `notional`, `addMargin`, all 18-decimal `bigint`), signs it EIP-712, and POSTs it to the Enigma solver at `https://solver.enigma.bz/api/instant_trade/instant_open`. You never hand-build that body; you just pass the inputs below.

```typescript
import { instantOpenAuto, PositionType } from "@symmio/trading-core";

const { tempQuoteId } = await instantOpenAuto(config, {
  from: sessionKey,
  subAccountAddress: subAccount,
  market: { id: 1 },            // use the id/name from getMarkets
  positionType: PositionType.LONG,
  initialMargin: "100",         // in USDC
  leverage: 5,
  slippage: 1,                  // percent
});
```

The call returns a negative `tempQuoteId`, a placeholder the solver issues until the trade anchors on-chain.

### Confirm the fill

The open is two-phase. Watch notifications for the on-chain `quoteId`, then reconcile it against your optimistic `tempQuoteId` record.

```typescript
import { watchNotifications, reconcileQuotes } from "@symmio/trading-core";

watchNotifications(config, {
  onNotification: (n) => {
    // when a SendQuoteTransaction arrives, the real on-chain quoteId is known
    reconcileQuotes(/* merge tempQuoteId -> quoteId in your store */);
  },
});
```

### Attach take-profit / stop-loss

Set TP/SL against the Virtual Account for the position (the SDK resolves the predicted VA for you). Confirm via the TP/SL notification stream, not the POST response.

```typescript
import { setQuoteTpSl } from "@symmio/trading-core";

await setQuoteTpSl(config, {
  from: sessionKey,
  quoteId,                                         // the on-chain id from reconcile
  tp: { triggerPrice: "150", priceType: "markPrice" },
  sl: { triggerPrice: "90",  priceType: "markPrice" },
});
```

### Close a position

Close against the on-chain `quoteId`. `instantCloseAuto` handles the whole flow, and `quantityToClose` lets you close partially.

```typescript
import { instantCloseAuto, PositionType } from "@symmio/trading-core";

await instantCloseAuto(config, {
  from: sessionKey,
  partyA: subAccount,
  market: { id: 1 },
  positionType: PositionType.LONG,
  quoteId,
  quantityToClose: "0.5",   // omit / full size to close entirely
  slippage: 1,
});
```

That's the full loop: stream prices, open, confirm, manage with TP/SL, close. For headless bots this is all of `@symmio/trading-core`. For a UI, the same steps have React hooks (`useInstantOpenAuto`, `useInstantCloseAuto`, `useSetQuoteTpSl`, `useManagedQuotes`).


---

# 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.symm.io/trader-documentation/building-a-trading-bot/part-2-trading.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.
