Skip to content

A high performance trade engine with real time quotation push

License

Notifications You must be signed in to change notification settings

luren5/viabtc_exchange_server

 
 

Repository files navigation

ViaBTC Exchange Server

ViaBTC Exchange Server is a high performance trade backend for exchanges like digital currency exchange. It support up to 10000 trades every second. It support push user data and market data in real time thought websocket.

Architecture

Architecture

This project is the server part in this picture.

code structure

Require system

  • MySQL: save oper log, save user balance history, order history, trade history.

  • Redis: a redis sentinel group, save market data.

  • Kafka: a message system.

Base library

  • network: a event base and high performance network programming library, easily supoort 1000K TCP connections. Include TCP/UDP/UNIX SOCKET server and client implementation, a simple timer, state machine, thread pool.

  • utils: some basic library. Include log, config parse, some data structure, http/websocket/rpc server implementation.

Modules

  • matchengine: the most important part, it reord user balance, execute user order. It is a in memory database, save oper log in MySQL, redo the oper log when start. It also write user history into MySQL, push balance and order and deal message to kafka.

  • marketprice: read message from kafka, generage k line data.

  • readhistory: read history data from MySQL.

  • accesshttp: support a simple HTTP interface and hide complexity for upper layer.

  • accwssws: a websocket server, support user data and market data query and push. You need nginx in front to support wss.

  • alertcenter: a simple server write FATAL level log to redis list, so we can send alert emails.

Compile and Install

operating system

Ubuntu 14.04 or Ubuntu 16.04. Not test on other system

Requirements

See requirements. Install those system or library.

You MUST use the depends/hiredis to install the hiredis library. Or it may not compatibility.

Compile order

Compile network and utils first. The rest all are independent.

Deploy

The matchengine and marketprice and alertcenter is a signal instance, the readhistory and accesshttp and accwssws can have multi instance work with loadbalance.

Every instance better not install on same machine.

Every process runing in deamon and start with a watchdog process, if crash, it will autoly restart in 1s.

The best practice of deploy the instance is in following directory structure:

matchengine
|---bin
|   |---matchengine.exe
|---log
|   |---matchengine.log
|---conf
|   |---config.json
|---shell
|   |---restart.sh
|   |---check_alive.sh

API

There are HTTP Protocl and Websocket Protocl documents. But it is in Chinese, I may translate it into English in the future.

Donation

  • BTC: 14x3GrEoMLituT6vF2wcEbqMAxCvt2724s
  • BCC: 1364ZurPv8uTgnFr1uqowJDFF15aNFemkf
  • ETH: 0xA2913166AE0689C07fCB5C423559239bB2814b6D

Pay service

If you need help in deploy this system, I can give a paid support.

About

A high performance trade engine with real time quotation push

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 97.7%
  • Other 2.3%