Introduction

Learn to understand and use API for cryptocurrency trading to gain numerous opportunities for entering and exiting positions. Even basic coding knowledge is enough to connect to the exchange server and automate trading strategies. By scraping the website, you can access the order matching tool for high-performance applications much faster.

The goal of this series is to introduce you to and teach you how to work with the Binance REST API. After reading the articles, you will be able to confidently request information about markets and positions, as well as place various types of orders.

In this article, we will use Postman to connect to the exchange. Don't worry — we won't risk real funds.


Prerequisites

Testnet Keys

For our purposes, we will use the test network. This will allow us to experiment with funds that have no real-world value. They work just like real coins and tokens, so after studying this article, you will be able to use the API for trading real funds.


  1. To get started, go to the spot test network.

  2. To access, log in to your GitHub account. Create an account if you don't have one.

  3. Click Authenticate and log in via GitHub.

  4. In the API keys section, you will see a message about the absence of registered keys. Click Generate HMAC_SHA256 Key.

  5. Then assign any label to the keys and click Generate.

  6. You will receive an API key and a secret key. It is important to write them down immediately. Otherwise, you will have to start the key generation process over again. We recommend storing the API key and secret key in a notes app for easy copying and pasting.

Note: When using a real exchange, it is advisable to label keys to manage them more easily. There can be multiple keys with different permissions in an account. If you are using multiple trading bots, keys with descriptive labels simplify permission management and the removal of keys without affecting all bots.


Loading and Installing Postman

Postman is a platform for interacting with APIs. It is the perfect starting point: it provides access to the Binance request collections that can be tested without writing any code.

The program is available on Mac, Windows, and Linux. Go to the download page and download the zip file.

After that, find it in the explorer and install it. Launch the application — and you can get started! You can optionally create an account to log in. To skip this step, choose the corresponding option at the bottom of the window.


Creating an Environment

At this stage, you should have a similar interface in front of you.



First, you need to create an environment to add variables to the set of requests we will work with. To do this, you need to get some information from the Binance repository on GitHub. Go to this link and download the zip file.



The download won't take long. Find the file in the explorer and extract it. Then return to Postman.



Click on the settings icon in the upper right corner, as shown in the image above. A pop-up window for managing environments will appear.

  1. Click Import and navigate to the folder you just extracted (binance-postman-api).

  2. Open it, then open the environments folder.

  3. There will be two files (one for the main network and one for the test network). We need binance_com_spot_testnet_api.postman_environment.json. Make sure to select the correct file, as otherwise the keys will not work.



Almost ready. Click Binance Spot Testnet API. You will see variables, as in the image below. Insert the previously saved keys into the two parameters highlighted in red. Click Update and close this window.



Leave the timestamp and signature fields empty. These values will be automatically generated with each request.

Just a little more to go. To the right of the settings icon we clicked to configure the environment, there is a dropdown menu labeled No Environment. Click on it and select Binance Spot Testnet API.


Importing a Collection

Now we need to import a collection — a comprehensive set of requests that will do the heavy lifting for us when we make a call. To load the collection into the environment:

  1. Click Import in the upper left corner.

  2. In the pop-up window on the File tab, select Upload Files.

  3. Find the binance-postman-api folder and open it.

  4. This time, go into the collections folder.

  5. There will be two files. One is for working with the futures API, the other is for the spot API. We need the spot one, so select the file binance_spot_api_v1.postman_collection.json.

  6. A confirmation window will appear on the screen, indicating that the import is being done in Postman Collection format. Click Import.

On the Import tab, a folder with more than 100 requests will appear on the left. Congratulations, you can now get started! In the next section, we will look at different types of requests.


Making Requests

If you expand the folders in the Collections tab, you will see many available requests. Three types of methods that can be used are highlighted in different colors:


  • GET: The GET method is used to retrieve data from the server. This method will help find information about account balances, asset prices, and so on.

  • POST: Typically, the POST method is used to create information on the server. This method is necessary for placing orders, withdrawal requests, and so on.

  • DELETE: The DELETE method asks the server to remove information. This method will be useful for canceling orders.


Searching for Trading Pairs and Trading Rules

It's time to create your first request! We need to get information about the trading pairs available on the exchange and the trading rules:

