{"id":12398,"date":"2021-11-24T19:50:55","date_gmt":"2021-11-24T19:50:55","guid":{"rendered":"http:\/\/algotrading101.com\/learn\/?p=12398"},"modified":"2023-04-03T21:06:00","modified_gmt":"2023-04-03T21:06:00","slug":"okx-api-guide","status":"publish","type":"post","link":"https:\/\/algotrading101.com\/learn\/okx-api-guide\/","title":{"rendered":"OKX API &#8211; An Introductory Guide"},"content":{"rendered":"<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_12398\" class=\"pvc_stats total_only  \" data-element-id=\"12398\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"300\" height=\"200\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/OKX_Logo_Logo-edited-1.webp\" alt=\"\" class=\"wp-image-19577\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Table of contents:<\/h2>\n\n\n\n<ol><li><a href=\"#what-is-okex-api\">What is the OKX API?<\/a><\/li><li><a href=\"#what-is-okex\">What is OKX?<\/a><\/li><li><a href=\"#is-okex-api-free\">Is OKX API free?<\/a><\/li><li><a href=\"#okex-pros\">Why should I use OKX API?<\/a><\/li><li><a href=\"#okex-cons\">Why shouldn\u2019t I use the OKX API?<\/a><\/li><li><a href=\"#okex-countries\">Is OKX API available in my country?<\/a><\/li><li><a href=\"#okex-alternatives\">What are the alternatives to using OKX API?<\/a><\/li><li><a href=\"#okex-clients\">What clients are available for the OKX API?<\/a><\/li><li><a href=\"#start-okex\">How to get started with OKX API?<\/a><\/li><li><a href=\"#okex-pairs\">How to get trading pairs info with OKX API?<\/a><\/li><li><a href=\"#okex-price\">How to get Price Data with OKX API?<\/a><\/li><li><a href=\"#okex-historical\">How to get historical data with OKX API?<\/a><\/li><li><a href=\"#okex-indicator\">How to access technical indicators such as the 20 SMA with the OKX API?<\/a><\/li><li><a href=\"#okex-book\">How to get Order Book data with OKX API?<\/a><\/li><li><a href=\"#okex-trades\">How to get Trades Data with OKX API?<\/a><\/li><li><a href=\"#okex-order1\">How to execute a trade on ETH when BTC hits a certain price with the OKX API?<\/a><\/li><li><a href=\"#okex-order2\">How to execute an ETH trade when BTC moves 5% in the last 5 minutes with the OKX API?<\/a><\/li><li><a href=\"#okex-cancel\">How to cancel orders with OKX API?<\/a><\/li><li><a href=\"#full-code\">Full code<\/a><\/li><\/ol>\n\n\n\n<a name=\"what-is-okex-api\">\n\n\n\n<h2 class=\"wp-block-heading\">What is the OKX API?<\/h2>\n\n\n\n<p>OKX API is a method that allows traders to automatically trade cryptocurrencies on OKX via code.<\/p>\n\n\n\n<p>Link: <a href=\"https:\/\/www.okx.com\">https:\/\/www.okx.com<\/a><\/p>\n\n\n\n<a name=\"what-is-okex\">\n\n\n\n<h2 class=\"wp-block-heading\">What is OKX?<\/h2>\n\n\n\n<p>OKXis an online cryptocurrency exchange platform that allows traders to trade over 250 coins and tokens. OKX comes equipped with its own Cloud service and the ability to partake in Spot, Margin, and Futures trading.<\/p>\n\n\n\n<a name=\"is-okex-api-free\">\n\n\n\n<h2 class=\"wp-block-heading\">Is OKX API free?<\/h2>\n\n\n\n<p>Signing up for OKX and testing out its API is completely free. The fees come in when you start trading with the OKX API. <\/p>\n\n\n\n<p>The fee structure of OKX is more complex than most other online cryptocurrency exchanges. The first thing that dictates the fees is the type of user you are.<\/p>\n\n\n\n<p>There are mainly two types of OKX users &#8211; the regular and VIP ones. For regular users, the fee structure is based on the amount of your total OKB holding (OKX native cryptocurrency). Here is how the SPOT fee tiers look:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"257\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_spot_fees-1024x257.webp\" alt=\"\" class=\"wp-image-19581\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_spot_fees-1024x257.webp 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_spot_fees-300x75.webp 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_spot_fees-768x193.webp 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_spot_fees.webp 1237w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>For the VIP users, the fee structure is dictated by your monthly trading volume expressed in USD. There are 7 tiers for the VIP users and all follow a maker\/taker fee structure. Below you can see how the fee structure looks:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"327\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_vip_fees-1024x327.webp\" alt=\"\" class=\"wp-image-19582\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_vip_fees-1024x327.webp 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_vip_fees-300x96.webp 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_vip_fees-768x245.webp 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_vip_fees.webp 1225w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The same thing goes for the Futures market but the fee structures are different. Below you will find two tables where the first one is for regular users, while the second one is for VIP users.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"241\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_futures_fees-1024x241.webp\" alt=\"\" class=\"wp-image-19583\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_futures_fees-1024x241.webp 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_futures_fees-300x71.webp 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_futures_fees-768x181.webp 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_futures_fees.webp 1219w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"329\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_futures_vip_fees-1024x329.webp\" alt=\"\" class=\"wp-image-19584\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_futures_vip_fees-1024x329.webp 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_futures_vip_fees-300x96.webp 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_futures_vip_fees-768x246.webp 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx_futures_vip_fees.webp 1231w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>For a more detailed understanding of the OKX fee structure and the way it operates please visit the following link where they explain it thoroughly with examples: <a href=\"https:\/\/www.okex.com\/fees.html\">https:\/\/www.okx.com\/fees.html<\/a><\/p>\n\n\n\n<a name=\"okex-pros\">\n\n\n\n<h2 class=\"wp-block-heading\">Why should I use OKX API?<\/h2>\n\n\n\n<ul><li>OKX API is free<\/li><li>OKX API is efficient<\/li><li>Has many available cryptocurrencies<\/li><li>Features Options, Futures and Margin trading<\/li><li>Offers educational materials<\/li><li>Has Fiat support<\/li><li>Has competitive fees<\/li><li>No withdrawal and deposit fees<\/li><\/ul>\n\n\n\n<a name=\"okex-cons\">\n\n\n\n<h2 class=\"wp-block-heading\">Why shouldn&#8217;t I use OKX API?<\/h2>\n\n\n\n<ul><li>Some people experience trouble with the customer service<\/li><li>Has withdrawal transfer limitations<\/li><\/ul>\n\n\n\n<a name=\"okex-countries\">\n\n\n\n<h2 class=\"wp-block-heading\">Is OKX API available in my country?<\/h2>\n\n\n\n<p>OKX strives to be available worldwide but because of some strict regulations and jurisdiction issues it is not available in the following countries:<\/p>\n\n\n\n<p>Hong Kong, Cuba, Iran, North Korea, Crimea, Sudan, Malaysia, Syria, United States (including all USA territories), Bangladesh, Bolivia, Ecuador, and Kyrgyzstan.&nbsp;<\/p>\n\n\n\n<a name=\"okex-alternatives\">\n\n\n\n<h2 class=\"wp-block-heading\">What are the alternatives to using OKX API?<\/h2>\n\n\n\n<p>OKX can be replaced with other websites that can be more suitable for your needs. Here are some of them:<\/p>\n\n\n\n<ul><li><a href=\"https:\/\/algotrading101.com\/learn\/coinbase-api-guide\/\">Coinbase<\/a><\/li><li><a href=\"https:\/\/algotrading101.com\/learn\/binance-python-api-guide\/\">Binance<\/a><\/li><li><a href=\"https:\/\/algotrading101.com\/learn\/bitmex-api-introduction-guide\/\">BitMex<\/a><\/li><li><a href=\"https:\/\/algotrading101.com\/learn\/kraken-api-guide\/\">Kraken<\/a><\/li><li><a href=\"https:\/\/algotrading101.com\/learn\/gemini-api-guide\/\">Gemini<\/a><\/li><li>FTX<\/li><li>KuCoin<\/li><li>Deribit<\/li><li>ByBit<\/li><li>Phemex<\/li><li>Bittrex<\/li><li>Bitfinex<\/li><\/ul>\n\n\n\n<a name=\"okex-clients\">\n\n\n\n<h2 class=\"wp-block-heading\">What clients are available for the OKX API?<\/h2>\n\n\n\n<p>OKX API is available in the following clients:<\/p>\n\n\n\n<ul><li><a href=\"https:\/\/github.com\/okex\/V3-Open-API-SDK\/tree\/master\/okex-python-sdk-api\">Python<\/a><\/li><li><a href=\"https:\/\/github.com\/okex\/V3-Open-API-SDK\/tree\/master\/okex-go-sdk-api\">Go<\/a><\/li><li><a href=\"https:\/\/github.com\/okex\/V3-Open-API-SDK\/tree\/master\/okex-java-sdk-api\">Java<\/a><\/li><li><a href=\"https:\/\/github.com\/okex\/V3-Open-API-SDK\/tree\/master\/okex-cpp-sdk-api\">C++<\/a><\/li><\/ul>\n\n\n\n<a name=\"start-okex\">\n\n\n\n<h2 class=\"wp-block-heading\">How to get started with OKX API?<\/h2>\n\n\n\n<p>In order to get started with the OKX API and launch those trading strategies, we first need to go over to their website and obtain the API Key. <\/p>\n\n\n\n<p>Go to the following link and click the blue &#8220;Sign up&#8221; button that is found at the top of the page: <a href=\"https:\/\/www.okex.com\">https:\/\/www.okx.com<\/a><\/p>\n\n\n\n<p>Then input your email address, create a password and click the Sign up button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"475\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx-singup-1024x475.webp\" alt=\"\" class=\"wp-image-19578\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx-singup-1024x475.webp 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx-singup-300x139.webp 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx-singup-768x356.webp 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx-singup-1536x712.webp 1536w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/okx-singup.webp 1857w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Then enter a 6-digit code that will be sent over to your email account. After that, you will be welcomed to the OKX website. Now, go over to your profile icon in the upper right corner and select API on the dropdown menu.<\/p>\n\n\n\n<p>You will now be prompted to enable 2FA via mobile number or Google Authenticator. After that, go to the API section and click the &#8220;+Create V5 API Key&#8221; Button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"160\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/6-5-1024x160.jpg\" alt=\"\" class=\"wp-image-15941\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/6-5-1024x160.jpg 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/6-5-300x47.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/6-5-768x120.jpg 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/6-5-1536x240.jpg 1536w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/6-5.jpg 1837w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Then you can specify how your API Key instance will operate on your account. You can add different permissions, names and etc.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"941\" height=\"963\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/7-4.jpg\" alt=\"\" class=\"wp-image-15942\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/7-4.jpg 941w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/7-4-293x300.jpg 293w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/7-4-768x786.jpg 768w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/figure>\n\n\n\n<p>Then you will obtain the API Key and Secret Key that you should store in a safe and secure place for later use. That&#8217;s it! Now we will explore the OKX API functionality and simulate two simple trading scripts at the end.<\/p>\n\n\n\n<a name=\"okex-pairs\">\n\n\n\n<h2 class=\"wp-block-heading\">How to get trading pairs info with OKX API?<\/h2>\n\n\n\n<p>Trading pairs can be obtained with the OKX API by utilizing the tickers endpoint. With the OKX API, you need to specify the ticker type that you want to obtain i.e. Spot, Swap, Futures, or Option.<\/p>\n\n\n\n<p>Let us import the relevant libraries and obtain all the spot trading pairs. For cleaning purposes, we will put the data into a pandas data frame, delete the <code>instType <\/code>aka &#8220;SPOT&#8221; column and print the last 5 values transposed.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import requests\nimport pandas as pd\n\nurl = &#39;https:\/\/www.okx.com&#39;\ntickers = pd.DataFrame((requests.get(url+&#39;\/api\/v5\/market\/tickers?instType=SPOT&#39;).json())[&#39;data&#39;])\ntickers = tickers.drop(&#39;instType&#39;, axis=1)\ntickers.tail().T<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"700\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/8-5-1024x700.jpg\" alt=\"\" class=\"wp-image-15943\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/8-5-1024x700.jpg 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/8-5-300x205.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/8-5-768x525.jpg 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/8-5.jpg 1031w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Here we see that the SPOT market has 505 trading pairs which is a decent number. To check for the rest just change the &#8220;SPOT&#8221; in the endpoint to your interest (i.e. &#8220;FUTURES&#8221;).<\/p>\n\n\n\n<a name=\"okex-price\">\n\n\n\n<h2 class=\"wp-block-heading\">How to get Price Data with OKX API?<\/h2>\n\n\n\n<p>To obtain the Price Data with the OKX API you need to specify the instrument id in the required endpoint. The instrument id consists of the trading pair + the market it belongs to. Let us code it out:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>ticker = requests.get(url+&#39;\/api\/v5\/market\/ticker?instId=BTC-USD-SWAP&#39;).json()\nticker<\/code><\/pre><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>{'code' : '0',\n 'msg': '',\n 'data': &#91;{'instType': 'SWAP',\n    'instId': 'BTC-USD-SWAP',\n    'last': '56143.2',\n    'lastSz': '5',\n    'askPx': '56145.4',\n    'askSz': '1475',\n    'bidPx': '56145.3',\n    'bidSz': '538',\n    'open24h': '58578.6',\n    'high24h': '59012',\n    'low24h': '54561.2',\n    'volCcy24h': '22600.2617',\n    'vol24h.: '12824931',\n    'ts': '1620119907853',\n    'sodUtc0': '57204.8',\n    'sodUtc8': '57653.4'}]} \n<\/code><\/pre>\n\n\n\n<a name=\"okex-historical\">\n\n\n\n<h2 class=\"wp-block-heading\">How to get historical data with OKX API?<\/h2>\n\n\n\n<p>To obtain historical data with the OKX API you will need to decide which endpoint to use as there are 4 endpoints for historical data. Then you can request the data via the chosen endpoint.<\/p>\n\n\n\n<p>Here are the 4 endpoints listed and explained:<\/p>\n\n\n\n<ul><li><strong>Get Candlesticks<\/strong> &#8211; retrieves the latest 1440 data entries grouped by the specified candlestick bar<br><\/li><li><strong>Get Candlesticks History (top currencies only)<\/strong> &#8211; retrieves history candlestick charts from recent years.<br><\/li><li><strong>Get Index Candlesticks<\/strong> &#8211; retrieves candlestick charts of the index.<br><\/li><li><strong>Get Mark Price Candlesticks<\/strong> &#8211; retrieves the candlestick charts of mark price.<\/li><\/ul>\n\n\n\n<p>I&#8217;ll go with the second one and obtain the BTC-USD data over the last years with the preset candlesticks. I&#8217;ll clean the response and put it into a pandas data frame.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>historical = pd.DataFrame((requests.get(url+&#39;\/api\/v5\/market\/history-candles?instId=BTC-USDT-SWAP&#39;).json())[&#39;data&#39;])\nhistorical<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"778\" height=\"579\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/10-5.jpg\" alt=\"\" class=\"wp-image-15945\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/10-5.jpg 778w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/10-5-300x223.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/10-5-768x572.jpg 768w\" sizes=\"(max-width: 778px) 100vw, 778px\" \/><\/figure>\n\n\n\n<p>Here we see that the OKX API returns us data that isn&#8217;t labeled in an informative way. Let&#8217;s look at what the documentation says and rename the columns accordingly.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"849\" height=\"570\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/11-6.jpg\" alt=\"\" class=\"wp-image-15946\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/11-6.jpg 849w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/11-6-300x201.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/11-6-768x516.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/figure>\n\n\n\n<p>We will also convert the Unix time to date time and sort the value in ascending order by it.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>historical.columns= [&quot;Date&quot;,&quot;Open&quot;,&quot;High&quot;,&quot;Low&quot;,&quot;Close&quot;,&quot;Vol&quot;,&quot;volCcy&quot;]\nhistorical[&#39;Date&#39;] = pd.to_datetime(historical[&#39;Date&#39;], unit=&#39;ms&#39;)\nhistorical.set_index(&#39;Date&#39;, inplace=True)\nhistorical.sort_values(by=&#39;Date&#39;)\nhistorical<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"774\" height=\"630\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/12-3.jpg\" alt=\"\" class=\"wp-image-15947\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/12-3.jpg 774w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/12-3-300x244.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/12-3-768x625.jpg 768w\" sizes=\"(max-width: 774px) 100vw, 774px\" \/><\/figure>\n\n\n\n<p>Great, we could use an indicator now and do something with this data.<\/p>\n\n\n\n<a name=\"okex-indicator\">\n\n\n\n<h2 class=\"wp-block-heading\">How to access technical indicators such as the 20 SMA with the OKX API?<\/h2>\n\n\n\n<p>OKX API doesn&#8217;t feature indicator creation but we can do that on our own by utilizing the pandas library or a more sophisticated btalib library that is built for indicators.<\/p>\n\n\n\n<p>Let us create a simple 20 SMA on our data and put it all in a nice graph:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>historical[&#39;20 SMA&#39;] = historical.Close.rolling(20).mean()\nhistorical.tail()<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"920\" height=\"315\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/13-4.jpg\" alt=\"\" class=\"wp-image-15948\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/13-4.jpg 920w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/13-4-300x103.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/13-4-768x263.jpg 768w\" sizes=\"(max-width: 920px) 100vw, 920px\" \/><\/figure>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import plotly.graph_objects as go\nfig = go.Figure(data=[go.Candlestick(x = historical.index,\n                                    open = historical[&#39;Open&#39;],\n                                    high = historical[&#39;High&#39;],\n                                    low = historical[&#39;Low&#39;],\n                                    close = historical[&#39;Close&#39;],\n                                    ),\n                     go.Scatter(x=historical.index, y=historical[&#39;20 SMA&#39;], line=dict(color=&#39;purple&#39;, width=1))])\n\n\nfig.show()<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"538\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/14-4-1024x538.jpg\" alt=\"\" class=\"wp-image-15949\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/14-4-1024x538.jpg 1024w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/14-4-300x158.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/14-4-768x403.jpg 768w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/14-4.jpg 1306w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<a name=\"okex-book\">\n\n\n\n<h2 class=\"wp-block-heading\">How to get Order Book data with OKX API?<\/h2>\n\n\n\n<p>Order Book data can be obtained with the OKX API by using the Get Order Book endpoint and specifying the instrument id and the order book depth to retrieve the data. The API returns data split in the bid and ask values.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>book = requests.get(url+&#39;\/api\/v5\/market\/books?instId=BTC-USD-SWAP&sz=10&#39;).json()\nbook[&#39;data&#39;]<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"596\" height=\"626\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/15-3.jpg\" alt=\"\" class=\"wp-image-15950\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/15-3.jpg 596w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/15-3-286x300.jpg 286w\" sizes=\"(max-width: 596px) 100vw, 596px\" \/><\/figure>\n\n\n\n<p>If you want to split the bids and asks into their own data frames you can do the following:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>ask = pd.DataFrame(book[&#39;data&#39;][0][&#39;asks&#39;])\nbid = pd.DataFrame(book[&#39;data&#39;][0][&#39;bids&#39;])\n\nask<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"270\" height=\"497\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/16-2.jpg\" alt=\"\" class=\"wp-image-15951\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/16-2.jpg 270w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/16-2-163x300.jpg 163w\" sizes=\"(max-width: 270px) 100vw, 270px\" \/><\/figure>\n\n\n\n<p>We again have numbers instead of informative columns. Let&#8217;s take the first row and explain what each number means:<\/p>\n\n\n\n<ul><li>0 = the depth price<\/li><li>1 = the size at the price<\/li><li>2 = the number of liquidated orders at the price<\/li><li>3 = the number of orders at the price <\/li><\/ul>\n\n\n\n<p>Now, let&#8217;s take the 0, 1 and 3 from both data frames and merge them into a single one.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>bid.pop(2)\nask.pop(2)\ndf = pd.merge(bid, ask, left_index=True, right_index=True)\ndf = df.rename({&quot;0_x&quot;:&quot;Bid Price&quot;,&quot;1_x&quot;:&quot;Bid Size&quot;, &quot;3_x&quot;:&quot;Bid Amount&quot;,\n                &quot;0_y&quot;:&quot;Ask Price&quot;,&quot;1_y&quot;:&quot;Ask Size&quot;, &quot;3_y&quot;:&quot;Ask Amount&quot;}, axis=&#39;columns&#39;)\ndf.head()<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"784\" height=\"281\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/17-2.jpg\" alt=\"\" class=\"wp-image-15952\" srcset=\"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/17-2.jpg 784w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/17-2-300x108.jpg 300w, https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2022\/07\/17-2-768x275.jpg 768w\" sizes=\"(max-width: 784px) 100vw, 784px\" \/><\/figure>\n\n\n\n<a name=\"okex-trades\">\n\n\n\n<h2 class=\"wp-block-heading\">How to get Trades Data with OKX API?<\/h2>\n\n\n\n<p>To obtain the trades data with the OKX API you will need to execute a request on the Get Trades endpoint. Here is how you can do it:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>trades = requests.get(url+&#39;\/api\/v5\/market\/trades?instId=BTC-USDT&#39;).json()\ntrades[&#39;data&#39;]<\/code><\/pre><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;{'instld': 'BTC-USDT',\n  'side': 'sell',\n  'sz': '0.00928',\n  'px': '54118.4',\n  'tradeId.: '177167228',\n  'ts': '1620149876536'},\n {'instID': 'BTCUSDT',\n  'side': 'buy',\n  'sz': '0.00002267',\n  'px': '54118.5',\n  'tradeId': '177167227',\n  'ts': '1620149876291'},<\/code><\/pre>\n\n\n\n\n\n<h2 class=\"wp-block-heading\">How to fire a market order vs a limit order with OKX?<\/h2>\n\n\n\n<p>There is a slight difference, aside from the price parameter, when launching a market vs a limit order with the OKX <a href=\"https:\/\/github.com\/Coinrisings\/okex-api-v5\">SDK <\/a>that we&#8217;re going to use.<\/p>\n\n\n\n<p>The difference is when you specify the size (<code>sz<\/code>) parameter. When using a market order the size will be specified by the second symbol of your ticker and vice-versa.<\/p>\n\n\n\n<p>To illustrate this, both of the following orders will buy $20 worth of ETH but the market order will focus on the USDC part while the limit order will focus on the ETH part. This is the reason why the <code>sz<\/code> parameter isn&#8217;t the same.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code># Limit Order\ntradeAPI.place_order(instId=&#39;ETH-USDC&#39;, tdMode=&#39;cash&#39;, side=&#39;buy&#39;,\n                     ordType=&#39;limit&#39;, sz=&#39;0.0093&#39;, px=&#39;2159.00&#39;)\n# Market Order\ntradeAPI.place_order(instId=&#39;ETH-USDC&#39;, tdMode=&#39;cash&#39;, side=&#39;buy&#39;,\n                     ordType=&#39;market&#39;, sz=&#39;20&#39;)<\/code><\/pre><\/div>\n\n\n\n<a name=\"okex-order1\">\n\n\n\n<h2 class=\"wp-block-heading\">How to execute a trade on BTC when ETH hits a certain price with the OKX API?<\/h2>\n\n\n\n<p>In the first example, I will show you how to properly and securely launch orders with specified requirements. The thing that we want to do is to launch a trade on BTC when ETH hits a certain price (e.g. $3000).<\/p>\n\n\n\n<p>In order to make this work, we will need to set our order foundation and then create a loop that will check if the price level is hit. If the price is hit, we will execute a market order. On the contrary, we will continue looping around.<\/p>\n\n\n\n<p>When the price is executed we will wait for a few seconds and then check if the order was really filled. This additional step is very important to have in your trading strategies as the exchange server may encounter some troubles. <\/p>\n\n\n\n<p>Now that we have the main idea in mind it is time to set up the trade. Take note that we will be using the OKX python <a href=\"https:\/\/github.com\/Coinrisings\/okex-api-v5\">SDK<\/a> for this.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import okx.Trade_api as Trade\nimport requests, time\n\napi_key = &quot;&quot;\nsecret_key = &quot;&quot;\npassphrase = &quot;&quot;\ninstId = &quot;ETH-USDC&quot;\nflag = &#39;0&#39;\n\ntradeAPI = Trade.TradeAPI(api_key, secret_key, passphrase, False, flag)\n\nwhile True:\n    try:\n        ticker = requests.get(&#39;http:\/\/www.okx.com\/api\/v5\/market\/ticker?instId=BTC-USDC&#39;).json()\n        print(ticker[&#39;data&#39;][0][&#39;bidPx&#39;])\n    except Exception as e:\n        print(f&#39;Unable to obtain ticker: {e}&#39;)\n    \n    if float(ticker[&#39;data&#39;][0][&#39;bidPx&#39;]) &gt;= 32000.00:\n        try: \n           result = tradeAPI.place_order(instId=instId, tdMode=&#39;cash&#39;, side=&#39;buy&#39;,\n                                           ordType=&#39;limit&#39;, sz=&#39;0.005&#39;, px=&#39;2000.00&#39;)\n           ordId = result[&#39;data&#39;][0][&#39;ordId&#39;]\n        except Exception as e:\n            print(f&#39;Unable to execute order: {e}&#39;)\n\n        time.sleep(2)\n\n        try:\n            check = tradeAPI.get_orders(instId, ordId)\n        except Exception as e:\n            print(f&#39;Unable to check order: {e}&#39;)\n\n        if check[&#39;data&#39;][0][&#39;state&#39;] == &#39;canceled&#39;:\n            print(&#39;Order was canceled.&#39;)\n            break\n        else:\n            print(&#39;Order was executed!&#39;)\n            break \n    else:\n        print(&#39;Requirement not reached.&#39;)\n        time.sleep(15)<\/code><\/pre><\/div>\n\n\n\n<a name=\"okex-order2\">\n\n\n\n<h2 class=\"wp-block-heading\">How to execute an ETH trade when BTC moves 5% in the last 5 minutes with the OKX API?<\/h2>\n\n\n\n<p>The main task will be to execute an ETH  trade when BTC moves 5% in the last 5 minutes. This means that we will want to create a loop that will obtain the prices of the two cryptos and calculate the percentage change between the two.<\/p>\n\n\n\n<p>If the percentage change is less than 5%, the program will be sleeping for 5 minutes and calculating the percentage change again. If the percentage change is equal to or more than 5% the trade will execute.<\/p>\n\n\n\n<p>After the trade execution, we will sleep for a few seconds and then check on the trade if it was filled or not.  Now that the logic is set, it is time to code it out:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import okx.Trade_api as Trade\nimport requests, time\n\napi_key = &quot;&quot;\nsecret_key = &quot;&quot;\npassphrase = &quot;&quot;\ninstId = &quot;ETH-USDC&quot;\nflag = &#39;0&#39;\n\ntradeAPI = Trade.TradeAPI(api_key, secret_key, passphrase, False, flag)\n\nwhile True:\n    try:\n        old = requests.get(&#39;http:\/\/www.okx.com\/api\/v5\/market\/ticker?instId=BTC-USDC&#39;).json()\n        print(old[&#39;data&#39;][0][&#39;bidPx&#39;])\n    except Exception as e:\n        print(f&#39;Unable to obtain ticker: {e}&#39;)\n\n    time.sleep(300)\n\n    try:\n        new = requests.get(&#39;http:\/\/www.okx.com\/api\/v5\/market\/ticker?instId=BTC-USDC&#39;).json()\n        print(new[&#39;data&#39;][0][&#39;bidPx&#39;])\n    except Exception as e:\n        print(f&#39;Unable to obtain ticker: {e}&#39;)\n    \n    percent = ((float(new[&#39;data&#39;][0][&#39;bidPx&#39;]) - float(old[&#39;data&#39;][0][&#39;bidPx&#39;])) \/ float(old[&#39;data&#39;][0][&#39;bidPx&#39;])) * 100\n\n    if percent &gt;= 5:\n        try: \n           result = tradeAPI.place_order(instId=instId, tdMode=&#39;cash&#39;, side=&#39;buy&#39;,\n                                           ordType=&#39;limit&#39;, sz=&#39;0.005&#39;, px=&#39;2000.00&#39;)\n           ordId = result[&#39;data&#39;][0][&#39;ordId&#39;]\n        except Exception as e:\n            print(f&#39;Unable to execute order: {e}&#39;)\n\n        time.sleep(2)\n\n        try:\n            check = tradeAPI.get_orders(instId, ordId)\n        except Exception as e:\n            print(f&#39;Unable to check order: {e}&#39;)\n\n        if check[&#39;data&#39;][0][&#39;state&#39;] == &#39;canceled&#39;:\n            print(&#39;Order was canceled.&#39;)\n            break\n        else:\n            print(&#39;Order was executed!&#39;)\n            break \n    else:\n        print(f&#39;Requirement not reached. Percentage move at {percent}&#39;)<\/code><\/pre><\/div>\n\n\n\n<a name=\"okex-cancel\">\n\n\n\n<h2 class=\"wp-block-heading\">How to cancel orders with OKX API?<\/h2>\n\n\n\n<p>To cancel an order with the OKX API all you need to do is to access the Cancel Order endpoint. Here is an example code from the OKX API SDK documentation:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import okx.Trade_api as Trade\n\ntradeAPI = Trade.TradeAPI(api_key, secret_key, passphrase, False, flag)\ntradeAPI.cancel_order(instId, ordId, clOrdId)\n<\/code><\/pre><\/div>\n\n\n\n<a name=\"full-code\">\n\n\n\n<h2 class=\"wp-block-heading\">Full code<\/h2>\n\n\n\n<p><a href=\"https:\/\/github.com\/IgorWounds\/OKEx-API-Algotrading101\">GitHub Link<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_12398\" class=\"pvc_stats total_only  \" data-element-id=\"12398\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/algotrading101.com\/learn\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p>Table of contents: What is the OKX API? What is OKX? Is OKX API free? Why should I use OKX API? Why shouldn\u2019t I use the OKX API? Is OKX API available in my country? What are the alternatives to using OKX API? What clients are available for the OKX API? How to get started [&hellip;]<\/p>\n","protected":false},"author":14,"featured_media":19575,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_lmt_disableupdate":"no","_lmt_disable":"no","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[3,2],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>OKX API - An Introductory Guide - AlgoTrading101 Blog<\/title>\n<meta name=\"description\" content=\"OKX API is a method that allows traders to automatically trade cryptocurrencies on OKX via code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/algotrading101.com\/learn\/okx-api-guide\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"OKX API - An Introductory Guide - AlgoTrading101 Blog\" \/>\n<meta property=\"og:description\" content=\"OKX API is a method that allows traders to automatically trade cryptocurrencies on OKX via code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/algotrading101.com\/learn\/okx-api-guide\/\" \/>\n<meta property=\"og:site_name\" content=\"Quantitative Trading Ideas and Guides - AlgoTrading101 Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-11-24T19:50:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-03T21:06:00+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/OKX_Logo_Logo.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Igor Radovanovic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Igor Radovanovic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"OKX API - An Introductory Guide - AlgoTrading101 Blog","description":"OKX API is a method that allows traders to automatically trade cryptocurrencies on OKX via code.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/algotrading101.com\/learn\/okx-api-guide\/","og_locale":"en_US","og_type":"article","og_title":"OKX API - An Introductory Guide - AlgoTrading101 Blog","og_description":"OKX API is a method that allows traders to automatically trade cryptocurrencies on OKX via code.","og_url":"https:\/\/algotrading101.com\/learn\/okx-api-guide\/","og_site_name":"Quantitative Trading Ideas and Guides - AlgoTrading101 Blog","article_published_time":"2021-11-24T19:50:55+00:00","article_modified_time":"2023-04-03T21:06:00+00:00","og_image":[{"width":400,"height":400,"url":"http:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2023\/01\/OKX_Logo_Logo.webp","type":"image\/webp"}],"author":"Igor Radovanovic","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Igor Radovanovic","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/algotrading101.com\/learn\/okx-api-guide\/#article","isPartOf":{"@id":"https:\/\/algotrading101.com\/learn\/okx-api-guide\/"},"author":{"name":"Igor Radovanovic","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/person\/a7ae60c112a73b7c3fe14ac56726a0ae"},"headline":"OKX API &#8211; An Introductory Guide","datePublished":"2021-11-24T19:50:55+00:00","dateModified":"2023-04-03T21:06:00+00:00","mainEntityOfPage":{"@id":"https:\/\/algotrading101.com\/learn\/okx-api-guide\/"},"wordCount":1846,"publisher":{"@id":"https:\/\/algotrading101.com\/learn\/#organization"},"articleSection":["Programming","Trading"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/algotrading101.com\/learn\/okx-api-guide\/","url":"https:\/\/algotrading101.com\/learn\/okx-api-guide\/","name":"OKX API - An Introductory Guide - AlgoTrading101 Blog","isPartOf":{"@id":"https:\/\/algotrading101.com\/learn\/#website"},"datePublished":"2021-11-24T19:50:55+00:00","dateModified":"2023-04-03T21:06:00+00:00","description":"OKX API is a method that allows traders to automatically trade cryptocurrencies on OKX via code.","breadcrumb":{"@id":"https:\/\/algotrading101.com\/learn\/okx-api-guide\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/algotrading101.com\/learn\/okx-api-guide\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/algotrading101.com\/learn\/okx-api-guide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/algotrading101.com\/learn\/"},{"@type":"ListItem","position":2,"name":"OKX API &#8211; An Introductory Guide"}]},{"@type":"WebSite","@id":"https:\/\/algotrading101.com\/learn\/#website","url":"https:\/\/algotrading101.com\/learn\/","name":"Quantitative Trading Ideas and Guides - AlgoTrading101 Blog","description":"Authentic Stories about Algorithmic trading, coding and life.","publisher":{"@id":"https:\/\/algotrading101.com\/learn\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/algotrading101.com\/learn\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/algotrading101.com\/learn\/#organization","name":"AlgoTrading101","url":"https:\/\/algotrading101.com\/learn\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/logo\/image\/","url":"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/11\/AlgoTrading101-Lucas-Liew.jpg","contentUrl":"https:\/\/algotrading101.com\/learn\/wp-content\/uploads\/2020\/11\/AlgoTrading101-Lucas-Liew.jpg","width":1200,"height":627,"caption":"AlgoTrading101"},"image":{"@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/person\/a7ae60c112a73b7c3fe14ac56726a0ae","name":"Igor Radovanovic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/algotrading101.com\/learn\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d46175c509b3ee240a1e2bbe735a4d1e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d46175c509b3ee240a1e2bbe735a4d1e?s=96&d=mm&r=g","caption":"Igor Radovanovic"},"sameAs":["https:\/\/igorradovanovic.com","https:\/\/www.linkedin.com\/in\/igor-radovanovic-profile"],"url":"https:\/\/algotrading101.com\/learn\/author\/igor\/"}]}},"modified_by":"Igor Radovanovic","_links":{"self":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts\/12398"}],"collection":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/comments?post=12398"}],"version-history":[{"count":6,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts\/12398\/revisions"}],"predecessor-version":[{"id":21148,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/posts\/12398\/revisions\/21148"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/media\/19575"}],"wp:attachment":[{"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/media?parent=12398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/categories?post=12398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/algotrading101.com\/learn\/wp-json\/wp\/v2\/tags?post=12398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}