forked from torreyleonard/algotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
executable file
·197 lines (157 loc) · 4.94 KB
/
test.js
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/**
* Algotrader - Tests
* @author Torrey Leonard
* @licence Apache-2.0
*/
const test = require('ava');
const algotrader = require('./index');
/**
* Broker Library
*/
// Robinhood
const Robinhood = algotrader.Robinhood;
const Instrument = Robinhood.Instrument;
const Fundamentals = Robinhood.Fundamentals;
const Market = Robinhood.Market;
test('broker | robinhood > get instrument', t => {
return Instrument.getBySymbol("MCD").then(res => {
t.true(res.constructor.name === "Instrument");
}).catch(error => t.fail(error));
});
test('broker | robinhood > get top moving instruments', t => {
return Instrument.getTopMoving("up").then(res => {
t.true(res.length > 0 && res[0].constructor.name === "Instrument");
}).catch(error => t.fail(error));
});
test('broker | robinhood > get most popular instruments', t => {
return Instrument.getMostPopular().then(res => {
t.true(res.length > 0 && res[0].constructor.name === "Instrument");
}).catch(error => t.fail(error));
});
test('broker | robinhood > get quote', t => {
return Instrument.getBySymbol("CMCSA").then(res => {
return res.getQuote().then(quote => {
t.true(quote.constructor.name === "Quote");
}).catch(error => t.fail(error));
}).catch(error => t.fail(error));
});
test('broker | robinhood > get fundamentals', t => {
return Fundamentals.getBySymbol("CRM").then(res => {
t.true(res.constructor.name === "Fundamentals");
}).catch(error => t.fail(error));
});
test('broker | robinhood > get market', t => {
return Market.getByMIC("XNYS").then(res => {
t.true(res.constructor.name === "Market");
}).catch(error => t.fail(error));
});
test('broker | robinhood > get market hours', t => {
return Market.getByMIC("XNYS").then(res => {
return res.getNextOpen().then(res => {
t.true(res instanceof Date);
}).catch(error => t.fail(error));
}).catch(error => t.fail(error));
});
/**
* Data Library
*/
// Query
const Query = algotrader.Data.Query;
test('data | query > search', t => {
return Query.search("Hewlett Packard").then(res => {
t.true(res.length > 0);
}).catch(error => t.fail(error));
});
test('data | query > get top gainers', t => {
return Query.getTopGainers(5).then(res => {
t.true(res.length > 0);
}).catch(error => t.fail(error));
});
test('data | query > get highest volume', t => {
return Query.getHighestVolume(5).then(res => {
t.true(res.length > 0);
}).catch(error => t.fail(error));
});
test('data | query > get highest open interest', t => {
return Query.getHighestOpenInterest(5).then(res => {
t.true(res.length > 0);
}).catch(error => t.fail(error));
});
test('data | query > get top ETFs', t => {
return Query.getTopETFs(5).then(res => {
t.true(res.length > 0);
}).catch(error => t.fail(error));
});
test('data | query > get similar', t => {
return Query.getSimilar("DPS").then(res => {
t.true(res.length > 0);
}).catch(error => t.fail(error));
});
test('data | query > get trending symbols', t => {
return Query.getTrendingSymbols(5).then(res => {
t.true(res.length > 0);
}).catch(error => t.fail(error));
});
test('data | query > get earnings', t => {
return Query.getEarnings(5).then(res => {
t.true(res.length > 0);
}).catch(error => t.fail(error));
});
test('data | query > get earnings by symbol', t => {
return Query.getEarningsBySymbol("BAC").then(res => {
t.true(res.length > 0);
}).catch(error => t.fail(error));
});
// Stream
const Stream = algotrader.Data.Stream;
test('data | stream > start stream', t => {
return new Promise(resolve => {
const s = new Stream([ "EXC", "MET", "HAS", "ATVI", "PEP" ]);
s.start();
s.on('quote', quote => {
t.true(quote.constructor.name === "Quote");
resolve(s.stop());
});
s.on('error', error => t.fail(error));
})
});
// Yahoo
const Yahoo = algotrader.Data.Yahoo;
test('data | yahoo > get quote', t => {
return Yahoo.getQuotes("MMM", "5d", "1m", false).then(res => {
t.true(res.length > 0 && res[0].constructor.name === "Quote");
}).catch(error => t.fail(error));
});
test('data | yahoo > get options chain', t => {
return Yahoo.getOptionsChain("LUV").then(res => {
t.true(res.constructor.name === "OptionsChain");
}).catch(error => t.fail(error));
});
// Nasdaq
const Nasdaq = algotrader.Data.Nasdaq;
test('data | nasdaq > get listings', t => {
return Nasdaq.getTraded().then(res => {
t.true(res.length > 0);
}).catch(error => t.fail(error));
});
// IEX
const IEX = algotrader.Data.IEX;
Object.getOwnPropertyNames(IEX).forEach(f => {
if (['length', 'prototype', '_request', 'getBatchQuotes', 'name'].indexOf(f) === -1)
test('data | IEX > ' + f, t => {
return IEX[f]("AAPL").then(res => {
t.true(res !== undefined)
}).catch(error => t.fail(error));
});
});
/**
* Algorithm Library
*/
// Scheduler
const Scheduler = algotrader.Algorithm.Scheduler;
test('algorithm | scheduler > create and cancel job', t => {
return Scheduler.onMarketOpen(0, () => { }).then(job => {
t.true(job.constructor.name === "Job");
Scheduler.cancel(job);
}).catch(error => t.fail(error));
});