Crypto Tutorials: Binance | Bitfinex | Bitmex | BscScan | Cardano | Coinbase | Coingecko | Coinmarketcap | CoinAPI | Coinranking | Etherscan | | Glassnode | Huobi | LiveCoinWatch | Kraken | Kucoin | Magic Eden | Messari | Nomics | OpenSea | PancakeSwap | Rarible | Rarify | Solanart


    How to connect Binance to Google Sheets

    Binance is one of the world’s most popular cryptocurrency exchanges, and their API is one of the most popular crypto exchange APIs. If you haven’t signed up for Binance yet, click here to sign up and register a new account.

    We can use Binance’s API to import data from Binance into Google Sheets. In this tutorial, you’ll learn how to connect the Binance REST API to Google Sheets in 5 steps using the Apipheny API add-on:

    1. Install the Apipheny Add-on
    2. Choose your Binance API endpoint
    3. Enter your Binance API request into Apipheny

    Step 1.) Install and open the Apipheny add-on for Google Sheets

    Apipheny is a free API connector for Google Sheets. You can use Apipheny to connect your Google Sheets to API data sources, easily.

    1.) Install Apipheny by opening the following link on desktop and then clicking the Install button in the Google Marketplace: https://apipheny.io/install

    2.) After you’ve installed Apipheny, open a Google Sheet and then click on the Extensions dropdown in the menu at the top.

    In the dropdown list you should see Apipheny. Click Apipheny then click Import API to open the Apipheny sidebar in your Google Sheet.

    open apipheny

    Tip: you can open a new Google Sheet by entering this URL in your browser: sheet.new

    Step 2.) Choose a Binance API endpoint

    An endpoint is an API URL that returns the specific data you want from Binance. In this section we show you how to browse the Binance API documentation to find the URL that returns the specific data you need. If you’d like to see specific examples of URLs you can use, just skip to the next section.

    To browse endpoint URLs and query requirements, go the Binance API documentation page here: https://binance-docs.github.io/apidocs/spot/en/#general-info

    All Binance endpoint URLs are created by appending an endpoint-specific path to the root URL:

    https://api.binance.com

    If you are experiencing problems with the above API root, please use an alternate as outlined in the general API information section of the official Binance documentation.

    In this tutorial, we will discuss two types of endpoints available from the Binance API:

    1. Endpoints that do not require authentication (Public endpoints)
    2. Endpoints that do require authentication (Signed endpoints)

    This tutorial covers how to use the public endpoints that do not require authentication. The only category from the Binance API documentation that has public endpoints which require no API key is the Market Data Endpoints: https://binance-docs.github.io/apidocs/spot/en/#market-data-endpoints

    Signed Binance API endpoints that require HMAC SHA256 will not currently work with Apipheny, but endpoints that do not require HMAC SHA256 will work. Some Binance API endpoints require HMAC SHA256 and others don't. The reason signed endpoints don't currently work with our app is because they require an additional parameter called signature, a keyed HMAC SHA256 signature with your secretKey as the key, and a concatenation of all the query’s parameters as the value passed to the HMAC operation. Signed endpoints also require a timeStamp parameter, populated with the request’s millisecond timestamp. You can tell if an endpoint is signed or not because when you look at the documentation for that endpoint, it will say (HMAC SHA256) next to the URL, as seen in the screenshot below:

    Once you’ve looked through the Binance API documentation and chosen a public endpoint you want to use, you can go ahead and enter the URL into Apipheny and run your request. In the next section we cover making a request in more detail along with some example requests.

    All time and timestamp related fields are in milliseconds. You can use https://timestamp.online/ to convert the date you want into milliseconds.

    Step 3.) Enter your Binance API request into Apipheny

    In this section we will show you some example requests using the public endpoints. Public endpoints can be accessed without an API key. In the section above we discussed how to determine whether an endpoint is public or not.

    The only category from the Binance API documentation that has public endpoints which require no API key is the Market Data Endpoints: https://binance-docs.github.io/apidocs/spot/en/#market-data-endpoints

    Market Data Endpoints Category
    Market Data Endpoints Category

    An example public endpoint is Symbol Price Ticker, which gets the latest price for one or multiple symbols. It uses the GET method and the URL for this endpoint is:

    https://api.binance.com/api/v3/ticker/price

    To use this endpoint or any other public endpoint, just copy and paste the URL into the Apipheny add-on, then click the Run button at the bottom of the add-on and the data will be imported into your Google Sheet, like so:

    Symbol Price Ticker Endpoint
    Symbol Price Ticker Endpoint

    More public endpoint examples

    The Check Server Time endpoint tests connectivity to the Rest API and gets the current server time. The URL for this endpoint is:

    Method: GET
    API URL: https://api.binance.com/api/v3/time

    The Order Book endpoint provides a listing of the ongoing orders in the system. The URL for this endpoint is:

    Method: GET
    API URL: https://api.binance.com/api/v3/depth?symbol=your_symbol

    When using this endpoint, don’t forget to replace your_symbol with an actual symbol.


    The Symbol Order Book Ticker endpoint gets the latest orders for one or multiple symbols. The URL for this endpoint is:

    Method: GET
    API URL: https://api.binance.com/api/v3/ticker/bookTicker

    The Recent Trades List endpoint returns a list of most recent trades on the platform. The URL for this endpoint is:

    Method: GET
    API URL: https://api.binance.com/api/v3/trades?symbol=your_symbol 

    Don’t forget to replace your_symbol with an actual symbol.


    The Compressed/Aggregate Trades List endpoint that gets compressed, aggregate trades. Trades that fill at the time, from the same order, with the same price will have the quantity aggregated.

    Method: GET
    API URL: https://api.binance.com/api/v3/aggTrades

    The 24hr Ticker Price Change Statistics endpoint that gets 24 hour rolling window price change statistics. Careful when accessing this with no symbol.

    Method: GET
    API URL Path: https://api.binance.com/api/v3/ticker/24hr

    Authenticated endpoints

    There are currently 1 or more endpoints that require an API key but they don’t require HMAC SHA256 which means they will work with Apipheny. To obtain an API key, follow the instructions below. If you already have your key you can skip this section.

    1. After logging in to your Binance account, click API Management in the user center drop-down box:

    Binance Account Dashboard
    Binance Account Dashboard

    2. If you did not install 2-factor authentication (2FA) when creating your Binance account, you will be asked to do add 2FA at this point:

    Choose Between Google Authentication and SMS Authentication
    Choose Between Google Authentication and SMS Authentication

    In this example I chose SMS Authentication. Click the Send SMS button to receive a code on your mobile phone. After you have received the code, enter it in the SMS Verification Code section. You can also choose Google Authentication, which is more secure. After you add 2FA, this popup will disappear and you can continue obtaining your API key.

    Two-Factor Authentication
    Two-Factor Authentication

    3. When the API management page finally opens, enter a name (label) for your private API key, and then click the Create button:

    Create a Label For Your API Key
    Create a Label For Your API Key

    4. Next, fill in the Google Authentication Code or SMS Authentication Code again, to confirm the API Key creation for your account:

    SMS or Google Authentication Code
    SMS or Google Authentication Code

    5. Once you have passed the 2FA Authentication, the system will send a confirmation email to the email address of your Binance account. You can go directly to your email or click the Go to email and verify button on the Binance page:

    Confirmation Email
    Confirmation Email

    6. In the email, click the Confirm new API key button:

    API Key Confirmation
    API Key Confirmation

    7. On the next page you will see your API key and Secret key. Remember to copy and paste your Secret Key somewhere safe, as it will not be shown again, due to security reasons. If you forget the Secret Key, you will need to delete the API key and then create a new one.

    API Key and Secret Key Section
    API Key and Secret Key Section

    Now that you have your API key, you can enter your API request into Apipheny.

    After you’ve found the endpoint you need, copy the complete URL into the API URL Path field in the Apipheny add-on.

    Here’s an example endpoint that requires an API key:

    https://api.binance.com/sapi/v1/margin/allPairs

    After you enter your URL into Apipheny, you’ll need to enter a couple headers.

    In the Headers section of Apipheny, add two rows with the following keys and values:

    Header 1 Key:
    Accept
    Header 1 Value: 
    application/json
    
    Header 2 Key:
    X-MBX-APIKEY
    Header 2 Value:
    your-API-key

    your-API-key is the value you got in the steps we covered above.

    Here’s what your API request should look like with the API URL and headers entered in Apipheny:

    Insert the API URL and Headers Into Apipheny
    Insert the API URL and Headers Into Apipheny

    Once you have the URL and headers entered, the last step is to click the Run button at the bottom of the Apipheny add-on and then wait for the Binance API data to be imported into your Google Sheet.

    Binance API Data in Google Sheets
    Binance API Data in Google Sheets

    More authenticated endpoint examples

    The Query Margin Asset (MARKET_DATA) endpoint:

    Method: GET
    API URL Path: https://api.binance.com/sapi/v1/margin/asset
    Headers:
        Header 1 Key:
           X-MBX-APIKEY
        Header 1 Value:
           your-API-key

    Make sure to replace your-API-key with the API key you previously obtained.


    The Query Cross Margin Pair endpoint:

    Method: GET
    API URL Path: https://api.binance.com/sapi/v1/margin/pair
    Headers:
        Header 1 Key:
           X-MBX-APIKEY
        Header 1 Value:
           your-API-key

    Make sure to replace your-API-key with the API key you previously obtained.