GET /exchangeInfo


This request does not require additional parameters — it can be copied and pasted into the address bar to get a response. However, if requests have multiple parameters, Postman makes it easy to view and change them.

To load this request, select Market > Exchange Information. The next tab will open:



Nothing more to do, just click Send. You will receive a response:



In the very top highlighted section, there is important information:

  • response status (200 means success, 400-499 means an error);

  • time to receive a response (less than a second);

  • size of the response (~22 KB).


In the second highlighted section is the main part of the response. The text is presented in a structured way to make it easier to read. It contains information about the exchange as well as the pairs available for trading and their minimum/maximum amounts.

It may seem that there is a lot of information, but this format greatly simplifies the work for programmers. When writing scripts for interaction, it will be easy to find the properties of certain elements.


Checking Account Balance

Let's check what assets we have and how many:

GET /account

The request can be found in the Trade > Account Information section. Click on it — a page similar to the previous one will open. However, there will be two new variables: timestamp and signature. The signature is a security measure. Since you are requesting confidential information, it is necessary to confirm that you are the account owner.

The timestamp informs the server when the request was sent. Due to network failures, the server may receive the request much later than intended. If too much time passes, the request will be rejected. You can specify a preferred wait time with the recvWindow parameter, which defaults to 5000 milliseconds.

Postman generates both fields on behalf of the user. Click Send to get a response. In the balances section, there will be six assets: BNB, BTC, BUSD, ETH, LTC, and TRX. The balance will be divided into available and locked. We haven't locked anything yet, so all assets should be available.

Congratulations on your (non-existent) wealth!


How to Check the Current Price of a Trading Pair

You can find out the current price of an asset in various ways. The simplest is to use the following request:

GET /api/v3/ticker/24hr

This request provides information about asset prices over the last 24 hours. Find it in the Market > 24hr Ticker Price Change Statistics section. By default, the trading pair is BTCUSDT.

You can send the request right away to see detailed price information. You can also change the trading pair (to BNBBUSD, LTCUSDT, and others) or uncheck the variable to get data for 40 pairs.

There is also a simpler request, Market > Symbol Price Ticker, which shows the current price of the asset:

GET /api/v3/price

As in the previous case, you can change the trading pair variable or remove it altogether and get the last price for all pairs.


Checking the Current Depth of the Order Book

The order book depth (also known as market depth or DOM) can tell you a lot about the market. To get useful information, you need to make the request:

GET api/v3/depth

When we send it with default values (Market > Order Book), we receive a response with bid prices and ask prices for BTCUSDT. The test network server does not provide as much data as the real network server, so below is a screenshot of what can be seen in the real environment:



In the highlighted section above, the first bid price is indicated. Since we are looking at the BTCUSDT book, the top number is the price someone is willing to pay for your BTC. Below is the amount that this user wants to buy. So, the order requests 0.999 BTC at a rate of 9704.65 USDT per BTC. The offer price decreases further: lower down the list are buyers who want to pay less.

The top offer will be the most advantageous. However, if you are trying to sell, for example, 3 BTC, you will only be able to sell 0.999 BTC at the best price. You will have to accept the next (cheaper) offers until the order is fully executed.



Below is information about the ask prices. They are similar to the bid prices, except that this section presents orders to sell BTC for USDT.


Placing a Test Order

Now we will place a test order.

POST api/v3/order/test

Although we are using test network funds, this request does not actually place an order. This allows testing orders before they are actually placed. The request is located in the Trade > Test New Order (TRADE) section.



This time, many more parameters are involved. Let's look at the highlighted ones:


  • symbol (trading pair) — we have encountered this before. It is the pair you want to trade.

  • side (action) — here you need to choose BUY or SELL. In the BTCUSDT pair, BUY allows you to buy BTC for USDT, while SELL allows you to sell BTC for USDT.

  • type (type) — the type of order you want to place. Possible values (more details in this link):

    • LIMIT

    • MARKET

    • STOP_LOSS

    • STOP_LOSS_LIMIT

    • TAKE_PROFIT

    • TAKE_PROFIT_LIMIT

    • LIMIT_MAKER

  • timeInForce — this parameter defines how the order will be executed:

    • GTC (good till canceled) — the most popular choice. The order will remain until it is executed or you cancel it.

    • FOK (fill or kill) — FOK instructs the exchange to fill the order immediately and completely. If the exchange cannot do this, the order is canceled immediately.

    • IOC (immediate or cancel) — the order must be executed immediately, either completely or partially. Unlike FOK, orders are not canceled if they can be partially filled.

  • quantity (amount) — the amount of the asset you want to buy or sell.

  • price (price) — the price at which you want to sell. For the BTCUSDT pair, it is expressed in USDT.

  • newClientOrderId — order identifier. This is an optional field, but you can specify an identifier that makes the request easier later. Otherwise, the exchange will generate the ID randomly.

