ExchangeSharp icon indicating copy to clipboard operation
ExchangeSharp copied to clipboard

ExchangeBinanceAPI.GetCurrencies Async throws collossal exception

Open jdx-john opened this issue 3 years ago • 6 comments

Ive been using this on the kraken exchange API fine but when I tested on Binance, I got an exception that was so giant, I couldn't even find the top of the popup (well done VS for Mac!)

It seems some request got an entire HTML page as a response... is this method believed to be functional?

ExchangeSharp.APIException: <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="format-detection" content="telephone=no,email=no,address=no" />
    <script src="https://bin.bnbstatic.com/static/sensors/[email protected]"></script>
    <title>Binance</title>
    <link rel="shortcut icon" type="image/x-icon" href="https://bin.bnbstatic.com/static/images/common/favicon.ico">
    <style>
      html,
      body {
        font-family: BinancePlex, Arial, PingFangSC-Regular, "Microsoft YaHei",
          sans-serif;
      }
      body {
        margin: 0;
      }
      .not-fount-container {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        flex-direction: column;
        background: #fafafa;
      }
      .not-fount-image {
        width: 340px;
      }
      .not-fount-tips {
        margin-top: 65px;
        display: flex;
        align-items: center;
      }
      .not-fount-tips-bold {
        font-size: 24px;
        line-height: 28px;
        color: #1e2026;
        font-weight: 500;
      }
      .link {
        color: #d0980b;
        font-size: 14px;
        line-height: 20px;
      }
      img {
        width: 100%;
        display: block;
      }
      .not-found-board-logo {
        width: 56px;
      }
      .not-found-board-left {
        display: flex;
      }
      .not-found-board-text {
        margin-left: 16px;
        color: #1e2026;
        font-weight: bold;
        margin-top: 6px;
        font-size: 16px;
      }
      .not-found-board-text-inner {
        display: flex;
      }
      .text-inner-icons {
        margin-left: 16px;
        display: flex;
        align-items: center;
      }
      .text-inner-icons span {
        display: inline-block;
        width: 16px;
        height: 16px;
        margin-right: 10px;
        background-position: center;
        background-repeat: no-repeat;
      }
      .icon-mac {
        background-image: url("https://bin.bnbstatic.com/static/images/electron/macicon.svg");
      }
      .icon-linux {
        background-image: url("https://bin.bnbstatic.com/static/images/electron/linux.svg");
      }
      .icon-windows {
        background-image: url("https://bin.bnbstatic.com/static/images/electron/windows.svg");
      }
      .not-found-board-right {
        margin-top: 6px;
      }
      button {
        padding: 10px 16px;
        border: none;
        outline: none;
        background: linear-gradient(180deg, #f8d12f 0%, #f0b90b 100%);
        border-radius: 4px;
        cursor: pointer;
        font-size: 14px;
        color: #1e2026;
        font-weight: 500;
      }
      @media only screen and (max-device-width: 1024px) {
        .not-found-board {
          display: none;
        }
      }
      @media only screen and (min-device-width: 1025px) {
        .not-found-board {
          background: #ffffff;
          padding: 0 16px;
          height: 80px;
          box-shadow: 0px 0px 1px rgba(20, 21, 26, 0.1),
            0px 3px 6px rgba(71, 77, 87, 0.04),
            0px 1px 2px rgba(20, 21, 26, 0.04);
          border-radius: 4px;
          width: 496px;
          margin-top: 56px;
          display: flex;
          justify-content: space-between;
          align-items: center;
        }
      }
    </style>
  </head>
  <body>
    <div class="not-fount-container">
      <div class="not-fount-image">
        <img
          width="100%"
          src="https://bin.bnbstatic.com/static/images/electron/404-error.png"
          alt=""
        />
      </div>
      <div class="not-fount-tips">
        <span class="not-fount-tips-bold"
          >Sorry! The page you’re looking for cannot be found.</span
        >
        <span style="margin-left: 16px"
          ><a href="/" class="link"
            >Go to Homepage</a
          ></span
        >
      </div>
      <div class="not-found-board">
        <div class="not-found-board-left">
          <div class="not-found-board-logo">
            <img
              src="https://bin.bnbstatic.com/static/images/electron/logo_01.png"
              alt=""
            />
          </div>
          <div class="not-found-board-text">
            <div class="not-found-board-text-inner">
              <div>Binance desktop</div>
              <div class="text-inner-icons">
                <span class="icon-windows"></span>
                <span class="icon-linux"></span>
                <span class="icon-mac"></span>
              </div>
            </div>
            <div
              style="
                font-size: 14px;
                color: #474d57;
                font-weight: 400;
                margin-top: 6px;
              "
            >
              A secure, fast and smooth trading experience.
            </div>
          </div>
        </div>
        <div class="not-found-board-right">
          <button id="njewuisj-404-desktop-download">Download Now</button>
        </div>
      </div>
    </div>
    <script>
      window.sensors = window["sensorsDataAnalytic201505"];
      if (sensors) {
        sensors.init({
          show_log: false,
          name: "sensors",
          server_url: "https://sensors.binance.cloud/sa?project=binance",
          heatmap: {
            // collect_elements: "all",
          },
          heatmap_url:
            "https://bin.bnbstatic.com/static/sensorsdata/heatmap.min.js",
          batch_send: false,
          send_type: "beacon",
          callback_timeout: 2000,
        });
        sensors.quick("autoTrack", {
          canary: "beta",
        });
      }
      window.onload = function () {
        var downloadBtn = document.getElementById(
          "njewuisj-404-desktop-download"
        );
        var p = navigator.platform;
        var isMac = p.indexOf("Mac") == 0;
        var isWin = p.indexOf("Win") == 0;
        var isLinux = p == "X11" || p.indexOf("Linux") == 0;
        downloadBtn.addEventListener("click", function () {
          if (isMac) {
            window.location.href =
              "https://ftp.binance.com/electron-desktop/mac/production/binance.dmg";
          }
          if (isWin) {
            window.location.href =
              "https://ftp.binance.com/electron-desktop/windows/production/binance-setup.exe";
          }
          if (isLinux) {
            window.location.href =
              "https://ftp.binance.com/electron-desktop/linux/production/binance-x86_64-linux.rpm";
          }
        });
      };
    </script>
  </body>
</html>

   at ExchangeSharp.APIRequestMaker.MakeRequestAsync

jdx-john avatar Jun 24 '21 16:06 jdx-john

Likely a bug you ran into. There was likely not an API currency endpoint back when that method was implemented, so as a hack, it was probably retrieved by parsing the HTML on the Binance website.

vslee avatar Jun 24 '21 17:06 vslee

I can see it's making a call to:

https://www.binance.com/assetWithdraw/getAllAsset.html

But I don't know the Binance API at all to comment :)

jdx-john avatar Jun 24 '21 17:06 jdx-john

That Binance end point is gone, method is currently broken

jjxtra avatar Jun 26 '21 16:06 jjxtra

https://binance-docs.github.io/apidocs/spot/en/#exchange-information

jjxtra avatar Jun 26 '21 16:06 jjxtra

Hmm, that's not the one either, not sure where this info has moved to

jjxtra avatar Jul 19 '21 22:07 jjxtra

I noticed this has apparently changed because BinanceGroup.OnGetCurrenciesAsync now calls "https://api.binance.com/sapi/v1/capital/config/getall" which is part of wallet-endpoints (https://binance-docs.github.io/apidocs/spot/en/#all-coins-39-information-user_data). It looks good but I get the error back API-key format invalid. Not sure why.

I figured I could maybe use results of OnGetMarketSymbolsMetadataAsync to find the list of currencies?

jdx-john avatar Nov 10 '21 21:11 jdx-john