Bitcoin Forum
May 24, 2024, 01:13:53 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Bitcoin / Project Development / How do I scale an exchange / trading engine wrote in C#? Threads/Race condtions on: October 28, 2020, 10:10:43 PM
I have a working concept for an exchange.

Two wallets for withdrawal/deposits and a trade engine + frontend in Nodejs. I wrote some bots to spam orders into the queue.

What is the best way to scale it?
I wrote my trade engine in C#. On my PC with everything running it can process about 60 orders a second.

1 market = 1 instance of the app / per server.

How do I queue orders for processing? If I split my app into threads what is the point if I can only do one trade at a time without race conditions?

I want to move the database from mysql which I was using to get it running quickly.

The app moves the order from the queue table to the processing table.

It then moves it from the processing table into the app.

The app trades the coins based on what's in the open order table.

Any remainder from an order is moved to the front of the processing queue in the app.

If no match is found the order is added to the open orders table.

If I have 2 threads and I put a lock on the processing table so that no more are taken by a thread, only one is firing at  a time? What is the point? How do I make it process more orders at a time? Use one thread for buy order and one thread for sell orders?

When I do use threads it gets up to about 300 orders a second, with my CPU I can run 4 threads without any lag but there is always race conditions.

If I use a master and then send each order to a thread round Robin style what if they both grab the same order from the open orders table?

If I get each thread to pull a job from the processing table how do I make sure each thread doesn't grab the same order?

What is the best way to do this? Use the GPU for calculations? Cache the open order book in the app for performance?

I am just looking for advice I suppose. If anyone sees a question they know anything about I will be very grateful

Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!