Perp88
Search
⌃K

Interact: Perpetual Trading

Below, you can find out the guide on how to interact directly with the contract in regards to Perpetual Trading:

Open A New Long/Short Position

To open a new Long/Short position, you must submit an increase position order to Perp88’s Orderbook. Then, Perp88’s bot will execute the order and create a new position on your account.
Step 1: Search for a request called “createIncreaseOrder”
Step 2: Before proceeding to Step 3, please make sure that you have approve the collateral token to be spent by Perp88’s Orderbook at this address.
Step 3: Input the following parameters
  • `_subAccountId` = The Sub Account that you’d like this position to be opened.
  • `_path` = The path to swap tokens into collateral token. For basic usage, please only put the collateral token address as an array. For example [“0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6”], this would mean WBTC is your collateral token.
  • `_amountIn` = The amount of collateral token in that token decimals to be supplied
  • `_indexToken` = The address of the index token or the token the position is on Long/Short. You can get the list of token addresses here.
  • `_minOut` = The minimum amount of collateral token that you expect to be after a swap. This will only apply if you specified `_path` with two tokens. Usually, this parameter will be thoroughly calculated by Perp88’s frontend. For ease of use, you can input `0` here. The downside is that the swap might happen at unfavourable price, but the transaction will not fail.
  • `_sizeDelta` = The total position value in USD that you wish to open. This will be in 30 decimal places. For example, a position with $100 value would be `100000000000000000000000000000000`.
  • `_collateralToken` = The address of the collateral token of the position. You can get the list of token addresses here.
  • `_isLong` = `true for Long and `false` for Short position
  • `_triggerPrice` = The price in USD and in 30 decimal places for this order to be executed. For market order, you can input `0` where the order will be executed at any price.
  • `_triggerAboveThreshold` = This parameter specifies if you want the price to be greater than the `_triggerPrice` to execute. If that’s the case, `true` will be the input and vice versa.
  • `_executionFee` = The amount of the execution fee of this order. Currently, the execution fee is 0.2 MATIC. The parameter input should be `200000000000000000`.
  • `_shouldWrap` = If your collateral token is MATIC, this should be `true`.
Step 4: Input the “Transfer Value (MATIC)”
  • If your collateral token is not MATIC, input only the execution fee here which is `200000000000000000`
  • If your collateral token is MATIC, input the MATIC amount you wish to be collateral and add the 0.2 MATIC execution fee.
Step 5: The below screenshot shows an example of creating an order for BTC Long position with 0.1 BTC as collateral and position size of $30,000.
Step 6: Click “Send” button and confirm your transaction on your Metamask.

View Your Trading Position

Step 1: Search for a request called “getPositionWithSubAccountId”
Step 2: Input the following parameters
  • `primaryAccount` = The wallet address of the owner of the position
  • `subAccountId` = The index of the Sub Account of the position. For Sub Account 1, please input `0`. If the position is in Sub Account 2, please input `1` and so on.
  • `collateralToken` = The address of the collateral token of the position. You can get the list of token addresses here.
  • `indexToken` = The address of the index token or the token the position is on Long/Short. You can get the list of token addresses here.
  • `isLong` = `true for Long and `false` for Short position
Step 3: Click “Send” button
Step 4: If the position is still active and you input the correct parameters, the result should return the information of that position as below.
[
{
"name": "",
"type": "tuple",
"value": [
{
"name": "primaryAccount",
"type": "address",
"value": "0x0578C797798Ae89b688Cd5676348344d7d0EC35E"
},
{
"name": "size",
"type": "uint256",
"value": "83068772476826960073212719726080"
},
{
"name": "collateral",
"type": "uint256",
"value": "20922589371308568841434925596041"
},
{
"name": "averagePrice",
"type": "uint256",
"value": "15989018203724877893899004705177002"
},
{
"name": "entryBorrowingRate",
"type": "uint256",
"value": "5238"
},
{
"name": "entryFundingRate",
"type": "int256",
"value": "744"
},
{
"name": "reserveAmount",
"type": "uint256",
"value": "83068772"
},
{
"name": "realizedPnl",
"type": "uint256",
"value": "0"
},
{
"name": "hasProfit",
"type": "bool",
"value": true
},
{
"name": "lastIncreasedTime",
"type": "uint256",
"value": "1669107434"
},
{
"name": "fundingFeeDebt",
"type": "int256",
"value": "29448186654437084671132516116"
}
]
}
]
* `size` is the total position USD value in 30 decimal places.
* `collateral` is the collateral USD value in 30 decimal places.
* `averagePrice` is the entry price of the position in 30 decimal places.

View Pending Order

