@icgio/icg-utils 1.9.72 → 1.9.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/rates.js +0 -2
- package/lib/utils.js +37 -0
- package/package.json +2 -2
package/lib/rates.js
CHANGED
package/lib/utils.js
CHANGED
|
@@ -163,6 +163,39 @@ function price_position(input_array, price) {
|
|
|
163
163
|
return { price, avg_price: sum / vol ? sum / vol : price, vol, sum, pos }
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
// Mid of the best ask and best bid; null when either side is empty
|
|
167
|
+
function orderbook_mid(asks, bids) {
|
|
168
|
+
if (asks.length === 0 || bids.length === 0) return null
|
|
169
|
+
return (asks[0][0] + bids[0][0]) / 2
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Best ask minus best bid as a fraction of the mid (0.01 = 1%); null when either side is empty
|
|
173
|
+
function orderbook_spread(asks, bids) {
|
|
174
|
+
const mid = orderbook_mid(asks, bids)
|
|
175
|
+
return mid === null ? null : (asks[0][0] - bids[0][0]) / mid
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Quote value of one side's levels ([price, amount], best first) within ±pct% of any ref_price, edge included
|
|
179
|
+
function depth_within_pct(levels, ref_price, pct) {
|
|
180
|
+
const band = ref_price * (pct / 100) * (1 + 1e-9)
|
|
181
|
+
let sum = 0
|
|
182
|
+
for (const [price, amount] of levels) {
|
|
183
|
+
if (Math.abs(price - ref_price) > band) break
|
|
184
|
+
sum += price * amount
|
|
185
|
+
}
|
|
186
|
+
return sum
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Largest gap between adjacent prices in one side's first n levels, as a fraction of the price nearer the touch; null below two levels
|
|
190
|
+
function max_level_gap(levels, n) {
|
|
191
|
+
let gap = null
|
|
192
|
+
for (let i = 0; i + 1 < Math.min(n, levels.length); i++) {
|
|
193
|
+
const level_gap = Math.abs(levels[i + 1][0] - levels[i][0]) / levels[i][0]
|
|
194
|
+
if (gap === null || level_gap > gap) gap = level_gap
|
|
195
|
+
}
|
|
196
|
+
return gap
|
|
197
|
+
}
|
|
198
|
+
|
|
166
199
|
function sum_position(input_array, sum_target) {
|
|
167
200
|
if (input_array.length === 1) {
|
|
168
201
|
return {
|
|
@@ -904,6 +937,10 @@ module.exports = {
|
|
|
904
937
|
cut_orderbook,
|
|
905
938
|
level_position,
|
|
906
939
|
price_position,
|
|
940
|
+
orderbook_mid,
|
|
941
|
+
orderbook_spread,
|
|
942
|
+
depth_within_pct,
|
|
943
|
+
max_level_gap,
|
|
907
944
|
sum_position,
|
|
908
945
|
vol_position,
|
|
909
946
|
sum_position_orderbook,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icgio/icg-utils",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.74",
|
|
4
4
|
"description": "Utils package.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@influxdata/influxdb-client-apis": "^1.35.0",
|
|
25
25
|
"bintrees": "^1.0.2",
|
|
26
26
|
"csv-parse": "^7.0.2",
|
|
27
|
-
"lodash": "^4.
|
|
27
|
+
"lodash": "^4.18.1",
|
|
28
28
|
"needle": "^3.3.1",
|
|
29
29
|
"winston": "^2.4.5"
|
|
30
30
|
}
|