CCXT
PHP Examples

Hyperliquid Trailing Order

Hyperliquid Trailing Order — 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;


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';
        $order_type = 'market';
        $side = 'sell';
        $amount = 0.2;
        $price = null;
        $params = array(
            'trailingPercent' => 5,
            'trailingTriggerPrice' => 100,
            'reduceOnly' => true,
        );
        try {
            $order = \React\Async\await($exchange->create_order($symbol, $order_type, $side, $amount, $price, $params));
            var_dump($order);
            $open_orders = \React\Async\await($exchange->fetch_open_orders($symbol));
            var_dump($open_orders);
            $canceled = \React\Async\await($exchange->cancel_order($order['id'], $symbol));
            var_dump($canceled);
        } catch(Exception $e) {
            var_dump(((string) $e));
        }
    }) ();
}


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