-
Notifications
You must be signed in to change notification settings - Fork 21
/
contract.js
173 lines (133 loc) · 3.37 KB
/
contract.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
import assert from 'assert';
export default class Contract {
static cfd(symbolOrData) {
return Contract._toContract(symbolOrData, 'CFD', {
currency: 'USD',
exchange: 'SMART'
});
}
static combo(symbolOrData) {
return Contract._toContract(symbolOrData, 'BAG', {
currency: 'USD',
exchange: 'SMART'
});
};
/* can be called as a pair forex('EURUSD')
or
forex({
symbol: 'EUR',
currency: 'USD'
});
*/
static forex(pairOrData) {
if (typeof pairOrData == 'string') {
assert(pairOrData.length == 6);
pairOrData = {
symbol: pairOrData.substr(0, 3),
currency: pairOrData.substr(3)
};
}
return Contract._toContract(pairOrData, 'CASH', {
exchange: 'IDEALPRO'
});
};
/*
symbol:
lastTradeDateOrContractMonth: The option's last trading day
or contract month.
* YYYYMM format: To specify last month
* YYYYMMDD format: To specify last trading day
*/
static future(data) {
assert(data.symbol != null);
assert(data.lastTradeDateOrContractMonth != null);
return Contract._toContract(data, 'FUT', {
currency: 'USD',
exchange: 'ONE'
});
}
/*
symbol:
lastTradeDateOrContractMonth: The option's last trading day
or contract month.
* YYYYMM format: To specify last month
* YYYYMMDD format: To specify last trading day
strike: option's strike
right: Put or call option.
Valid values are 'P', 'PUT', 'C' or 'CALL'.
exchange: Destination exchange.
multiplier:
currency:
*/
static futuresOption(data) {
assert(data.symbol != null);
assert(data.right != null);
assert(data.lastTradeDateOrContractMonth != null);
assert(data.strike != null);
return Contract._toContract(data, 'FOP', {
currency: 'USD',
exchange: 'GLOBEX',
multiplier: 50
});
}
static index(symbolOrData) {
return Contract._toContract(symbolOrData, 'IND', {
currency: 'USD',
exchange: 'CBOE'
});
}
/*
symbol:
lastTradeDateOrContractMonth: The option's last trading day
or contract month.
* YYYYMM format: To specify last month
* YYYYMMDD format: To specify last trading day
strike: option's strike
right: Put or call option.
Valid values are 'P', 'PUT', 'C' or 'CALL'.
exchange: Destination exchange.
multiplier:
currency:
*/
static option(data) {
assert(data.symbol != null);
assert(data.right != null);
assert(data.lastTradeDateOrContractMonth != null);
assert(data.strike != null);
return Contract._toContract(data, 'OPT', {
currency: 'USD',
exchange: 'SMART',
multiplier: 100
});
}
static stock(symbolOrData) {
return Contract._toContract(symbolOrData, 'STK', {
currency: 'USD',
exchange: 'SMART'
});
};
static _toContract(symbolOrData, secType, defaults) {
if (typeof symbolOrData == 'string') {
let c = {
symbol: symbolOrData,
secType: secType
};
for (let k in defaults) {
c[k] = defaults[k];
}
return c;
}
assert(typeof symbolOrData.symbol == 'string');
assert(!symbolOrData.secType);
let c = {
secType: secType
};
for (let k in defaults) {
c[k] = defaults[k];
}
for (let k in symbolOrData) {
c[k] = symbolOrData[k];
}
return c;
}
}