Pika Protocol
Search…
APIs

Open a Position

1
function openPosition(
2
uint256 productId,
3
uint256 margin,
4
bool isLong,
5
uint256 leverage
6
) external returns(uint256 positionId)
Copied!
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.
Name
Type
Description
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.
productId
Product
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:
1
function closePosition(
2
uint256 productId,
3
uint256 margin,
4
bool isLong
5
) external
Copied!
1
function closePositionWithId(
2
uint256 positionId,
3
uint256 margin
4
) public
Copied!
Name
Type
Description
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.
1
function getPositions(
2
uint256[] calldata positionIds
3
) external view returns(Position[] memory _positions)
Copied!
Get the information for a user's position for a product with certain direction.
1
function getPosition(
2
address account,
3
uint256 productId,
4
bool isLong
5
) external view returns(Position memory position) {
Copied!
Name
Type
Description
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 modified 3mo ago