-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-0400-asset.js
53 lines (45 loc) · 1.86 KB
/
test-0400-asset.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
//==============================================================================
// Name: tests/test-0400-asset
// Project: TuringTrader.js
// Description: test 0400: load asset quotes
// History: FUB, 2021vii13, created
//==============================================================================
import { createSimulator } from "../src"
//==============================================================================
const algo = {
run: async (sim) => {
// BUGBUG: test may fail in non-US timezones,
// if a date rollover is involved
// FIXME: specify timezone offset to remedy
sim.startDate = new Date("01/01/2021")
sim.endDate = new Date("05/01/2021")
// note that assets are asynchronous.
// to access the data, we need to await them
const spy = sim.asset("spy")
return {
id: spy.id,
data: await spy.data,
}
},
report: (sim) => {},
}
//==============================================================================
describe("test 0400: asset", () => {
test("can download asset quotes", () => {
return createSimulator(algo)
.run()
.then((result) => {
expect(result.id).toMatch(/^loadAsset\(spy,[0-9]+,[0-9]+\)$/)
expect(result.data.meta.ticker).toEqual("spy")
expect(result.data.t.length).toEqual(83)
expect(result.data.o.length).toEqual(83)
expect(result.data.h.length).toEqual(83)
expect(result.data.l.length).toEqual(83)
expect(result.data.c.length).toEqual(83)
expect(result.data.v.length).toEqual(83)
// TODO: verify last close divided by first open
})
})
})
//==============================================================================
// end of file