-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderBookDriver.java
More file actions
79 lines (74 loc) · 2.71 KB
/
OrderBookDriver.java
File metadata and controls
79 lines (74 loc) · 2.71 KB
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
import java.sql.Time;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class OrderBookDriver {
public static void main(String[] args){
OrderBook book = new OrderBook(10.00);
Scanner sc = new Scanner(System.in);
String choice = sc.nextLine();
if(choice.equals("bots")){
Queue<OrderBookBot> bots = new LinkedList<>();
System.out.println("Bot Count: ");
int count = sc.nextInt();
long id = 1;
for(int i = 0; i < count; i++){
bots.add(new OrderBookBot(id));
id++;
}
int ct = 0;
while(ct < 1000000){
OrderBookBot bot = bots.poll();
bot.execute();
bots.add(bot);
ct++;
if(ct % 10000 == 0){
System.out.println(OrderBookBot.positions);
System.out.println(OrderBookBot.profits);
}
}
System.out.println(OrderBookBot.positions);
System.out.println(OrderBookBot.profits);
}else{
//System.out.println("Trading sim begin: ");
long id = 10000000;
while(true){
String line = sc.nextLine();
String[] h = line.split("\\s+");
if(line.equals("Done")){
break;
}
else if(line.equals("view")){
System.out.println(book.buyersBook);
System.out.println(book.sellersBook);
System.out.println(book.availableBuys);
System.out.println(book.availableSells);
System.out.println("bidPrice: " + book.bidPrice);
System.out.println("askPrice: " + book.askPrice);
}
else if(h[0].equals("marketOrder")){
if(h[1].equals("sell")){
book.addMarketOrder(false, id);
}
else{
book.addMarketOrder(true, id);
}
id++;
}
else if(h[0].equals("limit")){
Double price = Double.parseDouble(h[2]);
if(h[1].equals("buy")){
book.addLimitOrder(true, price, id);
}
else{
book.addLimitOrder(false, price, id);
}
id++;
}
else{
System.out.println("invalid trade token used");
}
}
System.out.println("Trading sim exited");
}
}
}