OKX Marketplace Api开发笔记

開發環境:

https://www.postman.com/

開發者文檔:

https://www.okx.com/cn/web3/build/docs/home/welcome

Headers設置注意事項

post image

OK-ACCESS-KEY就是API KEY

OK-ACCESS-PASSPHRASE就是你創建上一步KEY時輸入的密碼

Body

post image

Body就是你請求內容的正文,範例中請求的內容為:請求tick為sats對應鍵值的內容

Pre-request Script

post image

Pre-request Script預請求的部分一般是先預先計算好

1.OK-ACCESS-SIGN

2.OK-ACCESS-TIMESTAMP

這兩個內容,因為SIGN簽名和TIMESTAP都是需要實時計算的,這兩個請求需要條件是變量。

馬賽克部分是對應上方API KEY的Secret Key,替換好即可。

因為這兩個條件是通過預請求計算好,並且在代碼后段使用

pm.request.headers.add 加入到headers中,所以不需要額外添加到headers中。


Python寫法

import requests
import json

url = "https://www.okx.com/api/v5/mktplace/nft/ordinals/listings"

payload = json.dumps({
  "slug": "9699",
  "limit": "1"
})
headers = {
  'OK-ACCESS-KEY': '***************',
  'OK-ACCESS-PASSPHRASE': '********',
  'Content-Type': 'application/json',
  'Cookie': '__cf_bm******************E-1700564356-0-ASAXgezM+z3+QDVPOU5VIPwokH1ETe/DXJD*************Qbxbk+fPna/AiEzak/E8Y='
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

轉換為Python時需另外將簽名(sign)和時間戳(timestap)添加回Headers的部分,並且需要先計算。

Back Body
post image