ArjunVachhani / order-matcher

simple, fast and feature rich order matching engine supports limit, market, stop-loss, iceberg, IOC, FOK, GTD orders
MIT License
137 stars 70 forks source link

Change OrderId type from int to ulong #39

Closed P9avel closed 1 year ago

P9avel commented 2 years ago

I am planed to have 1million orders per sec. And int can finished very quickly

ArjunVachhani commented 2 years ago

@P9avel OrderId, Price and Quantity types abstracts actual type, you could modify underlying type of OrderId, Price or Quantity based on your needs.

P9avel commented 2 years ago

Not undertood, sorry. Please look code

public class Order { public bool IsBuy { get; set; } public OrderId OrderId { get; set; }

P9avel commented 2 years ago

I am cannot replace OrderId here. Need rewrite all

ArjunVachhani commented 2 years ago

you could change underlying type. of order id, also you need to change serializer to match with underlying type.

public readonly struct OrderId : IEquatable<OrderId>, IComparable<OrderId>
{
    public const int SizeOfOrderId = sizeof(long);
    public static readonly OrderId MaxValue = long.MaxValue;
    public static readonly OrderId MinValue = long.MinValue;
    private readonly long _orderId;
    public OrderId(long orderId)
    {
        _orderId = orderId;
    }
    // rest of the code
}
P9avel commented 2 years ago

Many thanks, now understand. Possible you can add this code to repository, I am think ulong for OrderId is best solution for Exchange implementation

P9avel commented 2 years ago

I see you. But i am want to use your code as is and update when you will release new version without modification.

ArjunVachhani commented 2 years ago

I see,

ArjunVachhani commented 2 years ago

@P9avel long for OrderId seems good data type. We should probably use long as internal type. But do you think that we should give a choice to developers to use type of their choice. There might be some advantages of this

Your thoughts?

P9avel commented 2 years ago

Possible implement OrderId as Generic? And implement default internal type as long?

ArjunVachhani commented 2 years ago

If we use generic then it would be hard to restrict to just numeric types, short, int, long, decimal. This applies to other types as well, Mostly shares are traded in full number only, some developers might prefer using int for underlying datatype for Quantity.

P9avel commented 2 years ago

some developers might prefer using int for underlying datatype for Quantity Yes, you a right. But int value we can save to decimal and can used Validation for exclude real values. But with OrderId issue many complex. If we used int, then can saved 0...2 147 483 647 orders. For example many large exchanges guarantee matching 60000 orders per second. In result int give 2 147 483 647/60000 = 35791,39 seconds = 9,9hours. I am want to save orderId in database and long best solution in any case

ArjunVachhani commented 2 years ago

@P9avel I have refactored code, so that It makes easy to choose underlying types. Now you will need to change just OrderId structure, we have moved serialization and deserialization methods to OrderId structure. it is now more cohesive by design.

I am thinking of redesigning Order class and common types. so that choosing right type would be easier as well as more efficient.

see #49

P9avel commented 2 years ago

Many thanks for this!!!

P9avel commented 2 years ago

I am thinking of redesigning Order class and common types Possible can you add new unit test for custom Order implementation with long orderid and with userId property when complete?

ArjunVachhani commented 2 years ago

@P9avel Sure.

ArjunVachhani commented 2 years ago

@P9avel long-orderId-and-userId branch contains support for UserId and OrderId in long.

P9avel commented 2 years ago

Many many thx for your work

P9avel commented 2 years ago

I am think complete and you can close issue