本页面为社区翻译版本,仅供参考;内容以英文原版为准。
查看英文原版 ↗

交易所端点

交易所端点用于与 Hyperliquid 链交互并进行交易。有关为这些请求生成签名的代码,请参阅 Python SDK。

资产

许多请求接受 asset 作为输入。对于永续合约,它是 meta 响应返回的 universe 字段中的索引。对于现货资产,请使用 10000 + index,其中 index 是 spotMeta.universe 中对应的索引。例如,提交 PURR/USDC 订单时,应使用的 asset 为 10000,因为其在现货元数据中的资产索引为 0。

子账户与金库

子账户和金库没有私钥。若要代表子账户或金库执行操作,签名应由主账户完成,并应将 vaultAddress 字段设置为该子账户或金库的地址。Python SDK 中的 basic_vault.py 示例演示了这一用法。

Expires After

某些操作支持可选字段 expiresAfter,它是一个毫秒时间戳,超过该时间后操作将被拒绝。用户签名的操作(例如 Core USDC 转账)不支持 expiresAfter 字段。注意,因 expiresAfter 字段过期而被取消的操作,将消耗 5 倍于常规基于地址的速率限制额度。

有关签名时如何加入该字段的详细信息,请参阅 Python SDK。

下单

POST https://api.hyperliquid.xyz/exchange

有关订单请求各字段的完整示例,请参阅 Python SDK。

对于限价订单,TIF(time-in-force,有效期)决定订单首次触及订单簿时的行为。

ALO(add liquidity only,即 “post only”)订单将被直接取消,而不是立即撮合。

IOC(immediate or cancel)订单的未成交部分将被取消,而不是挂在订单簿上。

GTC(good til canceled)订单没有特殊行为。

Client Order ID(cloid)是一个可选的 128 位十六进制字符串,例如 0x1234567890abcdef1234567890abcdef

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "order",
"orders": [{

"a": Number,

"b": Boolean,

"p": String,

"s": String,

"r": Boolean,

"t": {

"limit": {

"tif": "Alo"

"Ioc" "Gtc"

} or

"trigger": {

"isMarket": Boolean,

"triggerPx": String,

"tpsl": "tp"

"sl"

}

},

"c": Cloid (optional)

}],

"grouping": "na"

"normalTpsl" "positionTpsl",

"builder": Optional({"b": "address", "f": Number, "s": Optional([{"b": "address", "s": Number}])})

}



各键的含义:
a 为 asset
b 为 isBuy
p 为 price
s 为 size
r 为 reduceOnly
t 为 type
c 为 cloid(客户端订单 ID)

可选 builder 参数中各键的含义:
b 为接收额外手续费的地址
f 为手续费大小,单位为十分之一个基点,例如 f 为 10 时,将向用户收取订单名义价值 1bp 的手续费并发送给 builder
s 为一个可选列表,最多包含 5 个子 builder,用于接收部分 builder 手续费。每项中 b 为地址(必须是已存在的用户),s 为该地址在 builder 手续费中所占的份额,单位为 0.001%,例如 s 为 50000 时,一半的 builder 手续费将发送至该地址。份额必须为正数,且总和不超过 100%。builder 获得剩余部分
nonce* Number 建议使用当前时间戳(毫秒)
signature* Object
vaultAddress String 若代表金库或子账户进行交易,则填写其 42 位十六进制格式的地址;例如 0x0000000000000000000000000000000000000000
expiresAfter Number 时间戳(毫秒)

{% tabs %}

{
   "status":"ok",
   "response":{
      "type":"order",
      "data":{
         "statuses":[
            {
               "resting":{
                  "oid":77738308
               }
            }
         ]
      }
   }
}

{% endtab %}

{% tab title="200: OK 错误响应" %}

{
   "status":"ok",
   "response":{
      "type":"order",
      "data":{
         "statuses":[
            {
               "error":"Order must have minimum value of $10."
            }
         ]
      }
   }
}

