---
title: /convertInExchange
slug: convertinexchange
createdAt: 2024-01-09T12:30:00.567Z
---

{
  "id": "DS1SAIIEuP-LYAxGu4knp",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "http://1.1.1.1/convertInExchange",
    "servers": [
      {
        "url": "http://1.1.1.1/convertInExchange"
      }
    ],
    "name": "",
    "description": "<ul>\n<li>\n<p>This function is used to swap a specified amount of one cryptocurrency to another on a given exchange.</p>\n</li>\n<li>\n<p>return - return markets for swapped coin</p>\n</li>\n</ul>\n<p><em><strong>NOTE</strong></em></p>\n<p>The following parameters returned from exchange:</p>\n<ul>\n<li>\"Id\": Order id</li>\n<li>\"Timestamp\":  Timestamp of the convert order.</li>\n<li>\"FromAsset\": The coin swapped from.</li>\n<li>\"ToAsset\": The coin swapped to.</li>\n<li>\"FromAmount\": Amount in the old coin</li>\n<li>\"ToAmount\": The amount that you receive in the <code>ToAsset</code> coin</li>\n<li>\"Status\": (0: OK, 1: PENDING, 2: WAITING_FOR_APPROVAL_FROM_EXCHANGE, 3: FAILED , 4: CANCELED, 5: UNKNOWN)</li>\n</ul>\n<p>example:</p>\n<p>convertInExchange(1, \"okx\", \"ETH\", \"BTC\", \"0.001\")</p>",
    "contentType": "application/json",
    "request": {
      "pathParameters": [],
      "headerParameters": [],
      "queryParameters": [
        {
          "kind": "required",
          "name": "account_id",
          "type": "integer",
          "example": 1,
          "description": "The ID of the account involved in this action",
          "default": 1
        },
        {
          "kind": "required",
          "name": "exchange_name",
          "type": "string",
          "example": "okx",
          "description": "the exchange name",
          "default": "okx"
        },
        {
          "kind": "required",
          "name": "from_coin",
          "type": "string",
          "example": "BTC",
          "description": "Coin to swap from",
          "default": "BTC"
        },
        {
          "kind": "required",
          "name": "to_coin",
          "type": "string",
          "example": "ETH",
          "description": "Coin to swap to",
          "default": "ETH"
        },
        {
          "kind": "required",
          "name": "amount",
          "type": "string",
          "example": "0.001",
          "description": "<p>How many from_coin to swap</p>\n<ul>\n<li>NOTE: Amount of from_coin is in currency units (e.g. BTC/ETH, not satoshi/wei) e.g. for swapping 1.5 BTC to ETH:\nconvertInExchange(1, \"okx\", \"BTC\", \"ETH\", 1.5)</li>\n</ul>",
          "default": "0.001"
        }
      ],
      "bodyDataParameters": [
        {
          "kind": "optional",
          "name": "body",
          "type": "object",
          "customType": "convertInExchangeRequest",
          "schema": [
            {
              "name": "FunctionData",
              "kind": "optional",
              "type": "object",
              "example": "",
              "schema": [
                {
                  "name": "account_id",
                  "kind": "optional",
                  "type": "integer",
                  "description": "The ID of the account involved in this action",
                  "example": 1,
                  "default": 1
                },
                {
                  "name": "exchange_name",
                  "kind": "optional",
                  "type": "string",
                  "description": "The name of the exchange",
                  "example": "binance",
                  "default": "binance"
                },
                {
                  "name": "from_coin",
                  "kind": "optional",
                  "type": "string",
                  "description": "The source coin",
                  "example": "eth",
                  "default": "eth"
                },
                {
                  "name": "to_coin",
                  "kind": "optional",
                  "type": "string",
                  "description": "The target coin",
                  "example": "usdt",
                  "default": "usdt"
                },
                {
                  "name": "amount",
                  "kind": "optional",
                  "type": "string",
                  "description": "The amount to be transferred",
                  "example": "0.001",
                  "default": "0.001"
                }
              ]
            },
            {
              "name": "Meta",
              "kind": "optional",
              "type": "object",
              "modelRef": "#/components/schemas/MetaTokenconvertInExchange",
              "customType": "MetaTokenconvertInExchange",
              "schema": [
                {
                  "name": "FunctionName",
                  "kind": "optional",
                  "type": "string",
                  "description": "The Function to be called",
                  "example": "convertInExchange",
                  "default": "convertInExchange"
                },
                {
                  "name": "RandomData",
                  "kind": "optional",
                  "type": "string",
                  "description": "Random Data",
                  "example": "288cd49d4b8bf00e7d6114b78d5668d5581d6b953fafef779133caa844cd4229",
                  "default": "288cd49d4b8bf00e7d6114b78d5668d5581d6b953fafef779133caa844cd4229"
                },
                {
                  "name": "Destination",
                  "kind": "optional",
                  "type": "string",
                  "description": "Id of the server",
                  "example": "",
                  "default": "b9cb8afe52f1d52521cf2b62dfe12146156ad5328f83c62c20c7da81b263356a61340de745c858998544c041798b01c2f4fac31bebe52a19280a32cd57d6d374ea"
                },
                {
                  "name": "Time",
                  "kind": "optional",
                  "type": "string",
                  "description": "UTC Time of execution",
                  "example": "2021-02-07T18:37:46.948Z",
                  "default": "2021-02-07T18:37:46.948Z"
                },
                {
                  "name": "Source",
                  "kind": "optional",
                  "type": "string",
                  "description": "User public key",
                  "example": "",
                  "default": "048b99461a70a49abe63fd585cb224177a22a92d2e9e4ddfbc0027887bee9d1843388f42a3eb2e740565e115ad8b7981abf59e3b03b771f4b063b53c517d7a9d99"
                },
                {
                  "name": "AccessToken",
                  "kind": "optional",
                  "type": "string",
                  "description": "Token used for authentication purposes",
                  "example": "51311c84d2c8fd2fafbe56ceb1fb30a99d3417abfc55769577338ab286798087",
                  "default": "51311c84d2c8fd2fafbe56ceb1fb30a99d3417abfc55769577338ab286798087"
                }
              ]
            }
          ],
          "modelRef": "#/components/schemas/convertInExchangeRequest",
          "isExpanded": true
        }
      ],
      "formDataParameters": [],
      "oAuthParameters": []
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "success",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "customType": "convertInExchangeResponse",
            "schema": [
              {
                "name": "FunctionData",
                "kind": "optional",
                "type": "object",
                "example": "",
                "schema": [
                  {
                    "name": "Message",
                    "kind": "optional",
                    "type": "number",
                    "description": "A numeric message",
                    "example": 1547.9,
                    "default": 1547.9
                  },
                  {
                    "name": "Status",
                    "kind": "optional",
                    "type": "boolean",
                    "description": "A boolean status indicating success",
                    "example": "true",
                    "default": "true"
                  }
                ]
              },
              {
                "name": "Meta",
                "kind": "optional",
                "type": "object",
                "modelRef": "#/components/schemas/MetaResponse",
                "customType": "MetaResponse",
                "schema": [
                  {
                    "name": "AccessToken",
                    "kind": "optional",
                    "type": "string",
                    "description": "The new access token generated after this operation",
                    "example": "a3e816b5bc04302d99da94705ec2309a4a63fe10d6aed3c5f6fc9e7ff27c6be6",
                    "default": "a3e816b5bc04302d99da94705ec2309a4a63fe10d6aed3c5f6fc9e7ff27c6be6"
                  },
                  {
                    "name": "Destination",
                    "kind": "optional",
                    "type": "string",
                    "description": "Id of the server",
                    "example": "042c671aeb148d9b2bb4918399c4c925f3764248c5ab2d5194ab0f32664132834692699a75e7fafb5af35f183b7d8a68bdc3b3e6ebfaff8ab555b9a3caf8090622",
                    "default": "042c671aeb148d9b2bb4918399c4c925f3764248c5ab2d5194ab0f32664132834692699a75e7fafb5af35f183b7d8a68bdc3b3e6ebfaff8ab555b9a3caf8090622"
                  },
                  {
                    "name": "Source",
                    "kind": "optional",
                    "type": "string",
                    "description": "User public key",
                    "example": "df4b76a23067a9d782d09a7372ed526ec713cf6d771fac4dbdb9610f7af36d570a157eed76986b8e85afde12888d10d10bef461399e490f3d7e4db44cde1b6e355",
                    "default": "df4b76a23067a9d782d09a7372ed526ec713cf6d771fac4dbdb9610f7af36d570a157eed76986b8e85afde12888d10d10bef461399e490f3d7e4db44cde1b6e355"
                  },
                  {
                    "name": "Time",
                    "kind": "optional",
                    "type": "string",
                    "description": "UTC Time of execution",
                    "example": "2021-02-14 09:58:52.320",
                    "default": "2021-02-14 09:58:52.320"
                  }
                ]
              }
            ],
            "modelRef": "#/components/schemas/convertInExchangeResponse",
            "isExpanded": true
          }
        ]
      }
    ],
    "examples": {
      "languages": [
        {
          "id": "example-0-curl",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url 'http://1.1.1.1/convertInExchange?account_id=1&exchange_name=okx&from_coin=BTC&to_coin=ETH&amount=0.001' \\\n     --header 'accept: application/json' \\\n     --header 'content-type: application/json' \\\n     --data '{\n     \"FunctionData\": {\n     \"account_id\": 1,\n     \"exchange_name\": \"binance\",\n     \"from_coin\": \"eth\",\n     \"to_coin\": \"usdt\",\n     \"amount\": \"0.001\"\n     },\n     \"Meta\": {\n     \"FunctionName\": \"convertInExchange\",\n     \"RandomData\": \"288cd49d4b8bf00e7d6114b78d5668d5581d6b953fafef779133caa844cd4229\",\n     \"Destination\": \"b9cb8afe52f1d52521cf2b62dfe12146156ad5328f83c62c20c7da81b263356a61340de745c858998544c041798b01c2f4fac31bebe52a19280a32cd57d6d374ea\",\n     \"Time\": \"2021-02-07T18:37:46.948Z\",\n     \"Source\": \"048b99461a70a49abe63fd585cb224177a22a92d2e9e4ddfbc0027887bee9d1843388f42a3eb2e740565e115ad8b7981abf59e3b03b771f4b063b53c517d7a9d99\",\n     \"AccessToken\": \"51311c84d2c8fd2fafbe56ceb1fb30a99d3417abfc55769577338ab286798087\"\n     }\n     }'"
        },
        {
          "id": "example-1-javascript",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\n\nvar raw = JSON.stringify({\n   \"FunctionData\": {\n      \"account_id\": 1,\n      \"exchange_name\": \"binance\",\n      \"from_coin\": \"eth\",\n      \"to_coin\": \"usdt\",\n      \"amount\": \"0.001\"\n   },\n   \"Meta\": {\n      \"FunctionName\": \"convertInExchange\",\n      \"RandomData\": \"288cd49d4b8bf00e7d6114b78d5668d5581d6b953fafef779133caa844cd4229\",\n      \"Destination\": \"b9cb8afe52f1d52521cf2b62dfe12146156ad5328f83c62c20c7da81b263356a61340de745c858998544c041798b01c2f4fac31bebe52a19280a32cd57d6d374ea\",\n      \"Time\": \"2021-02-07T18:37:46.948Z\",\n      \"Source\": \"048b99461a70a49abe63fd585cb224177a22a92d2e9e4ddfbc0027887bee9d1843388f42a3eb2e740565e115ad8b7981abf59e3b03b771f4b063b53c517d7a9d99\",\n      \"AccessToken\": \"51311c84d2c8fd2fafbe56ceb1fb30a99d3417abfc55769577338ab286798087\"\n   }\n});\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"http://1.1.1.1/convertInExchange?account_id=1&exchange_name=okx&from_coin=BTC&to_coin=ETH&amount=0.001\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "example-2-ruby",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"http://1.1.1.1/convertInExchange?account_id=1&exchange_name=okx&from_coin=BTC&to_coin=ETH&amount=0.001\")\n\nhttp = Net::HTTP.new(url.host, url.port);\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\nrequest.body = JSON.dump({\n   \"FunctionData\": {\n      \"account_id\": 1,\n      \"exchange_name\": \"binance\",\n      \"from_coin\": \"eth\",\n      \"to_coin\": \"usdt\",\n      \"amount\": \"0.001\"\n   },\n   \"Meta\": {\n      \"FunctionName\": \"convertInExchange\",\n      \"RandomData\": \"288cd49d4b8bf00e7d6114b78d5668d5581d6b953fafef779133caa844cd4229\",\n      \"Destination\": \"b9cb8afe52f1d52521cf2b62dfe12146156ad5328f83c62c20c7da81b263356a61340de745c858998544c041798b01c2f4fac31bebe52a19280a32cd57d6d374ea\",\n      \"Time\": \"2021-02-07T18:37:46.948Z\",\n      \"Source\": \"048b99461a70a49abe63fd585cb224177a22a92d2e9e4ddfbc0027887bee9d1843388f42a3eb2e740565e115ad8b7981abf59e3b03b771f4b063b53c517d7a9d99\",\n      \"AccessToken\": \"51311c84d2c8fd2fafbe56ceb1fb30a99d3417abfc55769577338ab286798087\"\n   }\n})\n\nresponse = http.request(request)\nputs response.read_body\n"
        },
        {
          "id": "example-3-python",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"http://1.1.1.1/convertInExchange?account_id=1&exchange_name=okx&from_coin=BTC&to_coin=ETH&amount=0.001\"\n\npayload = json.dumps({\n   \"FunctionData\": {\n      \"account_id\": 1,\n      \"exchange_name\": \"binance\",\n      \"from_coin\": \"eth\",\n      \"to_coin\": \"usdt\",\n      \"amount\": \"0.001\"\n   },\n   \"Meta\": {\n      \"FunctionName\": \"convertInExchange\",\n      \"RandomData\": \"288cd49d4b8bf00e7d6114b78d5668d5581d6b953fafef779133caa844cd4229\",\n      \"Destination\": \"b9cb8afe52f1d52521cf2b62dfe12146156ad5328f83c62c20c7da81b263356a61340de745c858998544c041798b01c2f4fac31bebe52a19280a32cd57d6d374ea\",\n      \"Time\": \"2021-02-07T18:37:46.948Z\",\n      \"Source\": \"048b99461a70a49abe63fd585cb224177a22a92d2e9e4ddfbc0027887bee9d1843388f42a3eb2e740565e115ad8b7981abf59e3b03b771f4b063b53c517d7a9d99\",\n      \"AccessToken\": \"51311c84d2c8fd2fafbe56ceb1fb30a99d3417abfc55769577338ab286798087\"\n   }\n})\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "example-0-curl"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "// success\n{\n  \"FunctionData\": {\n    \"Message\": 1547.9,\n    \"Status\": \"true\"\n  },\n  \"Meta\": {\n    \"AccessToken\": \"a3e816b5bc04302d99da94705ec2309a4a63fe10d6aed3c5f6fc9e7ff27c6be6\",\n    \"Destination\": \"042c671aeb148d9b2bb4918399c4c925f3764248c5ab2d5194ab0f32664132834692699a75e7fafb5af35f183b7d8a68bdc3b3e6ebfaff8ab555b9a3caf8090622\",\n    \"Source\": \"df4b76a23067a9d782d09a7372ed526ec713cf6d771fac4dbdb9610f7af36d570a157eed76986b8e85afde12888d10d10bef461399e490f3d7e4db44cde1b6e355\",\n    \"Time\": \"2021-02-14 09:58:52.320\"\n  }\n}"
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "children": [
    {
      "id": "4YrBWYfM49Y9uvvPbIlsr",
      "type": "bulleted-list",
      "children": [
        {
          "id": "bLfMC7jj7WfL6_pMCkn9L",
          "type": "list-item",
          "children": [
            {
              "id": "zGmHavF4JD6fgEM9uiVpA",
              "type": "list-item-child",
              "children": [
                {
                  "text": "This function is used to swap a specified amount of one cryptocurrency to another on a given exchange.",
                  "id": "LwfZksPBJdwg87xSQLmqK"
                }
              ]
            }
          ]
        },
        {
          "id": "vH2B335D6lnHTiDwMOSDD",
          "type": "list-item",
          "children": [
            {
              "id": "wGlXlpaAqB1RZLJloCo2S",
              "type": "list-item-child",
              "children": [
                {
                  "text": "return - return markets for swapped coin",
                  "id": "ggTOX8CZtrhLIZy6PAT_c"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "id": "1Izf1rSwQHsWUflpNlDc4",
      "type": "paragraph",
      "children": [
        {
          "text": "NOTE",
          "bold": true,
          "italic": true,
          "id": "dfq3Txmf1z3sdns0vimvD"
        }
      ]
    },
    {
      "id": "zwCACoqE7nY3-uhKSglcA",
      "type": "paragraph",
      "children": [
        {
          "text": "The following parameters returned from exchange:",
          "id": "OqdmPqNCMyD4HlixOSw36"
        }
      ]
    },
    {
      "id": "amrTSk5GhW9SvwPQjhJkg",
      "type": "bulleted-list",
      "children": [
        {
          "id": "yavJJey1972nVISrcbynL",
          "type": "list-item",
          "children": [
            {
              "id": "VjE8oneNyeMVohgasemI8",
              "type": "list-item-child",
              "children": [
                {
                  "text": "\"Id\": Order id",
                  "id": "QoOmHJ90bBXluwLAgXUai"
                }
              ]
            }
          ]
        },
        {
          "id": "zr4xC2KZRlDxVdMxFi0LC",
          "type": "list-item",
          "children": [
            {
              "id": "p9CNuRnLTgQDe-QqVenV-",
              "type": "list-item-child",
              "children": [
                {
                  "text": "\"Timestamp\":  Timestamp of the convert order.",
                  "id": "4aqozJsZ8xDIsoWGpfuoy"
                }
              ]
            }
          ]
        },
        {
          "id": "VN_Q9xRBAQ-lVXuXYTcYX",
          "type": "list-item",
          "children": [
            {
              "id": "io6O32dBp2HrA2e6JCAe7",
              "type": "list-item-child",
              "children": [
                {
                  "text": "\"FromAsset\": The coin swapped from.",
                  "id": "twT_37hhIy23JDkNJxSzJ"
                }
              ]
            }
          ]
        },
        {
          "id": "rYdDqC2Dp6wzEzf0dUrLs",
          "type": "list-item",
          "children": [
            {
              "id": "1VXIlTI8MDx_HfRtC69Eg",
              "type": "list-item-child",
              "children": [
                {
                  "text": "\"ToAsset\": The coin swapped to.",
                  "id": "_YRZdT0noD7bU9SMR1WTc"
                }
              ]
            }
          ]
        },
        {
          "id": "nAFx44vAUokeMleH--W-L",
          "type": "list-item",
          "children": [
            {
              "id": "pyyw2uQEj4fvlFvH3Env9",
              "type": "list-item-child",
              "children": [
                {
                  "text": "\"FromAmount\": Amount in the old coin",
                  "id": "h0uT8xg9VbHHIa3ki4N6o"
                }
              ]
            }
          ]
        },
        {
          "id": "Q2gd7vp15KJkwh0V1R4nO",
          "type": "list-item",
          "children": [
            {
              "id": "38YvTXbuvcFH4SLEaSnwW",
              "type": "list-item-child",
              "children": [
                {
                  "text": "\"ToAmount\": The amount that you receive in the ",
                  "id": "edXUje3RtWZ9-xiLxMR-4"
                },
                {
                  "text": "ToAsset",
                  "highlight": true,
                  "id": "F9o8dPq0R4PENW9a00jSU"
                },
                {
                  "text": " coin",
                  "id": "x3VFjy7_k_-3xbqr6bCih"
                }
              ]
            }
          ]
        },
        {
          "id": "PYl6KsWE2FM_SMSQGiMT-",
          "type": "list-item",
          "children": [
            {
              "id": "ATDtVZxVkzSRzdI-_pzGZ",
              "type": "list-item-child",
              "children": [
                {
                  "text": "\"Status\": (0: OK, 1: PENDING, 2: WAITING_FOR_APPROVAL_FROM_EXCHANGE, 3: FAILED , 4: CANCELED, 5: UNKNOWN)",
                  "id": "8a8hFp2Hol98FjSiV1lGW"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "id": "PA9qMuUdaQ2KHBftV5PA-",
      "type": "paragraph",
      "children": [
        {
          "text": "example:",
          "id": "eMkxeay-_cIjYU0XRC_KJ"
        }
      ]
    },
    {
      "id": "mMNm7w9eJPj2ExzjEFGOd",
      "type": "paragraph",
      "children": [
        {
          "text": "convertInExchange(1, \"okx\", \"ETH\", \"BTC\", \"0.001\")",
          "id": "qBWpJp8E4Ay_ZtZ-ThSwz"
        }
      ]
    }
  ]
}