Solution 1 :

Following seems to be working fine, not sure why you’re getting NaN. Please provide full working code to troubleshoot the issue.

function doit() {
  let d = new Date();
  let tempObject = {
    side: "buy",
    timestamp: d.getTime()

Problem :

I am trying to save the current time inside a temporary object inside the timestamp key using new Date.getTime() and push it into an array which is inside a globally accessible variable, GLOBAL_VAR.
But after I make the temporary variable and print its value it shows the timestamp is NaN I don’t know why I can’t get it inside the object (the console.log() and the result is shown below)

handleOrderMessage function is called when a event is received I don’t know if that will affect the new Date.getTime() function, showing output:

console.log("TEMP OBJECT IS", tempObject)
id: "-909e-11ea-9ede-066a42ffe1ae",
​price: "0.1",
​quantity: "0.1",
​side: "buy",
​timestamp: NaN
    function handleOrderMessage(msg) {

        let d = new Date();
        if (msg['status'] === "PLACED") {
            //for buy
            if (msg['orderSide'] === "Buy") {
                let tempObject = {
                    side: "buy",
                    id: msg["OrderID"],
                    timestamp: d.getTime(),
                    quantity: parseFloat(msg["Quantity"].toFixed(4)).toString(),
                    price: parseFloat(msg["Price"].toFixed(4)).toString()
                //pushing to the global orders with price from msg as key
                if (tempObject.price in GLOBAL_VAR.bidOrdersPricesAsKey) {
                } else {
                    GLOBAL_VAR.bidOrdersPricesAsKey[tempObject.price] = [tempObject]
                console.log("GLOBAL VAR BUY ORDERS PRICES ASK KEY", GLOBAL_VAR.bidOrdersPricesAsKey)
                console.log("TEMP OBJECT IS", tempObject)


Comment posted by Aioros

Your snippet is very hard to use. You should add the necessary variables and the function call.

Comment posted by JeffRSon

… and remove everything that’s not necessary to show your case

Comment posted by

Works fine here:

Comment posted by Emmanuel Thomas

It’s kind of a very huge file..that’s why I didn’t show it


Leave a Reply

Your email address will not be published. Required fields are marked *