{% endtab %}

{% tab title="200: OK 成功响应(已成交)" %}

{
   "status":"ok",
   "response":{
      "type":"order",
      "data":{
         "statuses":[
            {
               "filled":{
                  "totalSz":"0.02",
                  "avgPx":"1891.4",
                  "oid":77747314
               }
            }
         ]
      }
   }
}

{% endtab %}

取消订单

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "cancel",

"cancels": [

{

"a": Number,

"o": Number

}

],

"f": Boolean // fast

}



各键的含义:
a 为 asset
o 为 oid(订单 ID)
nonce* Number 建议使用当前时间戳(毫秒)
signature* Object
vaultAddress String 若代表金库或子账户进行交易,则填写其 42 位十六进制格式的地址;例如 0x0000000000000000000000000000000000000000
expiresAfter Number 时间戳(毫秒)

{% tabs %}

{
   "status":"ok",
   "response":{
      "type":"cancel",
      "data":{
         "statuses":[
            "success"
         ]
      }
   }
}

{% endtab %}

{% tab title="200: OK 错误响应" %}

{
   "status":"ok",
   "response":{
      "type":"cancel",
      "data":{
         "statuses":[
            {
               "error":"Order was never placed, already canceled, or filled."
            }
         ]
      }
   }
}

{% endtab %}

cancel 和 cancelByCloid 操作均包含一个可选的 fast 标志,在操作中编码为 f。如果 f: true 的取消请求涉及触发订单,则会被拒绝。目前 fast 没有其他作用。在未来的网络升级中,当且仅当 fast = true 时,取消操作才会在内存池中被优先处理。

请注意,如果 f 为 false,则必须省略该字段,即以 f: false 进行哈希的操作将被拒绝。

通过 cloid 取消订单

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "cancelByCloid",

"cancels": [

{

"asset": Number,

"cloid": String

}

],

"f": Boolean // fast

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object
vaultAddress String 若代表金库或子账户进行交易,则填写其 42 位十六进制格式的地址;例如 0x0000000000000000000000000000000000000000
expiresAfter Number 时间戳(毫秒)

{% tabs %}

{% endtab %}

{% tab title="200: OK 错误响应" %}

{% endtab %}

定时取消(死人开关)

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "scheduleCancel",

"time": number (optional)

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object
vaultAddress String 若代表金库或子账户进行交易,则填写其 42 位十六进制格式的地址;例如 0x0000000000000000000000000000000000000000
expiresAfter Number 时间戳(毫秒)

安排在将来某一时间执行全部取消操作。不包含 time 将移除已安排的取消操作。该时间必须至少晚于当前时间 5 秒。到达该时间后,所有未结订单都将被取消,并且触发计数将加一。每天最多触发 10 次。该触发计数在 UTC 00:00 重置。

修改订单

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "modify",

"oid": Number

Cloid,

"order": {

"a": Number,

"b": Boolean,

"p": String,

"s": String,

"r": Boolean,

"t": {

"limit": {

"tif": "Alo"

"Ioc" "Gtc"

} or

"trigger": {

"isMarket": Boolean,

"triggerPx": String,

"tpsl": "tp"

"sl"

}

},

"c": Cloid (optional)

},

"a": Boolean // always_place

}

各键的含义:
a 为 asset
b 为 isBuy
p 为 price
s 为 size
r 为 reduceOnly
t 为 type
c 为 cloid(客户端订单 ID)

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object
vaultAddress String 若代表金库或子账户进行交易,则填写其 42 位十六进制格式的链上地址;例如 0x0000000000000000000000000000000000000000
expiresAfter Number 时间戳(毫秒)

{% tabs %}

{% endtab %}

{% tab title="200: OK 错误响应" %}

{% endtab %}

