-
Notifications
You must be signed in to change notification settings - Fork 8
/
CompositeSampleApp.java
88 lines (76 loc) · 3.97 KB
/
CompositeSampleApp.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
package SampleApp;
import intrinio.realtime.composite.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Timer;
import java.util.TimerTask;
public class CompositeSampleApp {
public static void run(String[] args){
String apiKey = "API_KEY_HERE";
intrinio.realtime.options.Config optionsConfig = null;
try{
optionsConfig = new intrinio.realtime.options.Config(apiKey, intrinio.realtime.options.Provider.OPRA, null, new String[]{"MSFT", "NVDA", "AAPL"}, 8, false);
}catch (Exception e){
System.out.println("Error parsing options config: " + e.getMessage());
return;
}
intrinio.realtime.equities.Config equitiesConfig = null;
try{
equitiesConfig = new intrinio.realtime.equities.Config(apiKey, intrinio.realtime.equities.Provider.NASDAQ_BASIC, null, new String[]{"MSFT", "NVDA", "AAPL"}, true, 4);
}catch (Exception e){
System.out.println("Error parsing equities config: " + e.getMessage());
return;
}
//store the most recent values in a simple non-transactional cache that gives contextual information with the event.
intrinio.realtime.composite.DataCache currentDataCache = new CurrentDataCache();
//Initialize Options Client and wire it to the cache
//intrinio.realtime.options.OnUnusualActivity optionsUnusualActivityHandler = null;
intrinio.realtime.options.Client optionsClient = new intrinio.realtime.options.Client(optionsConfig);
optionsClient.setOnTrade(currentDataCache::setOptionsTrade);
optionsClient.setOnQuote(currentDataCache::setOptionsQuote);
optionsClient.setOnRefresh(currentDataCache::setOptionsRefresh);
//optionsClient.setOnUnusualActivity(optionsUnusualActivityHandler);
//Initialize Equities Client and wire it to the cache
intrinio.realtime.equities.OnTrade equitiesTradeHandler = currentDataCache::setEquityTrade;
intrinio.realtime.equities.OnQuote equitiesQuoteHandler = currentDataCache::setEquityQuote;
intrinio.realtime.equities.Client equitiesClient = new intrinio.realtime.equities.Client(equitiesTradeHandler, equitiesQuoteHandler, equitiesConfig);
//Display trade events with context
currentDataCache.setOnEquitiesTradeUpdated((SecurityData securityData, DataCache dataCache) -> {
intrinio.realtime.equities.Client.Log(securityData.getTickerSymbol() + " had a trade and also has " + securityData.getAllOptionsContractData().size() + " active contracts");
});
Runtime.getRuntime().addShutdownHook(new Thread( new Runnable() {
public void run() {
intrinio.realtime.equities.Client.Log("Stopping sample app");
optionsClient.leave();
optionsClient.stop();
equitiesClient.leave();
equitiesClient.stop();
}
}));
try{
equitiesClient.start();
//equitiesClient.joinLobby();
equitiesClient.join();
optionsClient.start();
//optionsClient.joinLobby();
optionsClient.join();
}catch (Exception e) {
e.printStackTrace();
}
Timer timer = new Timer();
TimerTask task = new TimerTask() {
public void run() {
try{
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
String date = dtf.format(now);
intrinio.realtime.options.Client.Log(date + " " + optionsClient.getStats());
intrinio.realtime.equities.Client.Log(date + " " + equitiesClient.getStats());
}catch (Exception e){
System.out.println("Error in summary timer: " + e.getMessage());
}
}
};
timer.schedule(task, 30000, 30000);
}
}