question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Binance Futures fetchBalance timestamp NaN

See original GitHub issue
  • OS: Windows 10
  • Programming Language version: Node
  • CCXT version: 1.40.73
const ccxt = require("ccxt");

(async () => {
  // --------------------------- Variable Information ----------------------------
  exchangeName = "binance";
  symbol = 'ETH/USDT';

  // --------------------------- Exchange Information ----------------------------

  const exchangeID = exchangeName;
  const exchangeClass = ccxt[exchangeID];
  exchange = new exchangeClass({
      "apiKey": apiKey,
      "secret": secret,
      "enableRateLimit": true,
      "verbose": true
  });

  exchange.options = {
    "defaultType": "future"
  }

  exchange.urls["api"] = exchange.urls["test"];

  // --------------------------- Testing Information ---------------------------- 

  // get markets test
  markets = await exchange.loadMarkets();
  // console.log({markets});

  // get ohlcv test
  ohlcv = await exchange.fetchOHLCV(symbol, "1h", undefined, 200);
  // console.log({ohlcv});

  // get balance test
  let balance = await exchange.fetchBalance();
  console.log({balance})
})()

handleRestResponse:
 binance GET https://testnet.binancefuture.com/fapi/v2/account?timestamp=NaN&recvWindow=5000&signature=c18d5b02c1f35efdf8f4a08360c57aa1528d3fbf40f8017d67fa1096ad44cca4 400 Bad Request 
Response:
 {
  'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
  'Access-Control-Allow-Origin': '*',
  Connection: 'keep-alive',
  'Content-Length': '98',
  'Content-Type': 'application/json',
  Date: 'Sun, 17 Jan 2021 18:34:03 GMT',
  Server: 'Bengine',
  Via: '1.1 80f77e0263ce0a0c768ad3f176f2720c.cloudfront.net (CloudFront)',
  'X-Amz-Cf-Id': 'Ty3Q6LpHnxaIGLtywvCM30lfONoa-QjXZJe_u3HM1l4UIE1tr4Efdw==',
  'X-Amz-Cf-Pop': 'ORD50-C1',
  'X-Cache': 'Error from cloudfront',
  'X-Mbx-Used-Weight-1m': '8',
  'X-Response-Time': '0ms'
} 
 {"code":-1102,"msg":"Mandatory parameter 'timestamp' was not sent, was empty/null, or malformed."} 

(node:105) UnhandledPromiseRejectionWarning: BadRequest: binance {"code":-1102,"msg":"Mandatory parameter 'timestamp' was not sent, was empty/null, or malformed."}
    at binance.throwExactlyMatchedException (/home/runner/exchange-testing/node_modules/ccxt/js/base/Exchange.js:532:19)
    at binance.handleErrors (/home/runner/exchange-testing/node_modules/ccxt/js/binance.js:2625:18)
    at /home/runner/exchange-testing/node_modules/ccxt/js/base/Exchange.js:602:18
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async timeout (/home/runner/exchange-testing/node_modules/ccxt/js/base/functions/time.js:195:24)
    at async binance.request (/home/runner/exchange-testing/node_modules/ccxt/js/binance.js:2634:26)
    at async binance.fetchBalance (/home/runner/exchange-testing/node_modules/ccxt/js/binance.js:854:26)
    at async /home/runner/exchange-testing/index.js:40:17
(node:105) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:105) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bigcountry-scavcommented, Jan 18, 2021

Found the issue it is because of setting exchange.options overwrites all the normal options.

0reactions
kroitorcommented, Jan 18, 2021

@bigcountry-scav you’re right, thx for your help! To fix it change your code like so:

  exchange = new exchangeClass({
      "apiKey": apiKey,
      "secret": secret,
      "enableRateLimit": true,
      "verbose": true,
      "options": {
          'defaultType': 'future',
      }
  });

or like so:

  exchange = new exchangeClass({
      "apiKey": apiKey,
      "secret": secret,
      "enableRateLimit": true,
      "verbose": true
  });

  exchange.options['defaultType'] = 'future'

Let me know if that does not resolve the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Binance Futures Order Book Historical Data
Symbol, timestamp (Unix), bid/ask (20 levels), price, quantity. Updates every 1s. BTC/USDT: since January 2020. For more details, please refer ...
Read more >
CCXT - Cryptocurrency Exchange Trading Library Tutorial
... over 100 crypto exchanges and makes trading available under a simple uniform interface. In this video, I use Binance and Coinbase Pro....
Read more >
Binance Futures Trading: How to Turn $50 into $5000
Crypto markets are down, but now is the best time to learn trading skills on binance like bankroll management, use of BNB and...
Read more >
Exchanges — ccxt 2.4.71 documentation
The ccxt library is a collection of available crypto exchanges or exchange classes. Each class implements the public and private API for a...
Read more >
ccxt-dev/ccxt - Gitter
How to create order with expiry date for eg bittrex huobi binance etc? is it ... @kroitor kraken reports on fetchbalances None types,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found