单个修改和批量修改操作均包含一个可选的 always_place 标志,在操作中编码为 a。当 always_place = true 时,无论取消是否成功,都会下新订单。当 always_place = false 时,新订单必须是非触发订单,且必须满足 TIF = ALO,或者是 TIF = GTC 的不可成交订单。在后一种情况下,新订单的 TIF 会被覆盖为 ALO。

请注意,如果 a 为 false,则必须省略该字段,即以 a: false 进行哈希的操作将被拒绝。

修改多个订单

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "batchModify",

"modifies": [{

"oid": Number

Cloid,

"order": {

"a": Number,

"b": Boolean,

"p": String,

"s": String,

"r": Boolean,

"t": {

"limit": {

"tif": "Alo"

"Ioc" "Gtc"

} or

"trigger": {

"isMarket": Boolean,

"triggerPx": String,

"tpsl": "tp"

"sl"

}

},

"c": Cloid (optional)

}

}],

"a": Boolean // always_place

}

各键的含义:
a 为 asset
b 为 isBuy
p 为 price
s 为 size
r 为 reduceOnly
t 为 type
c 为 cloid(客户端订单 ID)

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object
vaultAddress String 若代表金库或子账户进行交易,则填写其 42 位十六进制格式的链上地址;例如 0x0000000000000000000000000000000000000000
expiresAfter Number 时间戳(毫秒)

更新杠杆

POST https://api.hyperliquid.xyz/exchange

更新某个币种的全仓或逐仓杠杆。

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "updateLeverage",

"asset": index of coin,

"isCross": true or false if updating cross-leverage,

"leverage": integer representing new leverage, subject to leverage constraints on that coin

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object
vaultAddress String 若代表金库或子账户进行交易,则填写其 42 位十六进制格式的链上地址;例如 0x0000000000000000000000000000000000000000
expiresAfter Number 时间戳(毫秒)

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

更新逐仓保证金

POST https://api.hyperliquid.xyz/exchange

从逐仓仓位中增加或移除保证金

请注意,若要设定目标杠杆倍数而非以 USDC 金额表示的保证金变动,可使用替代操作 {"type": "topUpIsolatedOnlyMargin", "asset": <asset>, "leverage": <float string>}

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "updateIsolatedMargin",

"asset": index of coin,

