This repository has been archived by the owner on Jan 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 240
/
MockOrderbook.ts
71 lines (66 loc) · 3.57 KB
/
MockOrderbook.ts
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
/***************************************************************************************************************************
* @license *
* Copyright 2017 Coinbase, Inc. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance *
* with the License. You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on *
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the *
* License for the specific language governing permissions and limitations under the License. *
***************************************************************************************************************************/
import { OrderbookState, PriceLevelFactory } from '../../src/lib/Orderbook';
import { BookBuilder } from '../../src/lib/BookBuilder';
import { OrderDoneMessage, SnapshotMessage, StreamMessage } from '../../src/core/Messages';
import { NullLogger } from '../../src/utils/Logger';
function shallowState(): OrderbookState {
return {
sequence: 1,
bids: [
PriceLevelFactory(100, 10, 'buy'),
PriceLevelFactory(99, 5, 'buy'),
PriceLevelFactory(98, 20, 'buy'),
PriceLevelFactory(97, 10, 'buy'),
PriceLevelFactory(96, 1, 'buy'),
PriceLevelFactory(95, 15, 'buy'),
PriceLevelFactory(94, 10, 'buy'),
PriceLevelFactory(93, 25, 'buy'),
PriceLevelFactory(92, 25, 'buy'),
PriceLevelFactory(91, 2, 'buy')
],
asks: [
PriceLevelFactory(110, 10, 'sell'),
PriceLevelFactory(112, 5, 'sell'),
PriceLevelFactory(113, 1, 'sell'),
PriceLevelFactory(114, 1, 'sell'),
PriceLevelFactory(115, 20, 'sell'),
PriceLevelFactory(116, 30, 'sell'),
PriceLevelFactory(117, 10, 'sell'),
PriceLevelFactory(118, 5, 'sell'),
PriceLevelFactory(119, 50, 'sell'),
PriceLevelFactory(120, 2, 'sell')
]
} as OrderbookState;
}
const shallowBook: BookBuilder = new BookBuilder(NullLogger);
shallowBook.fromState(shallowState());
function level3Messages(): StreamMessage[] {
return [
Object.assign({
type: 'snapshot',
time: new Date('2017-06-01'),
productId: 'ABC-XYZ'
}, shallowState()) as SnapshotMessage,
{ type: 'orderDone',
sequence: 2,
time: new Date('2017-06-01 00:00:01'),
productId: 'ABC-XYZ',
price: '113',
remainingSize: '1',
reason: 'cancelled'
} as OrderDoneMessage
];
}
export { shallowBook, shallowState, level3Messages };