Bitcoin Forum
April 24, 2024, 06:42:18 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How do I scale an exchange / trading engine wrote in C#? Threads/Race condtions  (Read 55 times)
XMRTraders (OP)
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
October 28, 2020, 10:10:43 PM
 #1

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

Even if you use Bitcoin through Tor, the way transactions are handled by the network makes anonymity difficult to achieve. Do not expect your transactions to be anonymous unless you really know what you're doing.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713984138
Hero Member
*
Offline Offline

Posts: 1713984138

View Profile Personal Message (Offline)

Ignore
1713984138
Reply with quote  #2

1713984138
Report to moderator
1713984138
Hero Member
*
Offline Offline

Posts: 1713984138

View Profile Personal Message (Offline)

Ignore
1713984138
Reply with quote  #2

1713984138
Report to moderator
1713984138
Hero Member
*
Offline Offline

Posts: 1713984138

View Profile Personal Message (Offline)

Ignore
1713984138
Reply with quote  #2

1713984138
Report to moderator
Valera Vlasyuk
Jr. Member
*
Offline Offline

Activity: 47
Merit: 4


View Profile
February 02, 2021, 01:14:47 AM
Merited by Vod (1)
 #2

I think C# is a bad idea for the trading engine. Use GoLang or C/C++. mySQL is a bad idea

I've coded an engine that can handle 12000/minute transactions. I've used winners of HFT contests algo.
Some ideas for you:
 - no floating points all unsigned int.
 - all data is stored in memory.
 - sent all data by blocks where possible
 - create your own in-memory storage
 - use Linux or FreeBSD:)
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!