Now let's create a test order. We will use automatically generated values: a limit order to sell 0.1 BTC for USDT at a price of $9000. Click Send. If successful, we will receive {} as a response.

Placing a Real Order

It's time to learn how to place a real order.

POST /api/v3/order

Go to the Trade > New Order section. The parameters here are the same as for test orders. Let's leave all values as they are but change the selling price to $40,000. Adjust the price and click Send.

If successful, you will receive a response with details about the order.


Checking the Status of an Open Order

In the previous section, we already received confirmation that the order was placed, but how do we check it now? There are several requests for this.

GET /api/v3/openOrders

The request is found in the Trade > Current Open Orders (USER_DATA) section. By default, the pair is BTCUSDT. If you click Send, you will receive information about your open orders for BTCUSDT (at this stage, you will only see the one we placed earlier). If no trading pair is specified, you will receive information about all open orders.

GET /api/v3/allOrders

Trade > All Orders (USER_DATA) will give an overview of all orders, not just open ones. Here, you need to specify the trading pair. orderId, startTime, endTime, and limit are optional parameters that will help refine the search. They are not needed now, so uncheck them. Click Send — the same response will appear as before. Closed and canceled orders will also be displayed here if they exist.


Finally, you can request specific orders using:

GET /api/v3/order

The request is in the Trade > Query Order (USER_DATA) section. You need to specify orderId or origClientOrderId (the optional tag 'newClientOrderId' that can be added to orders). Uncheck orderId. For origClientOrderId, we will specify the default tag — 'my_order_id_1'. Fill in the field and click Send.


Cancelling an Order

If after some time the goal of $40,000 seems too optimistic, you can cancel the order. In this case, you need to use:

DELETE /api/v3/order

This request is in the Trade > Cancel Order section, which will allow you to specify orders for cancellation. Uncheck the orderId and newClientOrderId parameters and set the origClientOrderId to 'my_order_id_1'.

After sending the request, you will receive a response with information about the order. If you scroll down to the status section, you can see that it is indeed canceled. To confirm this, use the GET /api/v3/openOrders endpoint again (it will return an empty list) or GET /api/v3/order with origClientOrderId.


Placing an Order with Immediate Execution

The previous limit order was not executed because it would only trigger at the BTC price of $40,000. A market order, on the other hand, allows buying/selling at any current price. It executes immediately.

To do this, let's return to the Trade > New Order section. We will demonstrate the response type (newOrderRespType) — a parameter that can be set based on the desired response. There are three options: ACK, RESULT, or FULL. Examples of each request can be found at this link. We will choose ACK, which simply confirms that the order has been received.

Below you can see that we are about to send a market order to sell BNB for BUSD at the current market price.



Note that the response contains very little information:



You can confirm that the order was executed using /api/v3/allOrders.


Checking Trades

Now let's look at the request to check trades:

GET /api/v3/myTrades

It is located in the Trade > Account Trade List (USER_DATA) section. This request allows checking each trade with a specific trading pair. To see trades with the default trading pair (BTCUSDT), simply uncheck the startTime, endTime, and fromId parameters. The response will include up to 500 trades — change the limit parameter to see more.


Debugging with Postman

In Postman, you can additionally expand the raw HTTP request and response.



This menu will open the Postman console, which will output the details of each request.



Summary

The aim of this guide was to explain how to work with the Binance API without writing any code. Now you know how to request and send information.

In the next parts of this series, we will introduce you to the basic coding concepts that automate the buying and selling of cryptocurrencies and other digital assets.

If you have any questions, visit the Binance developer community or check out the documentation.