Coder Social home page Coder Social logo

Comments (5)

fasenderos avatar fasenderos commented on September 15, 2024 1

I think you need JSON.parse() each order in the bids and asks arrays.

from nodejs-order-book.

unauthxrized avatar unauthxrized commented on September 15, 2024

sry, err is not gone(

from nodejs-order-book.

unauthxrized avatar unauthxrized commented on September 15, 2024

i think we need "fromJSON" function

from nodejs-order-book.

fasenderos avatar fasenderos commented on September 15, 2024

Hi thanks for reporting. I wasn't able to reproduce your error. What I noticed is that each object in the orders array is actually a string. If you remove the double quotes before and after the opening and closing braces of each object, you can initialize the order book without any problems.

const snapshot = {
  snapshot: {
    bids: [
      {
        price: 30,
        orders: [
          {
            id: '14:22:1720293920736',
            side: 'buy',
            origSize: 1,
            size: 1,
            price: 30,
            time: 1720293920736,
            isMaker: true
          },
          {
            id: '14:22:1720293921301',
            side: 'buy',
            origSize: 1,
            size: 1,
            price: 30,
            time: 1720293921301,
            isMaker: true
          }
        ]
      }
    ],
    asks: [
      {
        price: 33,
        orders: [
          {
            id: '14:22:1720293904645',
            side: 'sell',
            origSize: 1,
            size: 1,
            price: 33,
            time: 1720293904646,
            isMaker: true
          },
          {
            id: '14:22:1720293912873',
            side: 'sell',
            origSize: 1,
            size: 1,
            price: 33,
            time: 1720293912873,
            isMaker: true
          },
          {
            id: '14:22:1720293913076',
            side: 'sell',
            origSize: 1,
            size: 1,
            price: 33,
            time: 1720293913076,
            isMaker: true
          }
        ]
      }
    ],
    ts: 1720293921302,
    lastOp: 5
  }
}

const book = new OrderBook({ snapshot: snapshot.snapshot, enableJournaling: true })
console.log(book.toString())

33 -> 3
------------------------------------
30 -> 2

from nodejs-order-book.

unauthxrized avatar unauthxrized commented on September 15, 2024

I think you need JSON.parse() each order in the bids and asks arrays.

yes, i think about it. Thx.

from nodejs-order-book.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.