注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
1. Order Matching Engine C#
You're going to write an exchange order matching engine.
The input is from stdin. Each line has several columns separated by one space.
The first column specifies the operation to be done. Our supported operations are:
BUY
SELL
CANCEL
MODIFY
PRINT
If the first column is BUY or SELL, then this line has five columns in total:
The second column is the order type, it's either "IOC" or "GFD".
The third column is the price you want to buy or sell, it's an integer.
The fourth column shows the quantity of that buy or sell, it's an integer. Both the price and quantity are positive numbers.
The fifth column is the order id which is an arbitrary word.
If the first column is CANCEL, then this line has two columns in total:
1. The second column is the order id.
This order needs to be deleted, it can't be traded any more. If the provided Order ID doesn't exist then do nothing.
If the first column is MODIFY, then this line has five columns in total:
1. The second column is the order id, it means that order needs to be modified.
2. The third column is either BUY or SELL.
3. The fourth column is the new price of that order.
4. The fifth column is the new quantity of that order.
If the provided Order ID doesn't exist then do nothing.
(Note: that we can't modify an IOC order type, as we'll mention later.)
MODIFY is a powerful operation, e.g. a BUY order can be modified to a SELL order:
BUY GFD 1000 10 order1
MODIFY order1 SELL 1000 10
ch is implemented cleanly and in a straightforward manner.
3. Performance: Consider the performance of the methods you write and the data structures you choose. Marks will be deducted for inefficiencies.
Examples
Example 1:
BUY GFD 1000 10 order1
PRINT
Output:
SELL:
BUY:
1000 10
Example 2:
BUY GFD 1000 10 order1
BUY GFD 1000 20 order2
PRINT
Output:
SELL:
BUY:
1000 30
Example 3:
BUY GFD 1000 10 order1
BUY GFD 1001 20 order2
PRINT
Output:
SELL:
BUY:
1001 20
1000 10
Example 4:
BUY GFD 1000 10 order1
SELL GFD 900 20 order2
PRINT
Output:
TRADE order1 1000 10 order2 900 10
SELL:
900 10
BUY:
Example 5:
BUY GFD 1000 10 ORDER1
BUY GFD 1010 10 ORDER2
SELL GFD 1000 15 ORDER3
Output:
TRADE ORDER2 1010 10 ORDER3 1000 10
TRADE ORDER1 1000 5 ORDER3 1000 5
|