CCXT
PHP Examples

Hyperliquid Priority Fees

Hyperliquid Priority Fees — CCXT PHP code example.

<?php
namespace ccxt;
include_once (__DIR__.'/../../ccxt.php');
// ----------------------------------------------------------------------------

// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code

// -----------------------------------------------------------------------------

error_reporting(E_ALL);
date_default_timezone_set('UTC');

use ccxt\Precise;
use React\Async;
use React\Promise;


// Hyperliquid order priority fees
// https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/priority-fees
//
// A priority fee gets an order processed sooner. It is set with the priorityFee param,
// an integer rate in units of 1e-8, so 10000 is 1 basis point (0.01%) of the order notional.
//
// - it is only accepted when every order in the request is IOC (market orders included),
//   or when every order is post-only and not reduce-only
// - it can't be combined with attached stopLoss / takeProfit orders
// - it is paid in HYPE from the undelegated staking balance, not from the trading balance
// - IOC orders pay on the filled notional, an IOC that does not fill pays nothing
// - post-only orders pay on the resting notional when placed, even if they never fill
function example() {
    return Async\async(function () {
        $exchange = new \ccxt\async\hyperliquid(array(
            'walletAddress' => 'MY_WALLET_ADDRESS',
            'privateKey' => 'MY_PRIVATE_KEY',
        ));
        \React\Async\await($exchange->load_markets());
        $symbol = 'SOL/USDC:USDC';
        $amount = 0.2;
        $ticker = \React\Async\await($exchange->fetch_ticker($symbol));
        $last = $ticker['last'];
        $priority_fee = 10000; // 1 basis point
        try {
            // a market order is sent as IOC, the price is only used to compute the max slippage price
            $market_order = \React\Async\await($exchange->create_order($symbol, 'market', 'buy', $amount, $last, array(
                'priorityFee' => $priority_fee,
            )));
            var_dump($market_order);
            // an IOC limit order
            $ioc_order = \React\Async\await($exchange->create_order($symbol, 'limit', 'sell', $amount, $last * 0.99, array(
                'timeInForce' => 'IOC',
                'reduceOnly' => true,
                'priorityFee' => $priority_fee,
            )));
            var_dump($ioc_order);
            // a post-only order, the fee is charged when the order is placed
            $post_only_order = \React\Async\await($exchange->create_order($symbol, 'limit', 'buy', $amount, $last * 0.95, array(
                'postOnly' => true,
                'priorityFee' => $priority_fee,
            )));
            var_dump($post_only_order);
            // one fee for a whole batch, every order must be of the same kind
            $orders = \React\Async\await($exchange->create_orders([array(
    'symbol' => $symbol,
    'type' => 'limit',
    'side' => 'buy',
    'amount' => $amount,
    'price' => $last * 0.94,
    'params' => array(
        'postOnly' => true,
    ),
), array(
    'symbol' => $symbol,
    'type' => 'limit',
    'side' => 'buy',
    'amount' => $amount,
    'price' => $last * 0.93,
    'params' => array(
        'postOnly' => true,
    ),
)], array(
                'priorityFee' => $priority_fee,
            )));
            var_dump($orders);
        } catch(Exception $e) {
            var_dump(((string) $e));
        }
    }) ();
}


\React\Async\await(example());