-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem.txt
82 lines (69 loc) · 3.86 KB
/
problem.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
http://www.tsurucapital.com/en/code-sample.html
Your task is to create a program, written in Haskell, that will parse and print quote messages from a market data feed.
When invoked with an -r flag, the program should re-order the messages according to the ‘quote accept time’ at the exchange.
Your code:
must be semantically correct
must be performant regardless of the input file size, in terms of throughput and memory usage;
must compile with -Wall -Werror.
Parsing the Market Data Feed
The relevant parts of the market data feed are sent via UDP broadcast to ports 15515/15516.
For the purposes of this exercise, a standard pcap file is supplied which you will use to parse the UDP packets.
Quote packets (specified below) begin with the ASCII bytes "B6034", and contain the five current best bids and offers
(or ‘asks’) on the market.
Anything else should be ignored.
Your program should print the packet and quote accept times, the issue code,
followed by the bids from 5th to 1st, then the asks from 1st to 5th; e.g.:
$ ./parse-quote mdf-kospi200.20110216-0.pcap
<pkt-time> <accept-time> <issue-code> <bqty5>@<bprice5> ... <bqty1>@<bprice1> <aqty1>@<aprice1> ... <aqty5>@<aprice5>
...
Reordering on Quote Accept Time
The delay between the exchange accepting the quote and us receiving the packet fluctuates for a variety of reasons; we may even receive the packets out of order.
Given an optional flag -r, your program should output the messages ordered by the quote accept time.
You should assume that the difference between the quote accept time and the pcap packet time is never more than 3 seconds.
Test Data
A small sample file with a capture of the Kospi 200 market data feed from the first 30s of trading on 2011-02-16 can be downloaded here.
Quote Packet Specification
ITEM NAME len Remark
--------------------------------------+---+---------------
Data Type 2 B6
Information Type 2 03
Market Type 1 4
Issue code 12 ISIN code
Issue seq.-no. 3
Market Status Type 2
Total bid quote volume 7
Best bid price(1st) 5 Decimals
Best bid quantity(1st) 7 Decimals
Best bid price(2nd) 5
Best bid quantity(2nd) 7
Best bid price(3rd) 5
Best bid quantity(3rd) 7
Best bid price(4th) 5
Best bid quantity(4th) 7
Best bid price(5th) 5
Best bid quantity(5th) 7
Total ask quote volume 7
Best ask price(1st) 5
Best ask quantity(1st) 7
Best ask price(2nd) 5
Best ask quantity(2nd) 7
Best ask price(3rd) 5
Best ask quantity(3rd) 7
Best ask price(4th) 5
Best ask quantity(4th) 7
Best ask price(5th) 5
Best ask quantity(5th) 7
No. of best bid valid quote(total) 5
No. of best bid quote(1st) 4
No. of best bid quote(2nd) 4
No. of best bid quote(3rd) 4
No. of best bid quote(4th) 4
No. of best bid quote(5th) 4
No. of best ask valid quote(total) 5
No. of best ask quote(1st) 4
No. of best ask quote(2nd) 4
No. of best ask quote(3rd) 4
No. of best ask quote(4th) 4
No. of best ask quote(5th) 4
*Quote accept time* 8 HHMMSSuu
End of Message 1 0xff