If your order has not been executed or you want to confirmed if it has been executed, follow the below steps:
Step 1: Search for request with the following names:
  • `getIncreaseOrder` for open new position order or order that add fund into positions
  • `getDecreaseOrder` for close position order or order that withdraw fund from positions
  • `getSwapOrder` for swap orders
Step 2: You will need to find your order index. The easiest way is to look at the transaction that created your order (example). Then, look at the “Logs” tab and find “CreateIncreaseOrder” event. The highlighted “orderIndex” in the screenshot is the order index that we need. In this case, it is `0`.
Step 3: Input the following parameters:
  • `_account` = The wallet address that created the order
  • `_subAccountId` = The index of the Sub Account of the position. For Sub Account 1, please input `0`. If the position is in Sub Account 2, please input `1` and so on.
  • `_orderIndex` = Taken from Step 2
Step 4: Click “Send” button
Step 5: If the order exists and is not executed, the result should look like this.
[
{
"name": "collateralToken",
"type": "address",
"value": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"
},
{
"name": "collateralDelta",
"type": "uint256",
"value": "0"
},
{
"name": "indexToken",
"type": "address",
"value": "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6"
},
{
"name": "sizeDelta",
"type": "uint256",
"value": "83068772476826960073212719726080"
},
{
"name": "isLong",
"type": "bool",
"value": false
},
{
"name": "triggerPrice",
"type": "uint256",
"value": "15000000000000000000000000000000000"
},
{
"name": "triggerAboveThreshold",
"type": "bool",
"value": false
}
]
Step 6: If the order does not exist or the order has already been executed, the result should look like this.
[
{
"name": "collateralToken",
"type": "address",
"value": "0x0000000000000000000000000000000000000000"
},
{
"name": "collateralDelta",
"type": "uint256",
"value": "0"
},
{
"name": "indexToken",
"type": "address",
"value": "0x0000000000000000000000000000000000000000"
},
{
"name": "sizeDelta",
"type": "uint256",
"value": "0"
},
{
"name": "isLong",
"type": "bool",
"value": false
},
{
"name": "triggerPrice",
"type": "uint256",
"value": "0"
},
{
"name": "triggerAboveThreshold",
"type": "bool",
"value": false
}
]

Cancel Pending Order

Step 1: Search the requests starting with “cancel” and use the one corresponding to your order type
​
​
Step 2: Input the following parameters:
  • `_subAccountId` = The index of the Sub Account of the position. For Sub Account 1, please input `0`. If the position is in Sub Account 2, please input `1` and so on.
  • `_orderIndex` = Taken from Step 2 of “View Pending Order”
Step 3: Click “Send” button

Edit Order

Step 1: Search the requests starting with “update” and use the one corresponding to your order type
​
​
Step 2: Input the following parameters:
  • `_subAccountId` = The index of the Sub Account of the position. For Sub Account 1, please input `0`. If the position is in Sub Account 2, please input `1` and so on.
  • `_orderIndex` = Taken from Step 2 of “View Pending Order”
  • `_sizeDelta` = The new position size to be changed
  • `_triggerPrice` = The new trigger price
  • `_triggerAboveThreshold` = The new value for triggerAboveThreshold
Step 3: Click “Send” button

Close A Long/Short Position

Step 1: Search for a request called “createDecreaseOrder”
​
​
Step 2: Input the following parameters
  • `_subAccountId` = The Sub Account that you’d like this position to be opened.
  • `_indexToken` = The address of the index token or the token the position is on Long/Short. You can get the list of token addresses here.
  • `_sizeDelta` = The total position value in USD that you wish to decrease. This will be in 30 decimal places. For example, if you want to decrease position size by $100, the input should be `100000000000000000000000000000000`. Decreasing position size is deleveraging. You will not receive any fund back.
  • `_collateralToken` = The address of the collateral token of the position. You can get the list of token addresses here.
  • `_collateralDelta` = The amount of collateral in USD and in 30 decimal places you wish to remove from the position. If you want to close the position entirely, you could specify `_sizeDelta` as the current position size and specify `0` for `_collateralDelta`.
  • `_isLong` = `true for Long and `false` for Short position
  • `_triggerPrice` = The price in USD and in 30 decimal places for this order to be executed. For market order, you can input `0` where the order will be executed at any price.
  • `_triggerAboveThreshold` = This parameter specifies if you want the price to be greater than the `_triggerPrice` to execute. If that’s the case, `true` will be the input and vice versa.
  • `_executionFee` = The amount of the execution fee of this order. Currently, the execution fee is 0.2 MATIC. The parameter input should be `200000000000000000`.
  • `_shouldWrap` = If your collateral token is MATIC, this should be `true`.
Step 3: Input the “Transfer Value (MATIC)” with the execution fee here which is `200000000000000000`
Step 4: Click “Send” button