[TOC]
The FMZ platform recently added support for Hyperliquid DEX, a high-performance decentralized exchange, providing users with more options for participating in decentralized trading. Currently, the FMZ platform's custodian functionality has been fully updated to support both Hyperliquid spot and perpetual contract trading and cover all API functionality of the DEX.
The Hyperliquid platform
Hyperliquid is a high-performance L1 blockchain optimized from scratch, with a vision to build a fully-chained open financial system. Users can create applications independently by interacting with efficient native components, while ensuring a smooth end-user experience.
Hyperliquid L1 has enough performance to support an unlicensed financial application ecosystem. All orders, withdrawals, transactions and settlements are completed on the chain in a completely transparent manner, with a block delay of less than 1 second. Currently, the chain supports processing capacities of up to 100,000 orders per second.
Hyperliquid L1 uses a custom consensus algorithm called HyperBFT, inspired by Hotstuff and its successors. Both the consensus mechanism and the network architecture are optimized from the ground up to meet the needs of high-performance blockchains.
With this guide, we hope to help you quickly master the programmatic and quantitative trading of Hyperliquid DEX on the FMZ platform and explore more trading opportunities.
The REST protocol - Practice the use of the interface. - Transactional interface practices (ordering, withdrawing) - Transaction-related inquiry practices (accounts, orders) - Other functions (cash, contract transfer, cash register access, transfer of assets to wallet, etc.)
The Websocket protocol - Exchange information subscription practice (no Trades interface in the REST interface, supplemented by Websocket interface)
On the Add Exchanges page of the FMZ platform, you can configure Hyperliquid spot and futures exchange objects:
Environmental divisions As with most exchanges, Hyperliquid has a test environment.
It's easy to use, the main network is stable and fast.
The address of the corresponding REST protocol API interface node:https://api.hyperliquid.xyz
I'm not sure.
The message signature information is also different:source == "a"
,chainId = 42161
The test net is often crashed, but is only used as a test interface, familiar with the trading functions on the DEX.
The address of the corresponding REST protocol API interface node:https://api.hyperliquid-testnet.xyz
I'm not sure.
The message signature information is also different:source == "b"
,chainId = 421614
As with most wallet connections on DEX, the wallet app can be used to connect to Hyperliquid (switching wallet to Arbitrum, scanning login, test network, home network, etc.).
If you want to get acquainted with the test network first, you can find the faucet directly on the Hyperliquid page after connecting the wallet to Hyperliquid.
After receiving the test asset and the USDC for the test, you can deposit it into Hyperliquid by clicking on the "Deposit" button (Arbitrum Test Net preferably with some ETH).
Clicking on the "Deposit" button to deposit requires a wallet verification and will consume a bit of ETH on Arbitrum.
When a transaction is done manually on a Hyperliquid APP page, the page automatically generates a proxy wallet address and a private key, which is recorded in the browser, for use on the browser page.
The required proxy wallet address and corresponding private key can be created on Hyperliquid's API page:
1 Name the proxy wallet you are about to create.
2, Generate addresses and private keys.
3. Use a wallet connected to Hyperliquid to authorize the proxy wallet.
Configure proxy wallet addresses, private keys on FMZ
This information can then be configured on the FMZ platform (see the configuration interface mentioned above).
Information needed to configure the exchange object:
Once the configuration is complete, we can test it on the FMZ platform, and we use the FMZ platform's "debugging tool" directly for testing practice.
If you are using a Hyperliquid exchange object with a test net information configuration, some switching operations may be required, such as:
function main() {
// REST协议API地址切换到测试网
exchange.SetBase("https://api.hyperliquid-testnet.xyz")
// source : a 主网 , b 测试网
exchange.IO("source", "b")
return exchange.GetAccount()
}
The main network configuration does not require any of the above switching operations, and the API interface for the spot and futures varieties on the Hyperliquid DEX exchange is almost the same, with only slight differences in detail.Home network configuration informationandConfiguration of the test networkWhat?Hyperliquid futuresThe exchange objects are tested.
function main() {
var markets = exchange.GetMarkets()
if (!markets) {
throw "get markets error"
}
var tbl = {
type: "table",
title: "test markets",
cols: [
"key", "Symbol", "BaseAsset", "QuoteAsset", "TickSize", "AmountSize", "PricePrecision", "AmountPrecision", "MinQty",
"MaxQty", "MinNotional", "MaxNotional", "CtVal", "CtValCcy"
],
rows: []
}
for (var symbol in markets) {
var market = markets[symbol]
tbl.rows.push([
symbol, market.Symbol, market.BaseAsset, market.QuoteAsset, market.TickSize, market.AmountSize,
market.PricePrecision, market.AmountPrecision, market.MinQty, market.MaxQty, market.MinNotional, market.MaxNotional, market.CtVal, market.CtValCcy
])
}
LogStatus("`" + JSON.stringify(tbl) + "`")
}
function main() {
var depth = exchange.GetDepth("ETH_USD.swap")
var asks = depth.Asks
var bids = depth.Bids
Log("买3", bids[2])
Log("买2", bids[1])
Log("买1", bids[0])
Log("卖1", asks[0])
Log("卖2", asks[1])
Log("卖3", asks[2])
}
function main() {
var account = exchange.GetAccount()
return account
}
function main() {
var symbols = ["ETH_USD.swap", "XRP_USD.swap", "HYPE_USD.swap"]
var arrDir = ["market_buy", "sell", "buy"]
var markets = exchange.GetMarkets()
var ids = []
for (var i in symbols) {
var symbol = symbols[i]
var side = arrDir[i]
var ticker = exchange.GetTicker(symbol)
var info = markets[symbol]
exchange.SetPrecision(info.PricePrecision, info.AmountPrecision)
// USDC
var qty = 15
var price = null
var amount = null
if (side == "market_buy") {
price = -1
side = "buy"
amount = qty / ticker.Last
} else {
price = side == "buy" ? ticker.Last * 0.9 : ticker.Last * 1.1
amount = qty / price
}
var id = exchange.CreateOrder(symbol, side, price, amount)
ids.push(id)
}
var tbl = {type: "table", title: "test", cols: ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"], rows: []}
for (var id of ids) {
var order = exchange.GetOrder(id)
tbl.rows.push([order.Symbol, order.Id, order.Price, order.Amount, order.DealAmount, order.AvgPrice, order.Status, order.Type, order.Offset, order.ContractType])
Sleep(500)
}
LogStatus("`" + JSON.stringify(tbl) + "`")
}
function main() {
var orders = exchange.GetOrders("USD.swap")
for (var order of orders) {
exchange.CancelOrder(order.Id, order)
Sleep(1000)
}
var tbl = {type: "table", title: "test", cols: ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"], rows: []}
for (var order of orders) {
tbl.rows.push([order.Symbol, order.Id, order.Price, order.Amount, order.DealAmount, order.AvgPrice, order.Status, order.Type, order.Offset, order.ContractType])
}
LogStatus("`" + JSON.stringify(tbl) + "`")
}
function main() {
// 设置当前为全仓
exchange.IO("cross", true)
// 设置杠杆
exchange.SetMarginLevel("ETH_USD.swap", 10)
return exchange.GetRawJSON()
}
exchange.GetRawJSON (()) returns the response to the leverage request:
{“status”:“ok”,“response”:{“type”:“default”}}
Since the interface parameters of the exchange are more complex and cannot be transmitted using the url encoding method, it is used to encode the data in the URL encoding method.exchange.IO
When calling a function, only JSON strings can be used as input parameters. The following are examples of each interface call.
Hyperliquid is a free and open-source project.https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order
var params = {"type": "scheduleCancel", "time": new Date().getTime()}
return exchange.IO("api", "POST", "/exchange", null, JSON.stringify(params))
{“status”:“err”,“response”:“Cannot set scheduled cancel time until enough volume traded. Required: \(1000000. Traded: \)174.57424.”}
This feature has some limitations: accounts can only use this feature if they have reached transaction level.
Create a TWAP order.
function main() {
var params = {
"type": "twapOrder",
"twap": {
"a": 0,
"b": true,
"s": "1",
"r": false,
"m": 10,
"t": false
}
}
// SOL_USDT.swap , 订单量 : 1 , twapOrder 订单有头寸要求,最少100美元价值
// a : 0 , 即 SOL_USDT.swap 这个品种
return exchange.IO("api", "POST", "/exchange", null, JSON.stringify(params))
}
The TWAP order has been cancelled.
function main() {
var params = {
"type": "twapCancel",
"a": 0,
"t": 3805
}
return exchange.IO("api", "POST", "/exchange", null, JSON.stringify(params))
}
The test network, authorizing a new proxy wallet.
function main() {
var params = {
"type": "approveAgent",
"hyperliquidChain": "Testnet",
"signatureChainId": "0x66eee",
"agentAddress": "0xAAAA",
"agentName": "test02",
"nonce": new Date().getTime()
}
return exchange.IO("api", "POST", "/exchange", null, JSON.stringify(params))
}
Authorization successfully returned:
{“status”:“ok”,“response”:{“type”:“default”}}
https://app.hyperliquid-testnet.xyz/API
The middle.In addition, the bank has also been accused of stealing assets from the bank.
function main() {
var params = {
"type": "vaultTransfer",
"vaultAddress": "0xAAA",
"isDeposit": true,
"usd": 5000000
}
return exchange.IO("api", "POST", "/exchange", null, JSON.stringify(params))
}
The test net, the asset presented to the wallet.
function main() {
var params = {
"type": "withdraw3",
"hyperliquidChain": "Testnet",
"signatureChainId": "0x66eee",
"amount": "5",
"time": new Date().getTime(),
"destination": "0xAAA"
}
return exchange.IO("api", "POST", "/exchange", null, JSON.stringify(params))
}
Asset splitting between spot/futures (permanent contracts)
function main() {
var params = {
"type": "usdClassTransfer",
"hyperliquidChain": "Testnet",
"signatureChainId": "0x66eee",
"amount": "5",
"toPerp": false,
"nonce": new Date().getTime()
}
return exchange.IO("api", "POST", "/exchange", null, JSON.stringify(params))
}
false
This is a list of all the different ways Futures -> Spot is credited in the database.true
This is the direction of redirection: spot -> futures.The WS interface address of the main network:
Mainnet: wss://api.hyperliquid.xyz/ws
Since the REST protocol API interface does not capture recent transaction data from the interface, the Websocket interface has this channel available for subscription.
Subscribe to the message structure
{
"method": "subscribe",
"subscription": {
"type": "trades",
"coin": "SOL"
}
}
Tests performed in the Deployment Tool:
function main() {
var loopCount = 20
var subMsg = {
"method": "subscribe",
"subscription": {
"type": "trades",
"coin": "SOL"
}
}
var conn = Dial("wss://api.hyperliquid.xyz/ws")
conn.write(JSON.stringify(subMsg))
if (conn) {
for (var i = 0; i < loopCount; i++) {
var msg = conn.read(1000)
if (msg) {
Log(msg)
}
}
}
conn.close()
Log("测试结束")
}
The above test, based on the latest custodian, requires the download of the latest custodian to support Hyperliquid DEX exchange.
Thank you for your support, thank you for reading.