{"id":37871,"date":"2023-11-28T17:42:03","date_gmt":"2023-11-28T12:12:03","guid":{"rendered":"https:\/\/coinswitch.co\/switch\/?p=37871"},"modified":"2023-11-30T16:16:51","modified_gmt":"2023-11-30T10:46:51","slug":"api-trading-setup-guide","status":"publish","type":"post","link":"https:\/\/coinswitch.co\/switch\/crypto\/api-trading-setup-guide\/","title":{"rendered":"API Trading made easy with CoinSwitch PRO: A how-to guide"},"content":{"rendered":"\n<p>API trading or Application Programming Interface trading is a technique to automate the trading process. While extremely useful and popular, API trading involves using basic coding in languages like Python and Java, which can be a bit confusing for users who are trying API trading for the first time.<\/p>\n\n\n\n<p>Yes, manual trading is a good option. But, if you wish to automate the trading process so that you can trade 24*7, then you might want to try the API trading option. Read our detailed blog post <a href=\"https:\/\/coinswitch.co\/switch\/crypto\/api-trading-vs-manual-trading\/\" target=\"_blank\" rel=\"noreferrer noopener\">API trading vs. manual trading<\/a> to learn more.<br><br>And here\u2019s a not-to-be-missed limited-time offer for you if you are a new API trader: <a href=\"https:\/\/coinswitch.co\/pro\/api-trading\" target=\"_blank\" rel=\"noreferrer noopener\">New traders need not pay any fee on all API trades for the first 30 days<\/a>.&nbsp;<\/p>\n\n\n\n<p>We will simplify the API trading process for you so that you can start your automated trading journey with ease.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Prerequisite:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Login to <a href=\"https:\/\/coinswitch.co\/pro\/btc-inr\/csx?utm_source=header_home\" target=\"_blank\" rel=\"noreferrer noopener\">CoinSwitch PRO<\/a><\/li>\n\n\n\n<li>Click on <a href=\"https:\/\/coinswitch.co\/pro\/api-trading\" target=\"_blank\" rel=\"noreferrer noopener\">API trading&nbsp;<\/a><\/li>\n\n\n\n<li>Click on <a href=\"https:\/\/api-trading.coinswitch.co\/#streamline-your-trading-experience\" target=\"_blank\" rel=\"noreferrer noopener\">API Documentation<\/a><\/li>\n<\/ul>\n\n\n\n<p>Here is a step-by-step guide to API Trading.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Getting Started with API Trading set-up&nbsp;<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: API Key Generation<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>On the API trading home page, you will find the \u2018Get Exclusive API Access\u2019 tab.&nbsp;<\/li>\n\n\n\n<li>If you have already logged in, you will see the \u2018Generate My Key\u2019 button on your screen.&nbsp;<\/li>\n\n\n\n<li>Click on the \u2018Generate My Key\u2019 button.&nbsp;<\/li>\n\n\n\n<li>Upon clicking, an OTP will be sent to your registered mobile number<\/li>\n\n\n\n<li>Enter the OTP and press enter.&nbsp;<\/li>\n<\/ul>\n\n\n\n<p>Your API Key and your Secret Key will now be visible on your screen.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">API Key&nbsp;<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Note down your API key in a safe place.&nbsp;<\/li>\n\n\n\n<li>Your API key will be visible on the screen when you trade.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Secret Key&nbsp;<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Copy your Secret Key and save it in a safe place&nbsp;<\/li>\n\n\n\n<li>It won\u2019t be visible again once you refresh the page.&nbsp;<\/li>\n\n\n\n<li>You should never share your Secret Key with anyone.&nbsp;<\/li>\n\n\n\n<li>In case you forget your secret key or misplace it, you can press the \u2018Delete Key\u2019 button on the API trading page to delete your existing API and Secret Key and generate new ones.&nbsp;<\/li>\n<\/ul>\n\n\n\n<p>Now that we have generated the API and Secret Key, we will proceed to the next step.&nbsp;<\/p>\n\n\n\n<p><em>PRO Tip: Never share your API key\/secret key with anyone. If the API keys were accidentally compromised, please get the key deactivated and raise a request for new key generation.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: API Set-Up on your system&nbsp;<\/h2>\n\n\n\n<p>API trading uses computer programming languages. The CoinSwitch Pro API trading supports Python and Java programming languages.<br>You can select your preferred programming language before you start this part of the API trading setup process.<br>We will first discuss the steps for Python, followed by Java. Therefore, if you are planning to use Java, you can skip to the Java set-up steps using the side navigation bar.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python environment set-up&nbsp;<\/h2>\n\n\n\n<p>Before we get started with Python environment set-up on your system, we have somethings that can help you with the set-up process. Click on the link below to watch the video explaining the Python environment set-up on your system. Additionally, the video also provides a set-by-set guide to your first order creation using your API keys. Watch the video below to start your API trading journey with ease and confidence. <\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"How To Setup your CoinSwitch Pro API Trading Account | CoinSwitch\" width=\"800\" height=\"600\" src=\"https:\/\/www.youtube.com\/embed\/Vd22Psxz3Xw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>Combine the steps in the video with the written steps below to get a full-proof guide for API trading environment set-up on your system. <\/p>\n\n\n\n<p>You can set up the Python environment on your computer using two different programs:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>PyCharm&nbsp;<\/li>\n\n\n\n<li>VSCode&nbsp;<\/li>\n<\/ol>\n\n\n\n<p><\/p>\n\n\n\n<p>We will start with PyCharm.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Setup With PyCharm<\/h3>\n\n\n\n<p>To set up a Python file in PyCharm, follow the instructions given below:<\/p>\n\n\n\n<p><strong>Install PyCharm<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Download and install the PyCharm community version IDE from the JetBrains website <a href=\"https:\/\/www.jetbrains.com\/edu-products\/download\/other-PCE.html\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.jetbrains.com\/edu-products\/download\/other-PCE.html<\/a><\/li>\n\n\n\n<li>Choose the appropriate version for your operating system and install Python 3 as well.<\/li>\n<\/ul>\n\n\n\n<p><strong>Create a new project<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Launch PyCharm and click on &#8220;Create New Project&#8221; on the welcome screen.&nbsp;<\/li>\n\n\n\n<li>If you already have a project open, you can also go to &#8220;File&#8221; -&gt; &#8220;New Project&#8221; to create a new one.<\/li>\n<\/ul>\n\n\n\n<p><strong>Configure project settings<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In the &#8220;New Project&#8221; dialog, choose the location where you want to store your project files and give your project a name.&nbsp;<\/li>\n\n\n\n<li>You can also specify the Python interpreter you want to use for this project.&nbsp;<\/li>\n\n\n\n<li>If you have a specific interpreter installed, select it; otherwise, you can choose the default option.<\/li>\n<\/ul>\n\n\n\n<p><strong>Create a new Python file<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Once the project is created, you&#8217;ll see the project structure on the left-hand side of the PyCharm window.&nbsp;<\/li>\n\n\n\n<li>Right-click on the directory where you want to create your Python file (e.g., the project root directory)&nbsp;<\/li>\n\n\n\n<li>Now select &#8220;New&#8221; -&gt; &#8220;Python File&#8221;. Give the file a meaningful name and press Enter.<\/li>\n<\/ul>\n\n\n\n<p><strong>Write your Python code or paste the API trading python file<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The newly created Python file will open in the editor window.&nbsp;<\/li>\n\n\n\n<li>You can start writing your Python code here or paste the API trading python file.&nbsp;<\/li>\n\n\n\n<li>PyCharm provides features like syntax highlighting, code completion, and debugging assistance to help you during development.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Install dependency<br><\/strong>Open PyCharm Terminal and run the below command<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install cryptography==40.0.2\npip install requests==2.27.1\npip install python-socketio==5.5.1\npip install websocket-client==1.2.3\n<\/code><\/pre>\n\n\n\n<p><strong>Run the Python file<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To run your Python file, you can right-click anywhere in the editor window and select &#8220;Run&#8221; from the context menu.&nbsp;<\/li>\n\n\n\n<li>Alternatively, you can use the keyboard shortcut (Ctrl+Shift+F10 on Windows\/Linux or Shift+Control+R on macOS) to run the current Python file.<\/li>\n<\/ul>\n\n\n\n<p><strong>View the output<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>After running the Python file, you&#8217;ll see the output in the &#8220;Run&#8221; tool window at the bottom of the PyCharm interface.&nbsp;<\/li>\n\n\n\n<li>If your program generates any output, it will be displayed here.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Congrats! You have successfully set up the environment for API Trading using PyCharm.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setup With VSCode<\/h2>\n\n\n\n<p>Download<a href=\"https:\/\/code.visualstudio.com\/download\" target=\"_blank\" rel=\"noreferrer noopener\"> VSCode<\/a> according to your system&#8217;s compatibility.<br>Click on the mentioned icon on the left panel in VSCode, search for <strong>Python extension,<\/strong> and install it<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/eM-YJEEWt9scSiwCrqeJMbPEQ8WyIKAUYdXZnI3Atx0_JZto4DSG1gvapLQVOeSUiVpK4ynxUn4YdAvxOMxbDzsxpBjb2LLgigj4U2lyzn8DoEpxUSHHzufUHwH-gEkkmdhx8doDZ_hvop-E7IS5szs\" alt=\"\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Mac Set-Up Steps<\/h2>\n\n\n\n<p>Open the terminal using the command Ctrl + `<\/p>\n\n\n\n<p><strong>Set up a virtual environment to run Python scripts via:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python3 -m venv venv\nsource venv\/bin\/activate<\/code><\/pre>\n\n\n\n<p><strong>Upgrade pip to install required libraries<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install --upgrade pip<\/code><\/pre>\n\n\n\n<p><strong>Install required libraries<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install cryptography==40.0.2\npip install requests==2.27.1\npip install python-socketio==5.5.1\npip install websocket-client==1.2<\/code><\/pre>\n\n\n\n<p><strong>Run the python script<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python &lt;file_name_on_system&gt;.py<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Windows Set-Up Steps<\/h2>\n\n\n\n<p>Open the command prompt using the command Cmd + R, type cmd, and press Enter<\/p>\n\n\n\n<p><strong>Set up a virtual environment to run a Python script via:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install virtualenv\nvirtualenv myenv\nmyenv\\Scripts\\activate<\/code><\/pre>\n\n\n\n<p><strong>Upgrade pip to install required libraries<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install --upgrade pip<\/code><\/pre>\n\n\n\n<p><strong>Install required libraries<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install cryptography==40.0.2\npip install requests==2.27.1\npip install python-socketio==5.5.1\npip install websocket-client==1.2.3<\/code><\/pre>\n\n\n\n<p><strong>Run the python script<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python &lt;file_name_on_system&gt;.py<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Java Client<\/strong><\/h2>\n\n\n\n<p>&nbsp;Here&#8217;s a guide to help you get started with setting up a Java project with IntelliJ and Gradle:<\/p>\n\n\n\n<p><strong>Install IntelliJ IDEA<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Download and install the latest version of IntelliJ IDEA from the official JetBrains website (<a href=\"https:\/\/www.jetbrains.com\/idea\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.jetbrains.com\/idea\/<\/a>).<\/li>\n<\/ul>\n\n\n\n<p><strong>Install Gradle<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Download and install Gradle by following the instructions on the official Gradle website (<a href=\"https:\/\/gradle.org\/install\/\" target=\"_blank\" rel=\"noopener\">https:\/\/gradle.org\/install\/<\/a>).<\/li>\n<\/ul>\n\n\n\n<p><strong>Open Shared API Trading Gradle project in IntelliJ<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Launch IntelliJ IDEA and select &#8220;Open Project&#8221; on the welcome screen.<\/li>\n\n\n\n<li>Choose &#8220;<strong>Gradle<\/strong>&#8221; on the left panel and click &#8220;<strong>Next<\/strong>.&#8221;<\/li>\n\n\n\n<li>Select &#8220;<strong>Java<\/strong>&#8221; as the project type and click &#8220;<strong>Next<\/strong>.&#8221;<\/li>\n\n\n\n<li>Specify the project name and location, then click &#8220;<strong>Finish<\/strong>.&#8221;<\/li>\n<\/ul>\n\n\n\n<p><strong>Configure Gradle in IntelliJ<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>After creating the project, IntelliJ will prompt you to configure Gradle.<\/li>\n\n\n\n<li>Choose &#8220;Use auto-import&#8221; to automatically synchronize Gradle changes.<\/li>\n\n\n\n<li>Select the Gradle JVM (Java Virtual Machine) you want to use for your project.<\/li>\n<\/ul>\n\n\n\n<p><strong>Configure project structure<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In the Project view on the left side of IntelliJ, navigate to the project folder.<\/li>\n\n\n\n<li>Right-click on the &#8220;src&#8221; folder and you will see two files: the first one is the main Java file and the second one is the config file<\/li>\n\n\n\n<li>Specify the class name and click &#8220;OK.&#8221;<\/li>\n<\/ul>\n\n\n\n<p><strong>Configure dependencies with Gradle<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the `build.gradle` file in the project root directory.<\/li>\n\n\n\n<li>Inside the `dependencies` block, specify the libraries and dependencies you want to include in your project.<\/li>\n\n\n\n<li>For example, to include the Apache Commons Lang library, you can add the following line:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>dependencies {\n\n&nbsp;&nbsp;&nbsp;implementation 'org.apache.commons:commons-lang3:3.12.0'}<\/code><\/pre>\n\n\n\n<p><strong>Build and run the project<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Click on the &#8220;Gradle&#8221; tab on the right side of the IntelliJ window.<\/li>\n\n\n\n<li>Expand the project tree and navigate to the &#8220;Tasks&#8221; section.<\/li>\n\n\n\n<li>Double-click on &#8220;build&#8221; to build the project.<\/li>\n\n\n\n<li>Once the build is successful, you can run the project by right-clicking on the Java class file and selecting &#8220;Run.&#8221;<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Congrats! You have set up the API Trading Java project with IntelliJ using Gradle as the build tool.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Get Set Go!<\/h2>\n\n\n\n<p>You have successfully installed the API trading environment on your system using the system and the language of your choice. Now is the time to put it to test by executing your first trade. Here are the prerequisites to execute a successful trade:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go through the <a href=\"https:\/\/api-trading.coinswitch.co\/#streamline-your-trading-experience\" target=\"_blank\" rel=\"noreferrer noopener\">API Documentation<\/a> available on CoinSwitch Pro.&nbsp;&nbsp;<\/li>\n\n\n\n<li>Familiarize yourself with the language you are planning to use ie. Python or Java.<\/li>\n\n\n\n<li>Load your wallet with some amount of money so that you can execute your first API trade.&nbsp;<\/li>\n<\/ol>\n\n\n\n<p>Brace yourself, you are about to write the very first code of your life.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Write your First Code <\/h2>\n\n\n\n<p><strong>Step 1<\/strong><\/p>\n\n\n\n<p>Add the received <strong>secret_key<\/strong> and <strong>API_key<\/strong> that you generated to the given placeholders in the given script at the lines mentioned below:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Python Code:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>secret_key = \"&lt;secret_key generated&gt;\"\napi_key = \"&lt;api_key generated&gt;\"\napi_trading_client = ApiTradingClient(secret_key, api_key)<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Java Code: <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ApiConfig {\n    public static final String API_KEY = \"&lt;api_key generated&gt;\";\n    public static final String SECRET_KEY = \"&lt;secret_key generated&gt;\";}\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is an Endpoint in API?<\/h3>\n\n\n\n<p>The document will talk something about Endpoints. Before we move ahead, it is important to understand what an Endpoint is.&nbsp;<\/p>\n\n\n\n<p><em>An API endpoint is a specific location within an API that accepts requests and sends back responses. It&#8217;s a way for different systems and applications to communicate with each other, by sending and receiving information and instructions via the endpoint.<\/em><\/p>\n\n\n\n<p>Now when we talk about Endpoints, you will know that it is basically how your API is going to interact with the CoinSwitch API to execute the command.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">General information on Endpoints used in CoinSwitch API trading<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The base endpoint is: https:\/\/coinswitch.co<\/li>\n\n\n\n<li>All timestamps are in milliseconds and in the IST timezone.<\/li>\n\n\n\n<li>GET request parameters are sent as a string of key-value params.<\/li>\n<\/ul>\n\n\n\n<p>Now that you know what an endpoint is, it is time to verify your API and Secret key so that you can execute a trade.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Verification and Authentication of Keys<\/h3>\n\n\n\n<p>Use the code below to verify and authenticate your keys:<\/p>\n\n\n\n<p><strong>Python Code:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#validate_keys\nprint(api_trading_client.validate_keys())<\/code><\/pre>\n\n\n\n<p><strong>Java Code:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/check connection\npublic String ValidateKeys() throws Exception {\n&nbsp;&nbsp;&nbsp;&nbsp;HashMap&lt;String, String&gt; parameters = new HashMap&lt;&gt;();\n&nbsp;&nbsp;&nbsp;&nbsp;HashMap&lt;String, Object&gt; payload = new HashMap&lt;&gt;();\n&nbsp;&nbsp;&nbsp;&nbsp;String response = this.makeRequest(\"GET\", ApiConfig.VALIDATE_API, payload, parameters);\n\n&nbsp;&nbsp;&nbsp;&nbsp;return response;\n\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Query Parameters:<\/strong><strong> <\/strong>None<\/p>\n\n\n\n<p>If your keys match and are verified, you will get the following response:<\/p>\n\n\n\n<p><strong>Success Response:<\/strong><\/p>\n\n\n\n<p>Response Code: <strong>200<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\"message\":\"Valid Access\"}<\/code><\/pre>\n\n\n\n<p>In case your keys do not match and are thus not verified, you will get the following response:&nbsp;<\/p>\n\n\n\n<p><strong>Failure Response:<\/strong><\/p>\n\n\n\n<p>Response Code:<strong> 401<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\"message\":\"Invalid Access\"}<\/code><\/pre>\n\n\n\n<p>In case of failed key verification, you can Delete the key and generate a new one using the step mentioned at the beginning of this article.&nbsp;<\/p>\n\n\n\n<p>You have come a long way, now is the time to move on to the exciting part. Let\u2019s try our hands at executing a trade using the API environment that you so meticulously set up on your system.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Trading Endpoints<\/h2>\n\n\n\n<p>There are various trading endpoints that you can use to execute different types of orders. These trading endpoints are:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create Order<\/li>\n\n\n\n<li>Cancel Order<\/li>\n\n\n\n<li>Portfolio<\/li>\n\n\n\n<li>Open Orders&nbsp;<\/li>\n\n\n\n<li>Close Orders<\/li>\n<\/ol>\n\n\n\n<p>Let&#8217;s under the <strong>Create Order<\/strong> trade endpoint with an example.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create Order<\/h2>\n\n\n\n<p>Use the code below to place an order on a particular exchange:<\/p>\n\n\n\n<p><strong>Python Code:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#create order\n\n\n\npayload = {\n   \"side\":\"sell\",\n   \"symbol\":\"BTC\/INR\",\n   \"type\":\"limit\",\n   \"price\":2300000,\n   \"quantity\":0.00005,\n   \"exchange\":\"coinswitchx\"\n}\nprint(api_trading_client.create_order(payload=payload))\n<\/code><\/pre>\n\n\n\n<p><strong>Java Code<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/create order\npublic String createOrder() throws  Exception{\n        HashMap&lt;String, String&gt; parameters = new HashMap&lt;&gt;();\n        HashMap&lt;String, Object&gt; payload = new HashMap&lt;&gt;();\n        payload.put(\"side\", \"sell\");\n        payload.put(\"symbol\", \"BTC\/INR\");\n        payload.put(\"quantity\", 0.00005);\n\t payload.put(\"price\", 2300000);\n        payload.put(\"type\", \"limit\");\n        payload.put(\"exchange\", \"coinswitchx\");    \n        String response = this.makeRequest(\"POST\", ApiConfig.CREATE_ORDER, payload, parameters);\n        return response;\n    }\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Query Parameters: <\/strong><strong><br><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th><strong>Name<\/strong><\/th><th><strong>Type<\/strong><\/th><th><strong>Mandatory<\/strong><\/th><th><strong>Description<\/strong><\/th><\/tr><tr><th>side<\/th><th>STRING<\/th><th>Yes<\/th><th>Allowed values:<br>\u201cbuy\u201d<br>\u201csell\u201d<br>(case insensitive)<\/th><\/tr><tr><th>symbol<\/th><th>STRING<\/th><th>Yes<\/th><th>Should be in the format<br>base_currency\/quote_currency<br>(case insensitive)<\/th><\/tr><tr><th>type<\/th><th>STRING<\/th><th>Yes<\/th><th>Order Type like LIMIT<\/th><\/tr><tr><th>price<\/th><th>FLOAT<\/th><th>Yes<\/th><th>Price at which you want to place the order<\/th><\/tr><tr><th>quantity<\/th><th>FLOAT<\/th><th>Yes<\/th><th>Base quantity that you want to buy or sell.<\/th><\/tr><tr><th>exchange<\/th><th>STRING<\/th><th>Yes<\/th><th>Allowed values:<br>\u201ccoinswitchx\u201d<br>\u201cwazirx\u201d<br>(case insensitive)<\/th><\/tr><\/thead><\/table><\/figure>\n\n\n\n<p><em>PRO Tip: After you create an order, it might take some time for it to get executed on the exchange. So please be patient and plan your trades accordingly.<\/em><\/p>\n\n\n\n<p>Once you execute the above query, you will get one of the following responses.<br><\/p>\n\n\n\n<p><strong>Response:&nbsp;<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Status Code: 200 \n\n{\n   \"data\":{\n      \"order_id\":\"927db2d9-643c-47a3-9c0f-78741ac95cf5\",\n      \"symbol\":\"BTC\/INR\",\n      \"price\":2300000, # price at which Order was placed by the user\n      \"average_price\":0, # price at which the order got executed\n      \"orig_qty\":5e-05, # quantity at which order was placed\n      \"executed_qty\":0, # quantity that got executed\n      \"status\":\"OPEN\",\n      \"side\":\"SELL\",\n      \"exchange\":\"coinswitchx\",\n      \"order_source\":\"API_TRADING\",\n      \"created_time\":1689661638000, # time stamp in mili seconds \n      \"updated_time\":1689661639000   # time stamp in mili seconds\n   }\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Status Details:<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>OPEN: Order is in open state and not executed at all.&nbsp;<\/li>\n\n\n\n<li>PARTIALLY_EXECUTED: The order is executed partially and the order is still open<\/li>\n\n\n\n<li>CANCELED: The user has canceled the order.<\/li>\n\n\n\n<li>EXECUTED: The order was Executed in the exchange.<\/li>\n\n\n\n<li>EXPIRED: The order expired.<\/li>\n\n\n\n<li>DISCARDED: Order cannot be processed. (It is not placed on the exchange)<\/li>\n<\/ul>\n\n\n\n<p>If you get the EXECUTED response, it means your trade was successfully executed. Hurry! It is time to celebrate as you have made your first API trading transaction. You are now an API trader and you will not pay any commission on your trades for the first 30 days. So make the most of this, but do proper research as cryptos are unregulated products and thus can be risky.&nbsp;<\/p>\n\n\n\n<p><strong>Error Response<\/strong><\/p>\n\n\n\n<p>Alas, if you get any of the below responses, it means your trade wasn&#8217;t successful. You will have to go through the error message to figure out what went wrong and rectify it.<br><br>You can execute the trade again after addressing the issue.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Status Code: 422\n{&nbsp;\n\n\"message\": \"Input price must be of type number\"\n\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Status Code: 400\n{&nbsp;\n\n\"message\": \"Amount is more than available balance\"&nbsp;\n\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Status Code: 401\n{&nbsp;\n\n\"message\": \"Invalid access\"&nbsp;\n\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>There is a lot more to API trading than just executing trades. We recommend that you go through our <a href=\"https:\/\/api-trading.coinswitch.co\/#streamline-your-trading-experience\">API trading <\/a><a href=\"https:\/\/api-trading.coinswitch.co\/#streamline-your-trading-experience\" target=\"_blank\" rel=\"noreferrer noopener\">Documentation<\/a> to know the code to perform tasks like:<br><br><a href=\"https:\/\/api-trading.coinswitch.co\/#create-order\" target=\"_blank\" rel=\"noreferrer noopener\">Cancelling an order<br><\/a><a href=\"https:\/\/api-trading.coinswitch.co\/#portfolio\" target=\"_blank\" rel=\"noreferrer noopener\">Checking your Portfolio<br><\/a><a href=\"https:\/\/api-trading.coinswitch.co\/#open-orders\" target=\"_blank\" rel=\"noreferrer noopener\">Checking all your open orders<\/a><br><a href=\"https:\/\/api-trading.coinswitch.co\/#candles\" target=\"_blank\" rel=\"noreferrer noopener\">Getting Candlestick Data<\/a> of a coin on an exchange and much more.&nbsp;<br><\/p>\n\n\n\n<p><a href=\"https:\/\/coinswitch.co\/pro\/api-trading\" target=\"_blank\" rel=\"noreferrer noopener\">CoinSwit<\/a><a href=\"https:\/\/coinswitch.co\/pro\/api-trading\">ch Pro\u2019s API trading<\/a> facility offers a number of functionalities and is very easy to use. We recommend that you spend some time with this product to familiarize yourself with its working to make the most of API trading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>API trading or Application Programming Interface trading is a technique to automate the trading process. While extremely useful and popular, API trading involves using basic coding in languages like Python and Java, which can be a bit confusing for users who are trying API trading for the first time. Yes, manual trading is a good [&hellip;]<\/p>\n","protected":false},"author":122,"featured_media":37875,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_ayudawp_aiss_exclude":false,"footnotes":""},"categories":[460],"tags":[13987,14124],"class_list":["post-37871","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-crypto","tag-api-trading","tag-api-trading-environment-set-up"],"acf":{"youtube_vodeo_url":"","seo":{"title":"","keywords":"","description":"","canonical":""},"blog_banner_image":false,"blog_coin":false,"download_the_app":{"button_value":"","button_url":""},"twitter_card":{"twitter_title":"","twitter_description":"","twitter_link":""},"maturity_tag":"","post_author":false,"guest_author":false,"hide_toc":false,"select_disclaimer":"Disclaimer: Crypto products and NFTs are unregulated and can be highly risky. There may be no regulatory recourse for any loss from such transactions. The information provided in this post is not to be considered investment\/financial advice from CoinSwitch. Any action taken upon the information shall be at the user\u2019s risk.","key_takeways":false},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/coinswitch.co\/switch\/wp-json\/wp\/v2\/posts\/37871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coinswitch.co\/switch\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coinswitch.co\/switch\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coinswitch.co\/switch\/wp-json\/wp\/v2\/users\/122"}],"replies":[{"embeddable":true,"href":"https:\/\/coinswitch.co\/switch\/wp-json\/wp\/v2\/comments?post=37871"}],"version-history":[{"count":14,"href":"https:\/\/coinswitch.co\/switch\/wp-json\/wp\/v2\/posts\/37871\/revisions"}],"predecessor-version":[{"id":37971,"href":"https:\/\/coinswitch.co\/switch\/wp-json\/wp\/v2\/posts\/37871\/revisions\/37971"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coinswitch.co\/switch\/wp-json\/wp\/v2\/media\/37875"}],"wp:attachment":[{"href":"https:\/\/coinswitch.co\/switch\/wp-json\/wp\/v2\/media?parent=37871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coinswitch.co\/switch\/wp-json\/wp\/v2\/categories?post=37871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coinswitch.co\/switch\/wp-json\/wp\/v2\/tags?post=37871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}