.

Binance API


Reading time: about 1 minute

Binance has APIs for both fetching public data and for executing trades.

Data API

https://data-api.binance.vision/api

Testnet / Sandbox

Binance has a testnet/sandbox thing for writing your API code without touching your real account.

It is located at https://testnet.binance.vision/.

Authentication

You need an API key and a secret key. HMAC-SHA256 is used for signing the HTTP requests.

Here is a dotnet code snippet I’ve used for this before.

private static long Millis()
{
    return DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
}

private static string SignUrl(string url)
{
    var qry = new UriBuilder(url).Query;

    if (!string.IsNullOrEmpty(qry))
        qry += "&";

    qry += $"timestamp={Millis()}";

    var key = GlobalHost.Config["Binance:HmacSha256SecretKey"];

    using var hmacCalculator = new HMACSHA256(Encoding.UTF8.GetBytes(key));
    var hmacBytes = hmacCalculator.ComputeHash(Encoding.UTF8.GetBytes(qry));
    var hmacHex = BitConverter.ToString(hmacBytes).Replace("-", string.Empty).ToLower();
    qry += $"&signature={hmacHex}";

    return new UriBuilder(url) { Query = qry }.ToString();
}

internal static async Task<HttpResponseMessage> GetAsync(string url)
{
    var signedUrl = SignUrl(url);
    var apiKey = GlobalHost.Config["Binance:HmacSha256ApiKey"];

    using var req = new HttpRequestMessage(HttpMethod.Get, signedUrl);
    req.Headers.Add("X-MBX-APIKEY", apiKey);
    var resp = await HttpClient.Instance.SendAsync(req).ConfigureAwait(false);

    return resp;
}

Resources

Some API docs

  • https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md
  • https://binance-docs.github.io/apidocs/spot/en/

The following pages link here

Citation

If you find this work useful, please cite it as:
@article{yaltirakli,
  title   = "Binance API",
  author  = "Yaltirakli, Gokberk",
  journal = "gkbrk.com",
  year    = "2025",
  url     = "https://www.gkbrk.com/binance-api"
}
Not using BibTeX? Click here for more citation styles.
IEEE Citation
Gokberk Yaltirakli, "Binance API", February, 2025. [Online]. Available: https://www.gkbrk.com/binance-api. [Accessed Feb. 04, 2025].
APA Style
Yaltirakli, G. (2025, February 04). Binance API. https://www.gkbrk.com/binance-api
Bluebook Style
Gokberk Yaltirakli, Binance API, GKBRK.COM (Feb. 04, 2025), https://www.gkbrk.com/binance-api

Comments

© 2025 Gokberk Yaltirakli