本頁面為社群翻譯版本,僅供參考;內容以英文原版為準。
查看英文原版 ↗

交易所端點

交易所端點用於與 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 %}

英文官方來源: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint
原文擷取日期: · 鏡像建置日期: · 社群翻譯,以英文原版為準
非官方社群鏡像與翻譯,內容版權歸 Hyperliquid 所有,以英文原版為準。 來源: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint