Trading via Etherscan
Pika Protocol is a fully decentralized and permission-less exchange, operated not by team, but by unstoppable code. In the rare case when the website server is down, you can always trade directly with the smart contract from block explorers like Etherscan.
Preparation
If you have previously approved the contract in Pika UI, you can skip this step.
Approve Pika Contracts for USDC
To approve the contract, you first open the USDC contract on Etherscan: https://optimistic.etherscan.io/token/0x7f5c764cbc14f9669b88837ca1490cca17c31607#writeContract
Then clicks Connect to Web
to connect to your Metamask wallet.
You need to click the Approve function 4 times to approve these 4 addresses:
PikaPerpV4 address: 0x9b86B2Be8eDB2958089E522Fe0eB7dD5935975AB
PositionManager address: 0xb67c152e69217b5acb85a2e19df13423351b0e27
OrderBook address: 0x835a179a9E1A57f15823eFc82bC460Eb2D9d2E7C
PositionRouter address: 0xa78Cd820b198A943199deb0506E77d655b5078cC
The amount
is your intended trade amount. If you want to trade 100 USDC, the input amount should be 10000000000(100*1e8).
Enable Trading
You need to open the PikaPerpV4 contract: https://optimistic.etherscan.io/address/0x9b86b2be8edb2958089e522fe0eb7dd5935975ab#code and call setAccountManager
twice to enable the trading for market, limit and stop orders:
Call
setAccountManager
function by setting_manager
as the PositionManager contract address(0xb67c152e69217b5acb85a2e19df13423351b0e27) and_isActive
is true.Call the
setAccountManager
function by setting_manager
as the OrderBook contract address(0x835a179a9E1A57f15823eFc82bC460Eb2D9d2E7C) and_isActive
is true.
To enable placing market orders together with take profit and stop loss orders, you need to send two additional transactions:
Open the positionManager contract: https://optimistic.etherscan.io/address/0xB67c152E69217b5aCB85A2e19dF13423351b0E27 and call
setAccountManager
function,_manager
is the positionRouter contract: 0xa78Cd820b198A943199deb0506E77d655b5078cCOpen the orderbook contract: https://optimistic.etherscan.io/address/0x835a179a9E1A57f15823eFc82bC460Eb2D9d2E7C and call
setAccountManager
function,_manager
is the positionRouter contract: 0xa78Cd820b198A943199deb0506E77d655b5078cC
Place a Market Order
Place an Open Market Order
Open the PositionManager contract at https://optimistic.etherscan.io/address/0xB67c152E69217b5aCB85A2e19dF13423351b0E27#writeContract and fill in the parameters for createOpenPosition
function. The parameters are described below. Then you can click the Write
button to confirm the transaction.
Check the Position
In around 10 seconds after submitting the open order, you can check your position on Pika from PikaPerpV4 contract's getPosition
function: https://optimistic.etherscan.io/address/0x9b86B2Be8eDB2958089E522Fe0eB7dD5935975AB#readContract. Below is the description of each parameters.
The values in the return array represent: productId
, leverage
, entryPrice
, oraclePriceAtTheEntry
(can be ignored), margin
, ownerOfPosition
, entryTimestamp
, direction
, and fundingAtTheEntry
(can be ignored).
For example, the position below is a 2x ETH Long with the margin of 30 USDC, with enty price at 1847.867, opened at the timestamp of 1691810315.
If your open order is not executed successfully, your active position will show up as 0s.
Place a Close Market Order
Open the PositionManager contract at https://optimistic.etherscan.io/address/0xB67c152E69217b5aCB85A2e19dF13423351b0E27#writeContract and fill in the parameters for createClosePosition
function. The parameters are the same as those for createOpenPosition
mentioned above. Then you can click the Write
button to confirm the transaction.
Place a Limit/Stop Order
Place an Open Limit/Stop Order
Open the OrderBook contract at https://optimistic.etherscan.io/address/0x835a179a9E1A57f15823eFc82bC460Eb2D9d2E7C#writeContract and fill in the parameters for createOpenOrder
function. Fill in the parameters using the description provided below. Once all the parameters are entered, click the Write
button to confirm the transaction.
Place a Close Limit/Stop Order
Open the OrderBook contract at https://optimistic.etherscan.io/address/0x835a179a9E1A57f15823eFc82bC460Eb2D9d2E7C#writeContract and fill in the parameters for createCloseOrder
function. These parameters are the same as those for createOpenOrder
mentioned above, except for the `size, which refers to the position size you wish to close. The intended size needs to multiply 1e8 for the input. Then you can click the Write
button to confirm the transaction.
Place an Open Market Order with Take Profit and Stop Loss Orders
Open the PositionRouter contract at https://optimistic.etherscan.io/address/0xa78Cd820b198A943199deb0506E77d655b5078cC#writeContract and fill in the parameters for createOpenMarketOrderWithCloseTriggerOrders
function. The parameters are described below. After entering all the necessary information, click the Write
button to confirm the transaction.
Place Take Profit and Stop Loss Orders for an Existing Position
Open the PositionRouter contract at https://optimistic.etherscan.io/address/0xa78Cd820b198A943199deb0506E77d655b5078cC#writeContract and fill in the parameters for createCloseTriggerOrders
function. These parameters are the same as those for createOpenMarketOrderWithCloseTriggerOrders
mentioned above. Then you can click the Write
button to confirm the transaction.
Add and Remove Margin
First, open the PikaPerpV4 contract at https://optimistic.etherscan.io/address/0x9b86B2Be8eDB2958089E522Fe0eB7dD5935975AB#readContract. Call the getPositionId
function to retrieve the positionId
using your address, productId
, and position direction.
Next, navigate to https://optimistic.etherscan.io/address/0x9b86B2Be8eDB2958089E522Fe0eB7dD5935975AB#writeContract. Call the modifyMargin
function, inputting the positionId
from the previous step, the margin amount you wish to add or remove, and specify true
for adding margin or false
for removing margin in the shouldIncrease
field.
Last updated