Skip to main content

Open Position

Overview

This documentation will guide you through the process of opening a new position when trading on the Chromatic Protocol.

Prerequisites

Before opening a position, ensure that you have completed the following steps:

  • Set up the Chromatic Protocol SDK by following the installation instructions.
  • Create an account using the SDK, as account creation is required before trading. Refer to the "Create an Account" section for more information.

Opening a New Position

To open a new position on the Chromatic Protocol, use the openPosition method provided by the ChromaticRouter instance. This method allows you to specify the market address, leverage, taker margin, maker margin, and maximum allowable trading fee.

import { Client } from "@chromatic-protocol/sdk-ethers-v5"

const client: Client = ... // Replace with your instantiated Client object

const marketAddress: string = ... // Replace with the address of the market you want to trade on
const leverage: number = ... // Specify the leverage for the position
const takerMargin: string = ... // Specify the taker margin amount
const makerMargin: string = ... // Specify the maker margin amount
const maxAllowableTradingFee: string = ... // Specify the maximum allowable trading fee

await client.router().openPosition(
marketAddress,
leverage,
takerMargin,
makerMargin,
maxAllowableTradingFee
)

Replace the placeholders (client, marketAddress, leverage, takerMargin, makerMargin, maxAllowableTradingFee) with your actual values. Make sure you have the sufficient funds in your account to open the position.

The openPosition method is asynchronous and returns a Promise, so you need to use await to wait for the position opening process to complete.

Retrieving Positions

After opening a position, you can retrieve information about your positions using the getPositions method provided by the ChromaticPosition instance. This method requires the market address and an array of position IDs.

const positionIds = await client.account().getPositionIds(marketAddress)
const positions = await client.position().getPositions(marketAddress, positionIds)

The getPositionIds method retrieves the array of position IDs associated with the specified market address. Then, you can use the getPositions method to retrieve detailed information about each position.