"isBuy": true, (this parameter won't have any effect until hedge mode is introduced)

"ntli": int representing amount to add or remove with 6 decimals, e.g. 1000000 for 1 usd,

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object
vaultAddress String 若代表金库或子账户进行交易,则填写其 42 位十六进制格式的链上地址;例如 0x0000000000000000000000000000000000000000
expiresAfter Number 时间戳(毫秒)

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

发送资产

POST https://api.hyperliquid.xyz/exchange

此通用方法用于在不同永续 DEX、现货余额、用户和/或子账户之间转移代币。使用 "" 指定默认的 USDC 永续 DEX,使用 "spot" 指定现货。只有抵押代币(collateral token)才能转入或转出永续 DEX。

请求头

名称 值
Content-Type* application/json

请求体

名称 类型 描述
action* Object

{

"type": "sendAsset",

"hyperliquidChain": "Mainnet" (on testnet use "Testnet" instead),

"signatureChainId": the id of the chain used when signing in hexadecimal format; e.g. "0xa4b1" for Arbitrum,

"destination": address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000,

"sourceDex": name of perp dex to transfer from,

"destinationDex": name of the perp dex to transfer to,

"token": tokenName:tokenId; e.g. "PURR:0xc4bf3f870c0e9465323c0b6ed28096c2",

"amount": amount of token to send as a string; e.g. "0.01",

"fromSubAccount": address in 42-character hexadecimal format or empty string if not from a subaccount,

"nonce": current timestamp in milliseconds as a Number, should match nonce

}

nonce* Number 建议使用当前时间戳(毫秒),必须与上方 action Object 中的 nonce 一致
signature* Object

响应

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

代理发送资产

POST https://api.hyperliquid.xyz/exchange

与发送资产类似,但可以由代理(agent)签名。destination 必须与源地址一致。使用 "" 指定默认的 USDC 永续 DEX,使用 "spot" 指定现货。只有抵押代币(collateral token)才能转入或转出永续 DEX。

请求头

名称 值
Content-Type* application/json

请求体

名称 类型 描述
action* Object

{

"type": "agentSendAsset",

"destination": address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000,

"sourceDex": name of perp dex to transfer from,

"destinationDex": name of the perp dex to transfer to,

"token": tokenName:tokenId; e.g. "PURR:0xc4bf3f870c0e9465323c0b6ed28096c2",

"amount": amount of token to send as a string; e.g. "0.01",

"fromSubAccount": address in 42-character hexadecimal format or empty string if not from a subaccount,

"nonce": current timestamp in milliseconds as a Number, should match nonce

}

nonce* Number 建议使用当前时间戳(毫秒),必须与上方 action Object 中的 nonce 一致
signature* Object

响应

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

携带数据发送至 EVM

POST https://api.hyperliquid.xyz/exchange

这是一种用于 Core 到 EVM 转移的专用操作,包含额外的数据负载。更多细节请参阅 HyperCore <> HyperEVM 转移。使用时将在已链接的合约上调用 coreReceiveWithData 而非 transfer。重要提示:调用者有责任确保代币已正确链接,且已链接的合约支持以下接口:

interface ICoreReceiveWithData {
  function coreReceiveWithData(
    address from,
    bytes32 destinationRecipient,
    uint32 destinationChainId,
    uint256 amount,
    uint64 nonce,
    bytes calldata data
  ) external;
}

请求头

名称 值
Content-Type* application/json

请求体

名称 类型 描述
action* Object

{

"type": "sendToEvmWithData",

"hyperliquidChain": "Mainnet" (on testnet use "Testnet" instead),

"signatureChainId": the id of the chain used when signing in hexadecimal format; e.g. "0xa4b1" for Arbitrum,

"token": tokenName:tokenId; e.g. "PURR:0xc4bf3f870c0e9465323c0b6ed28096c2",

"amount": amount of token to send as a string; e.g. "0.01",

"sourceDex": name of perp dex to transfer from,

"destinationRecipient": address in addressEncoding format,

"addressEncoding": "hex"

"base58",

"destinationChainId": number,

"gasLimit": number,

"data": bytes,

"nonce": current timestamp in milliseconds as a Number, should match nonce

}

nonce* Number 建议使用当前时间戳(毫秒),必须与上方 action Object 中的 nonce 一致
signature* Object

响应

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

Core USDC 转账

POST https://api.hyperliquid.xyz/exchange

向另一个地址发送 usd。此转账不经过 EVM 桥。签名格式对钱包界面而言是人类可读的。

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "usdSend",

"hyperliquidChain": "Mainnet" (on testnet use "Testnet" instead),
"signatureChainId": the id of the chain used when signing in hexadecimal format; e.g. "0xa4b1" for Arbitrum,

"destination": address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000,

"amount": amount of usd to send as a string, e.g. "1" for 1 usd,

"time": current timestamp in milliseconds as a Number, should match nonce

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

Core 现货转账

POST https://api.hyperliquid.xyz/exchange

向另一个地址发送现货资产。此转账不经过 EVM 桥。签名格式对钱包界面而言是人类可读的。

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "spotSend",

"hyperliquidChain": "Mainnet" (on testnet use "Testnet" instead),
"signatureChainId": the id of the chain used when signing in hexadecimal format; e.g. "0xa4b1" for Arbitrum,

"destination": address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000,
"token": tokenName:tokenId; e.g. "PURR:0xc4bf3f870c0e9465323c0b6ed28096c2",

"amount": amount of token to send as a string, e.g. "0.01",

"time": current timestamp in milliseconds as a Number, should match nonce

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

Example sign typed data for generating the signature:
{
  "types": {
    "HyperliquidTransaction:SpotSend": [
      {
        "name": "hyperliquidChain",
        "type": "string"
      },
      {
        "name": "destination",
        "type": "string"
      },
      {
        "name": "token",
        "type": "string"
      },
      {
        "name": "amount",
        "type": "string"
      },
      {
        "name": "time",
        "type": "uint64"
      }
    ]
  },
  "primaryType": "HyperliquidTransaction:SpotSend",
  "domain": {
    "name": "HyperliquidSignTransaction",
    "version": "1",
    "chainId": 42161,
    "verifyingContract": "0x0000000000000000000000000000000000000000"
  },
  "message": {
    "destination": "0x0000000000000000000000000000000000000000",
    "token": "PURR:0xc1fb593aeffbeb02f85e0308e9956a90",
    "amount": "0.1",
    "time": 1716531066415,
    "hyperliquidChain": "Mainnet"
  }
}

发起提款请求

POST https://api.hyperliquid.xyz/exchange

此方法用于发起提款流程。发出此请求后,L1 验证者将对提款请求进行签名并将其发送至桥合约。截至撰写本文时,提款手续费为 1 美元,提款大约需要 5 分钟完成。

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{
"type": "withdraw3",

"hyperliquidChain": "Mainnet" (on testnet use "Testnet" instead),
"signatureChainId": the id of the chain used when signing in hexadecimal format; e.g. "0xa4b1" for Arbitrum,

"amount": amount of usd to send as a string, e.g. "1" for 1 usd,

"time": current timestamp in milliseconds as a Number, should match nonce,

"destination": address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000

}

nonce* Number 建议使用当前时间戳(毫秒),必须与上方 action Object 中的 nonce 一致
signature* Object

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

从现货账户转账至永续合约账户(及反向)

POST https://api.hyperliquid.xyz/exchange

此方法用于将 USDC 从用户的现货钱包转到永续合约钱包,或反之。

请求头

名称 值
Content-Type* "application/json"

请求体

名称类型描述
action*Object

{

"type": "usdClassTransfer",

"hyperliquidChain": "Mainnet" (on testnet use "Testnet" instead),
"signatureChainId": the id of the chain used when signing in hexadecimal format; e.g. "0xa4b1" for Arbitrum,

"amount": amount of usd to transfer as a string, e.g. "1" for 1 usd. If you want to use this action for a subaccount, you can include subaccount: address after the amount, e.g. "1" subaccount:0x0000000000000000000000000000000000000000,

"toPerp": true if (spot -> perp) else false,

"nonce": current timestamp in milliseconds as a Number, must match nonce in outer request body

}

nonce*Number建议使用当前时间戳(毫秒),必须与上方 action Object 中的 nonce 一致
signature*Object

响应

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

存入质押

POST https://api.hyperliquid.xyz/exchange

此方法用于将原生代币从用户的现货账户转入质押,以便委托给验证者。

请求头

名称 值
Content-Type* application/json

请求体

名称 类型 描述
action* Object

{

"type": "cDeposit",

"hyperliquidChain": "Mainnet" (on testnet use "Testnet" instead),
"signatureChainId": the id of the chain used when signing in hexadecimal format; e.g. "0xa4b1" for Arbitrum,

"wei": amount of wei to transfer as a number,

"nonce": current timestamp in milliseconds as a Number, must match nonce in outer request body

}

nonce* Number 建议使用当前时间戳(毫秒),必须与上方 action Object 中的 nonce 一致
signature* Object

响应

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

存入质押(代理)

POST https://api.hyperliquid.xyz/exchange

与存入质押类似,但可以由代理(agent)签名。

请求头

名称 值
Content-Type* application/json

请求体

名称 类型 描述
action* Object

{

"type": "cDeposit2",

"wei": amount of wei to transfer as a number

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object
expiresAfter Number 时间戳(毫秒)

响应

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

从质押中取出

POST https://api.hyperliquid.xyz/exchange

此方法用于将原生代币从质押转回用户的现货账户。请注意,从质押转到现货账户需经过 7 天的取消质押队列。

请求头

名称 值
Content-Type* application/json

请求体

名称 类型 描述
action* Object

{

"type": "cWithdraw",

"hyperliquidChain": "Mainnet" (on testnet use "Testnet" instead),
"signatureChainId": the id of the chain used when signing in hexadecimal format; e.g. "0xa4b1" for Arbitrum,

"wei": amount of wei to transfer as a number,

"nonce": current timestamp in milliseconds as a Number, must match nonce in outer request body

}

nonce* Number 建议使用当前时间戳(毫秒),必须与上方 action Object 中的 nonce 一致
signature* Object

响应

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

向验证者委托或取消委托质押

POST https://api.hyperliquid.xyz/exchange

向某个验证者委托原生代币,或取消委托。请注意,对特定验证者的委托有 1 天的锁定期。

请求头

名称 值
Content-Type* application/json

请求体

名称 类型 描述
action* Object

{

"type": "tokenDelegate",

"hyperliquidChain": "Mainnet" (on testnet use "Testnet" instead),
"signatureChainId": the id of the chain used when signing in hexadecimal format; e.g. "0xa4b1" for Arbitrum,

"validator": address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000,
"isUndelegate": boolean,

"wei": number,

"nonce": current timestamp in milliseconds as a Number, must match nonce in outer request body

}

nonce* number 建议使用当前时间戳(毫秒)
signature* Object

响应

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

向金库存入或从金库取出资金

POST https://api.hyperliquid.xyz/exchange

向金库存入资金或从金库取出资金。

请求头

名称 值
Content-Type* application/json

请求体

名称 类型 描述
action* Object

{

"type": "vaultTransfer",

"vaultAddress": address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000,
"isDeposit": boolean,

"usd": number

}

nonce* number 建议使用当前时间戳(毫秒)
signature* Object
expiresAfter Number 时间戳(毫秒)

响应

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

向 HIP-3 DEX 的后备清算者存入或取出资金

POST https://api.hyperliquid.xyz/exchange

向 HIP-3 后备清算者(backstop liquidator)地址存入资金,或从中取出资金。ntl 是一个整数,单位为 1e-6 计价资产。金额必须是 1000 个计价资产的整数倍(即 ntl % 1000000000 == 0)。

只有本金可以取出,pnl 不可取出。

请求头

名称 值
Content-Type* application/json

请求体

名称 类型 描述
action* Object

{

"type": "hip3LiquidatorTransfer",

"dex": string (e.g. "xyz"),

"ntl": number,
"isDeposit": boolean

}

nonce* number 建议使用当前时间戳(毫秒)
signature* Object
expiresAfter Number 时间戳(毫秒)

响应

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

批准 API 钱包

POST https://api.hyperliquid.xyz/exchange

批准一个 API 钱包(有时也称为 Agent 钱包)。更多细节请参阅此处。

请求头

名称 值
Content-Type* application/json

请求体

名称 类型 描述
action* Object

{
"type": "approveAgent",

"hyperliquidChain": "Mainnet" (on testnet use "Testnet" instead),
"signatureChainId": the id of the chain used when signing in hexadecimal format; e.g. "0xa4b1" for Arbitrum,

"agentAddress": address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000,

"agentName": Optional name for the API wallet. An account can have 1 unnamed approved wallet and up to 3 named ones. And additional 2 named agents are allowed per subaccount. A custom expiration can be set by appending valid_until {timestamp} after the name. The expiration can be at most 180 days in the future,

"nonce": current timestamp in milliseconds as a Number, must match nonce in outer request body

}

nonce* number 建议使用当前时间戳(毫秒)
signature* Object

响应

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

批准 builder 手续费

POST https://api.hyperliquid.xyz/exchange

为 builder 批准最高手续费率。

请求头

名称 值
Content-Type* application/json

请求体

名称 类型 描述
action* Object

{
"type": "approveBuilderFee",

"hyperliquidChain": "Mainnet" (on testnet use "Testnet" instead),
"signatureChainId": the id of the chain used when signing in hexadecimal format; e.g. "0xa4b1" for Arbitrum,

"maxFeeRate": the maximum allowed builder fee rate as a percent string; e.g. "0.001%",

"builder": address in 42-character hexadecimal format; e.g. 0x0000000000000000000000000000000000000000,

"nonce": current timestamp in milliseconds as a Number, must match nonce in outer request body

}

nonce* number 建议使用当前时间戳(毫秒)
signature* Object

响应

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

下 TWAP 订单

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "twapOrder",
"twap": {

"a": Number,

"b": Boolean,

"s": String,

"r": Boolean,

"m": Number,

"t": Boolean

}

}

各键的含义:
a 为 asset
b 为 isBuy
s 为 size
r 为 reduceOnly

m 为 minutes
t 为 randomize

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object
vaultAddress String 若代表金库或子账户进行交易,则填写其 42 位十六进制格式的链上地址;例如 0x0000000000000000000000000000000000000000
expiresAfter Number 时间戳(毫秒)

{% tabs %}

{
   "status":"ok",
   "response":{
      "type":"twapOrder",
      "data":{
         "status": {
            "running":{
               "twapId":77738308
            }
         }
      }
   }
}

{% endtab %}

{% tab title="200: OK 错误响应" %}

{
   "status":"ok",
   "response":{
      "type":"twapOrder",
      "data":{
         "status": {
            "error":"Invalid TWAP duration: 1 min(s)"
         }
      }
   }
}

{% endtab %}

取消 TWAP 订单

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "twapCancel",

"a": Number,

"t": Number

}

