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:

  1. PikaPerpV4 address: 0x9b86B2Be8eDB2958089E522Fe0eB7dD5935975AB

  2. PositionManager address: 0xb67c152e69217b5acb85a2e19df13423351b0e27

  3. OrderBook address: 0x835a179a9E1A57f15823eFc82bC460Eb2D9d2E7C

  4. 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:

  1. Call setAccountManager function by setting _manager as the PositionManager contract address(0xb67c152e69217b5acb85a2e19df13423351b0e27) and _isActive is true.

  2. 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:

  1. Open the positionManager contract: https://optimistic.etherscan.io/address/0xB67c152E69217b5aCB85A2e19dF13423351b0E27 and call setAccountManager function, _manager is the positionRouter contract: 0xa78Cd820b198A943199deb0506E77d655b5078cC

  2. Open 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.

ParametersDescription

createOpenPosition

The ether to pay for execution fee. The input should be 0.00025.

account

Your wallet address

productId

The number represents the intended trading pair. Please refer to Trading Pairs for the productId of each trading pair.

margin

It is the USDC margin for the position. Note the intended margin amount needs to multiply 1e8 for the input. For example: 50 USDC margin's input is 5000000000.

leverage

It is the leverage of the position. The value needs to multiply 1e8 for the input (1000000000 represents 10x leverage).

isLong

It is the direction of the position. If you want to close a long position, the input is "true". If you want to close a short position, the input is "false"

acceptablePrice

It is the lowest acceptable price for open short or close long order, and highest acceptable price for open long or close short order. The order will be cancelled if the current price does not satisfy the acceptable price. Note the intended price needs to multiply 1e8 for the input.

executionFee

It is the execution fee paid to keepers to cover the gas fee of executing the order. The input amount should be 25000 (representing 0.00025ETH).

referralCode

It is the referral code of the trade. Put 0x0000000000000000000000000000000000000000000000000000000000000000 before the launch of referral program

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.

ParametersDescription

account

User wallet address

productId

The number represents the trading pair. Please refer to Trading Pairs for the productId of each trading pair.

isLong

It is the direction for the position. If it is "true", your position is long. If it is "false", your position is short.

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.

ParametersDescription

createOpenOrder

The ether to pay for execution fee. The input should be 0.00025.

productId

The number represents the intended trading pair. Please refer to Trading Pairs for the productId of each trading pair.

margin

It is the USDC margin for the position. Note the intended margin amount needs to multiply 1e8 for the input. For example: 50 USDC margin's input is 5000000000.

leverage

It is the leverage of the position. The value needs to multiply 1e8 for the input (1000000000 represents 10x leverage).

isLong

It is the direction of the position. If you want to close a long position, the input is "true". If you want to close a short position, the input is "false"

triggerPrice

It is the price at which the order will be triggerred. Note the trigger has high success rate but not 100% if the price moves cross the price and then goes back quickly before the keeper is able to trigger it. Note the intended price needs to multiply 1e8 for the input.

triggerAboveThreshold

If you want the order to be triggered when the price is above triggerPrice, the input is "true". If you want the order to be triggered when the price is below triggerPrice, the input is "false".

executionFee

It is the execution fee paid to keepers to cover the gas fee of executing the order. The input amount should be 25000 (representing 0.00025ETH).

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.

ParametersDescription

createOpenMarketOrderWithCloseTriggerOrders

The ether to pay for execution fee. The input should be 0.00075 if you are open a market order with both take profit and stop loss orders. The input is 0.0005 if you are open a market order with either take proft or stop loss order.

productId

The number represents the intended trading pair. Please refer to Trading Pairs for the productId of each trading pair.

margin

It is the USDC margin for the position. Note the intended margin amount needs to multiply 1e8 for the input. For example: 50 USDC margin's input is 5000000000.

leverage

It is the leverage of the position. The value needs to multiply 1e8 for the input (1000000000 represents 10x leverage).

isLong

It is the direction of the position. If you want to close a long position, the input is "true". If you want to close a short position, the input is "false"

acceptablePrice

It is the lowest acceptable price for open short or close long order, and highest acceptable price for open long or close short order. The order will be cancelled if the current price does not satisfy the acceptable price. Note the intended price needs to multiply 1e8 for the input.

executionFee

It is the execution fee paid to keepers to cover the gas fee of executing the order. The input amount should be 75000 (representing 0.00075ETH) if you open a market order with both take profit and stop loss orders. The input is 50000 if you are open a market order with either take proft or stop loss order.

stopLossPrice

It is the price below which the close long order will get triggered, and above which the close short order will get triggerred. Put 0 if do not want to place stop loss order.

takeProfitPrice

It is the price above which the close long order will get triggered, and below which the close short order will get triggerred. Put 0 if do not want to place take profit order.

referralCode

Put 0x0000000000000000000000000000000000000000 before the referral program is launched.

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