-
Notifications
You must be signed in to change notification settings - Fork 1
/
ExecEnviron.java
executable file
·137 lines (105 loc) · 3.35 KB
/
ExecEnviron.java
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package c8;
import java.io.File;
import java.io.FileInputStream;
import java.util.*;
import c8.gateway.*;
import c8.trading.*;
import c8.util.*;
public class ExecEnviron {
static EnvironmentServer current;
static Properties appProperties;
static boolean isStarted;
private ExecEnviron() {
}
static {
current = new NullEnvironmentServer();
appProperties = new Properties();
try {
FileInputStream in = new FileInputStream("c8.ini");
appProperties.load(in);
} catch (Exception e) {
// TODO: what to do?
e.printStackTrace();
}
}
public static EnvironmentServer start() {
if (isStarted) {
throw new RuntimeException("Cannot start ExecEnviron twice");
}
String environName = appProperties.getProperty("Market");
if (environName.equalsIgnoreCase("Test")) {
throw new RuntimeException();
} else if (environName.equalsIgnoreCase("OANDA")) {
current = new OandaEnvironmentServer();
current.start();
isStarted = true;
} else {
System.err.println("Specified ExecEnviron is not recognised: " + environName);
}
return current;
}
public static Properties c8props() {
return appProperties;
}
public static boolean isTradingBlackout() {
return isTradingBlackout(time());
}
public static boolean isTradingBlackout(long time) {
return current.isTradingBlackout(time);
}
public static boolean isConnected() {
return current.isConnected();
}
public static void sleepUntilNextRoundTime(Interval iv) {
long nextRoundTime = iv.nextRoundTime();
assert nextRoundTime > time();
sleep(nextRoundTime - time());
}
public static void sleep(long ms) {
current.sleep(ms);
}
public static boolean shouldStop() {
File stopFile = new File("c8stop");
return stopFile.exists();
}
public static PriceTable getPriceTable() {
return current.getPriceTable();
}
public static void send(Message msg) {
current.send(msg);
}
// public static Message sendReplyPaid(Message msg) {
// //contract reply info by msg type:
// //OpenOrder - transaction
// //ModifyOrder - transaction
// //CloseOrder - transaction
// //OpenOrderConfirmation - should not be sent by client side... null
// //TransactionUpdate - transaction
// //PriceUpdate - price
// //CloseAllPositions - boolean
// //Logoff - boolean
//
// return current.sendReplyPaid(msg);
// }
public static Transaction execute(MarketOrder order, String accId) {
return current.execute(order, accId);
}
public static Transaction modify(MarketOrder order, String accId) {
return current.modify(order, accId);
}
public static Transaction close(MarketOrder order, String accId) {
return current.close(order, accId);
}
public static long time() {
return current.getTime();
}
public static void setTime(long time) {
current.setTime(time);
}
public static Currency getAccountingCcy() {
return current.getAccountingCcy();
}
public static String getName() {
return current.getName();
}
}