CCXT
Python Examples

Hyperliquid Priority Fees

Hyperliquid Priority Fees — CCXT Python code example.

import os
import sys

# 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

# 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
async def example():
    exchange = ccxt.hyperliquid({
        'walletAddress': 'MY_WALLET_ADDRESS',
        'privateKey': 'MY_PRIVATE_KEY',
    })
    await exchange.load_markets()
    symbol = 'SOL/USDC:USDC'
    amount = 0.2
    ticker = 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 = await exchange.create_order(symbol, 'market', 'buy', amount, last, {
            'priorityFee': priority_fee,
        })
        print(market_order)
        # an IOC limit order
        ioc_order = await exchange.create_order(symbol, 'limit', 'sell', amount, last * 0.99, {
            'timeInForce': 'IOC',
            'reduceOnly': True,
            'priorityFee': priority_fee,
        })
        print(ioc_order)
        # a post-only order, the fee is charged when the order is placed
        post_only_order = await exchange.create_order(symbol, 'limit', 'buy', amount, last * 0.95, {
            'postOnly': True,
            'priorityFee': priority_fee,
        })
        print(post_only_order)
        # one fee for a whole batch, every order must be of the same kind
        orders = await exchange.create_orders([{
    'symbol': symbol,
    'type': 'limit',
    'side': 'buy',
    'amount': amount,
    'price': last * 0.94,
    'params': {
        'postOnly': True,
    },
}, {
    'symbol': symbol,
    'type': 'limit',
    'side': 'buy',
    'amount': amount,
    'price': last * 0.93,
    'params': {
        'postOnly': True,
    },
}], {
            'priorityFee': priority_fee,
        })
        print(orders)
    except Exception as e:
        print(str(e))

    await exchange.close()


asyncio.run(example())