APIs

Open a Position

function openPosition(
  uint256 productId, 
  uint256 margin, 
  bool isLong, 
  uint256 leverage
) external returns(uint256 positionId)

This function opens a new leverage position for a product. If there's an existing position for the product with the same direction, this trade will increase the existing position.

NameTypeDescription

productId

uint256

the ID representing the product. The mapping of IDs and products is the the table below.

margin

uint256

the amount of token used as collateral for the position(need to multiply 1e8).

isLong

bool

True means Long and False means short.

leverage

uint256

the intended leverage for the position(need to multiply 1e8).

positionId

uint256

the id representing the position.

Below is the mapping between productId and product. The list will grow as more product is added.

productIdProduct

1

ETH-USD

2

BTC-USD

3

LINK-USD

4

SNX-USD

Close a Position

There are two functions available to close a position owned by the sender:

function closePosition(
  uint256 productId,
  uint256 margin,
  bool isLong
  ) external 
function closePositionWithId(
  uint256 positionId,
  uint256 margin
) public
NameTypeDescription

productId

uint256

the ID representing the product

margin

uint256

the amount of collateral to close for the position. The position can be fully or partially closed.(need to multiply 1e)

isLong

bool

True means Long and False means short

positionId

uint256

the id of the position to close

Get Open Positions

Get the information given the list of positionIds.

function getPositions(
  uint256[] calldata positionIds
) external view returns(Position[] memory _positions) 

Get the information for a user's position for a product with certain direction.

function getPosition(
  address account, 
  uint256 productId, 
  bool isLong
) external view returns(Position memory position) {
NameTypeDescription

positionIds

uint256[]

a list of position ids

account

address

a user's wallet address

productId

uint256

the ID representing the produt

isLong

bool

True means Long and False means short

position

Position

the struct consist of positionId, leverage, entry price, orace price at the opening, margin, owner, timestamp, direction

Last updated