Giter VIP home page Giter VIP logo

fasenderos / hft-limit-order-book Goto Github PK

View Code? Open in Web Editor NEW
112.0 2.0 26.0 2.2 MB

Ultra-fast Node.js Limit Order Book for high-frequency trading (HFT) :rocket::rocket:

Home Page: https://github.com/fasenderos/hft-limit-order-book

License: MIT License

JavaScript 12.03% Shell 0.63% TypeScript 87.35%
exchange hft hft-trading limit-order-book matching-algorithm matching-engine nodejs order-book orderbook trading

hft-limit-order-book's People

Contributors

afshinkoohsari avatar andreafassina avatar dependabot[bot] avatar fasenderos avatar ipod1g avatar vanodevium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hft-limit-order-book's Issues

Order: traderID

First of all, thanks for your great work!


Created orders have no indication of who created them. It follows that I, as a trader, can buy from myself or sell to myself. It seems to me that this is not entirely logical.

I think it would be great to add a Trader ID for each order and just skip orders with the same Trader ID in the matching process.

How to lock user balance on market order

Hello, please help me with this scenario
Pair Matic/USD
wallet balance of user1 is 10 USD
wallet balance of user2 is 5 USD

User1 want to sell 10 Matic at price of 1 USD
User2 place a MARKET order to buy 10 Matic but he use has balance of 5 USD.

How to stop this order and process according to wallet balance

How I create orderbook UI with your lib data

Hii, I am a beginner in blockchain & trading. I want to create an order book ui like this:-

Screenshot 2023-05-21 at 5 28 12 PM

This is Binance order ui

I found some data in your library functions

console.log('bids', book.bids);
console.log('asks', book.asks);
console.log('depth', book.depth());

please anyone guide me how i create and manage this.

Discussion: canceled orders

If the order has a FOK, then it is not quite an error when it isn't fulfilled, it is simply a canceled order.

I have an idea: to add another property to the response, canceled orders, where are placed those orders that were canceled for several reasons:

  • FOK and IOC
  • OCO orders
  • canceled by user's decision

Let's discuss?

Question: market buy quantity

When a user makes a market order to buy some symbol, the exchange as a balance controller needs to freeze the user's money. But the market order does not have a price, and of course I do not know what amount to freeze.

In many systems, I noticed a good solution to this issue: for market buy orders, they accept the quantity in the quote currency (BTC/USD as base/quote, so they received quantity in USD), which allows me to correctly calculate the order book and freeze the excess money on the balance sheet.

Question: maybe you have some other solution or you can explain how to freeze money correctly if it is specified in the base currency.

For context: let's say I use your orderbook using asynchronous queues (kafka or nats). If I don't know what money to freeze, the user will have the option of double spending. On another side, I can check result and cancel market order but there are already fulfilled limit orders which are deleted from orderbook.

Thanks!

buyOrderCanBeFilled/sellOrderCanBeFilled optimization

Since the OrderSide already has its own volume value, it would be good to first check whether the volume is in principle sufficient for the order.
I think it will speed up the check a bit.

Example:

  buyOrderCanBeFilled(orderSide: OrderSide, size: number, price: number) {

    // THIS IS PRE-CHECK
    if (orderSide.volume() < size) {
      return false
    }

    let cumulativeSize = 0
    orderSide.priceTree().forEach((_key, priceLevel) => {
      if (price >= priceLevel.price() && cumulativeSize < size) {
        cumulativeSize += priceLevel.volume()
      } else {
        return true // break the loop
      }
    })
    return cumulativeSize >= size
  }

Modifying the order price should run the matching process

Describe the bug

Hi,
After a user modifies an order price, the updated order should be matched with other orders in the book.

To Reproduce

limit("sell", "id1", 1, 200);
limit("buy", "id2", 1, 100);
modify("id2", { side: "buy", size: 1, price: 200})

Result:
asks: 200 -> 1
--------------  
bids: 200 -> 1

Expected behavior

Empty order book

Simple test reveal bug

Describe the bug

Matching a sell to multiple buys does not produced the right results.

To Reproduce

lob.createOrder("limit", "buy", 100, 1.2, "A0");
lob.createOrder("limit", "buy", 100, 1.2, "A1");
console.log(lob.orders, "sell", lob.asks.toString(),"buy", lob.bids.toString() )
//sell buy
//1.2 -> 200
lob.createOrder("limit", "sell", 309, 1.2, "B0");
console.log(lob.orders, "sell", lob.asks.toString(),"buy", lob.bids.toString() )
//sell buy
//1.2 -> -9

Expected behavior

Should output this in the asks
//sell
//1.2 -> 109

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.