各键的含义:
a 为 asset
t 为 twap_id

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object
vaultAddress String 若代表金库或子账户进行交易,则填写其 42 位十六进制格式的地址;例如 0x0000000000000000000000000000000000000000
expiresAfter Number 时间戳(毫秒)

{% tabs %}

{
   "status":"ok",
   "response":{
      "type":"twapCancel",
      "data":{
         "status": "success"
      }
   }
}

{% endtab %}

{% tab title="200: OK 错误响应" %}

{
   "status":"ok",
   "response":{
      "type":"twapCancel",
      "data":{
         "status": {
            "error": "TWAP was never placed, already canceled, or filled."
         }
      }
   }
}

{% endtab %}

下跟踪止损订单

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "trailingStop",

"asset": Number,

"isBuy": Boolean,

"sz": String,

"reduceOnly": Boolean,

"retracement": {"pct": as a percent string; e.g. "1.234%"} or {"px": String},

"activationPx": String

null

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object
vaultAddress String 若代表金库或子账户进行交易,则填写其 42 位十六进制格式的地址;例如 0x0000000000000000000000000000000000000000
expiresAfter Number 时间戳(毫秒)

{% tabs %}

{
   "status":"ok",
   "response":{
      "type":"trailingStop",
      "data":{
         "oid":77738308
      }
   }
}

