-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathweighted_averages.js
More file actions
70 lines (65 loc) · 2 KB
/
weighted_averages.js
File metadata and controls
70 lines (65 loc) · 2 KB
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
'use strict'
const numberValidator = require('./validators/number')
const Model = require('./model')
const fields = {
tradeCount: 0,
sumBuyingSpent: 1,
sumBuyingAmount: 2,
sumSellingSpent: 4,
sumSellingAmount: 5,
buyingWeightedPrice: 7,
sellingWeightedPrice: 8,
firstTradeMts: 10,
lastTradeMts: 11
}
/**
* Weighted Averages model
*/
class WeightedAverages extends Model {
/**
* @param {object|Array} data - weighted averages data
* @param {number} data.tradeCount - trade count
* @param {number} data.sumBuyingSpent - sum buying spent
* @param {number} data.sumBuyingAmount - sum buying amount
* @param {number} data.sumSellingSpent - sum selling spent
* @param {number} data.sumSellingAmount - sum selling amount
* @param {number} data.buyingWeightedPrice - buying weighted price
* @param {number} data.sellingWeightedPrice - selling weighted price
* @param {number} data.firstTradeMts - first trade ms timestamp
* @param {number} data.lastTradeMts - last trade ms timestamp
*/
constructor (data = {}) {
super({ data, fields })
}
/**
* @param {object[]|object|Array[]|Array} data - data to convert to POJO
* @returns {object} pojo
*/
static unserialize (data) {
return super.unserialize({ data, fields })
}
/**
* Validates a given WeightedAverages instance
*
* @param {object[]|object|WeightedAverages[]|WeightedAverages|Array} data - instance to validate
* @returns {string} error - null if instance is valid
*/
static validate (data) {
return super.validate({
data,
fields,
validators: {
tradeCount: numberValidator,
sumBuyingSpent: numberValidator,
sumBuyingAmount: numberValidator,
sumSellingSpent: numberValidator,
sumSellingAmount: numberValidator,
buyingWeightedPrice: numberValidator,
sellingWeightedPrice: numberValidator,
firstTradeMts: numberValidator,
lastTradeMts: numberValidator
}
})
}
}
module.exports = WeightedAverages