# OKX Marketplace Api开发笔记

By [Harry](https://paragraph.com/@apeazuki) · 2023-11-21

---

開發環境：

[https://www.postman.com/](https://www.postman.com/)

開發者文檔：

[https://www.okx.com/cn/web3/build/docs/home/welcome](https://www.okx.com/cn/web3/build/docs/home/welcome)

**Headers**設置注意事項

![](https://storage.googleapis.com/papyrus_images/86a922cad81b212a6f132c1ceaf0c6ddfca85ab1715541c083f7ac783e6f4293.png)

OK-ACCESS-KEY就是API KEY

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

**Body**

![](https://storage.googleapis.com/papyrus_images/975c6422ee168b1ae4fd0abab848b0ce68c4a74da963661d4a948aa05609eb05.png)

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

**Pre-request Script**

![](https://storage.googleapis.com/papyrus_images/7051f4054fbe6dd1aad828bc3ca61a377c25a8dfaac2f7f1dfe16bc15d711ef0.png)

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：
    

![](https://storage.googleapis.com/papyrus_images/2ef70c92374e5d54f97d8d9e02a8f4c4e3aa945e13bbc4330bdb1ee544e83e26.png)

---

*Originally published on [Harry](https://paragraph.com/@apeazuki/okx-marketplace-api)*