{% endtab %}

预留额外操作额度

POST https://api.hyperliquid.xyz/exchange

此操作允许以每次请求 0.0005 USDC 的费用预留额外操作额度,而无需通过交易来提高基于地址的速率限制。费用从永续合约余额中支付。

可以设置 destination 来为另一个 L1 用户付费。目标用户必须已存在。如果未设置该字段,则在哈希时会跳过它。

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "reserveRequestWeight",

"weight": Number,

"destination": Address

null

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object
expiresAfter Number 时间戳(毫秒)

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

使未决 Nonce 失效(noop)

POST https://api.hyperliquid.xyz/exchange

此操作不执行任何操作(no operation),但会使 nonce 被标记为已使用。相比取消操作,这可能是取消在途订单更有效的方式。

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "noop"

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object
expiresAfter Number 时间戳(毫秒)

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

启用 HIP-3 DEX 抽象

POST https://api.hyperliquid.xyz/exchange

注意:已弃用。请优先使用 userSetAbstraction。

设置后,在 HIP-3 永续合约上的操作将自动从验证者运营的 USDC 永续余额中转移抵押品(针对以 USDC 作为抵押代币的 HIP-3 DEX),否则从现货余额转移。当 HIP-3 DEX 抽象处于启用状态时,抵押品从仓位或未结订单中释放时,会返还到相同的来源(验证者运营的 USDC 永续余额或现货余额)。

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称类型描述
action*Object

