Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Matching Engine in kotlin - (coroutine / channel)

NotificationsYou must be signed in to change notification settings

FirstArtaxer/komatch

Repository files navigation

Overview

A simple trade orders matching engine for a crypto exchange implemented in Kotlin using coroutines and channels.
This sample supports limit buy and sell orders and matches them concurrently.
It uses the Price/Time algorithm (First-in-First-out) or the Pro-Rata algorithm via a system property.

Usage

To run the application using the Pro-Rata algorithm:

java -Dmatching.algorithm=PRO_RATA -jar komatch.jar

Example

importcom.yourusername.matchingengine.*importkotlinx.coroutines.runBlockingimportkotlinx.coroutines.delayfunmain()= runBlocking {val engine=MatchingEngine() engine.start()   engine.addOrder(Order(1,OrderType.BUY,100.0,10.0)) engine.addOrder(Order(2,OrderType.SELL,100.0,5.0))// delay for the matching engine to process orders delay(100)val matchedOrders= engine.getMatchedOrders()println(matchedOrders)// Output: [(Order(id=1, type=BUY, price=100.0, quantity=5.0), Order(id=2, type=SELL, price=100.0, quantity=5.0))] engine.stop()}

About

Matching Engine in kotlin - (coroutine / channel)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp