GithubHelp home page GithubHelp logo

leonguyensg / order-matcher Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arjunvachhani/order-matcher

0.0 0.0 0.0 2.08 MB

simple matching engine supports limit, market, stop-loss, iceberg, IOC, FOK, GTD orders

License: MIT License

C# 100.00%

order-matcher's Introduction

order-matcher

Order Matching Engine / Trading Engine

  • Built with .Net Core, can run on linux and windows
  • Support multiple order types
    • Limit
    • Market
    • Stop Loss / Stop Limit
    • Immediate or Cancel(IOC)
    • Fill or kill(FOK)
    • Good till Date(GTD)
    • Iceberg

Supports integer & real numbers/decimal for price and quantity

Hand written serializer faster than any serializer. x15 times faster than JSON, x5 times faster than messagepack

Documentation

home

1. Terminology

2. Order

3. Frequently Asked Questions(FAQ)

Code

class Program
{
	static void Main(string[] args)
	{
		//create instance of matching engine.
		MatchingEngine matchingEngine = new MatchingEngine(0, 1, new MyTradeListener(), new TimeProvider());

		Order order1 = new Order { IsBuy = true, OrderId = 1, Quantity = 1000, Price = 10 };
		//push new order engine.
		matchingEngine.AddOrder(order1);

		//cancel existing orders
		matchingEngine.CancelOrder(1);//pass orderId to cancel
	}
}



//create a listener to receive events from matching engine. pass it to constructore of MatchingEngine
class MyTradeListener : ITradeListener
{
    public void OnCancel(ulong orderId, Quantity remainingQuantity, Quantity remainingOrderAmount, CancelReason cancelReason)
    {
        Console.WriteLine($"Order Cancelled.... orderId : {orderId}, remainingQuantity : {remainingQuantity}, cancelReason : {cancelReason}");
    }

    public void OnOrderTriggered(ulong orderId)
    {
        Console.WriteLine($"Stop Order Triggered.... orderId : {orderId}");
    }

    public void OnTrade(ulong incomingOrderId, ulong restingOrderId, Price matchPrice, Quantity matchQuantiy, bool incomingOrderCompleted)
    {
        Console.WriteLine($"Order matched.... incomingOrderId : {incomingOrderId}, restingOrderId : {restingOrderId}, executedQuantity : {matchQuantiy}, exetedPrice : {matchPrice}");
    }
}

order-matcher's People

Contributors

arjunvachhani avatar dependabot[bot] avatar

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.