{

"type": "userDexAbstraction",

"hyperliquidChain": "Mainnet" (on testnet use "Testnet" instead),

"signatureChainId": the id of the chain used when signing in hexadecimal format; e.g. "0xa4b1" for Arbitrum,

"user": address in 42-character hexadecimal format. Can be a sub-account of the user,

"enabled": boolean,

"nonce": current timestamp in milliseconds as a Number, should match nonce

}

nonce*Number建议使用当前时间戳(毫秒)
signature*Object

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

启用 HIP-3 DEX 抽象(代理)

注意:已弃用。请优先使用 agentSetAbstraction。

与上面的 UserDexAbstraction 效果相同,但仅在将值从 null 设置为 true 时有效。

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "agentEnableDexAbstraction"

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

设置用户抽象

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "userSetAbstraction",

"hyperliquidChain": "Mainnet" (on testnet use "Testnet" instead),

"signatureChainId": the id of the chain used when signing in hexadecimal format; e.g. "0xa4b1" for Arbitrum,

"user": address in 42-character hexadecimal format. Can be a sub-account of the user,

"abstraction": one of the strings ["disabled", "unifiedAccount", "portfolioMargin"],

"nonce": current timestamp in milliseconds as a Number, should match nonce

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

设置用户抽象(代理)

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "agentSetAbstraction",

"abstraction": one of the strings ["i", "u", "p"] where "i" is "disabled", "u" is "unifiedAccount", and "p" is "portfolioMargin"

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

拆分结果

将 X 个计价资产拆分为 X 份 Yes 份额和 X 份 No 份额。

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "userOutcome",

"splitOutcome": { "outcome": Number, amount: String (e.g., "123.0") }

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

合并结果

将 X 份 Yes 份额和 X 份 No 份额合并为 X 个计价资产。

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "userOutcome",

"mergeOutcome": { "outcome": Number, amount: String

null (null means max) }

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

合并问题

将同一问题下每个结果各自的 X 份 Yes 份额合并为 X 个计价资产。

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "userOutcome",

"mergeQuestion": { "question": Number, amount: String

null (null means max) }

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

取反结果

将与某个问题相关联的某一结果的 X 份 No 份额,转换为该问题下所有其他结果各 X 份 Yes 份额。

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "userOutcome",

"negateOutcome": { "question": Number, "outcome": Number, amount: String }

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

验证者对一致性计价资产的无风险利率投票

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "validatorL1Stream",

"riskFreeRate": String // e.g. "0.04" for 4%

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

授权 AQAv2 角色

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "authorizeAqav2Role",

"token": number // e.g. 0 for USDC,

"role": "technical"

"treasury"

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

领取奖励

POST https://api.hyperliquid.xyz/exchange

请求头

名称 类型 描述
Content-Type* String "application/json"

请求体

名称 类型 描述
action* Object

{

"type": "claimRewards"

}

nonce* Number 建议使用当前时间戳(毫秒)
signature* Object

{% tabs %}

{'status': 'ok', 'response': {'type': 'default'}}

{% endtab %}

非官方社区镜像与翻译,内容版权归 Hyperliquid 所有,以英文原版为准。 来源: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint