-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathws_status_messages_deriv.js
More file actions
81 lines (75 loc) · 2.27 KB
/
ws_status_messages_deriv.js
File metadata and controls
81 lines (75 loc) · 2.27 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
71
72
73
74
75
76
77
78
79
80
81
'use strict'
const stringValidator = require('./validators/string')
const priceValidator = require('./validators/price')
const Model = require('./model')
const fields = {
timestamp: 0,
price: 2,
priceSpot: 3,
fundBal: 5,
fundingEventTimestamp: 7,
fundingAccrued: 8,
fundingStep: 9,
currentFunding: 11,
markprice: 14,
openInterest: 17,
clampMin: 21,
clampMax: 22
}
/**
* Derivatives Status Message model used by the websocket
*/
class StatusMessagesDerivWS extends Model {
/**
* @param {object|Array} data - derivatives status message data
* @param {number} data.timestamp - timestamp
* @param {string} data.price - price
* @param {string} data.priceSpot - spot price
* @param {string} data.fundBal - funding balance
* @param {number} data.fundingEventTimestamp - timestamp
* @param {string} data.fundingAccrued - accrued funding
* @param {string} data.fundingStep - funding step
* @param {number} data.currentFunding - funding applied in the current 8h period,
* @param {number} data.markprice - markprice,
* @param {number} data.openInterest - total number of outstanding derivative contracts,
* @param {number} data.clampMin - min clamp
* @param {number} data.clampMax - max clamp
*/
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 public trade instance
*
* @param {object[]|object|PublicTrade[]|PublicTrade|Array} data - instance to validate
* @returns {string} error - null if instance is valid
*/
static validate (data) {
return super.validate({
data,
fields,
validators: {
timestamp: stringValidator,
price: priceValidator,
priceSpot: priceValidator,
fundBal: priceValidator,
fundingEventTimestamp: stringValidator,
fundingAccrued: priceValidator,
fundingStep: priceValidator,
currentFunding: priceValidator,
markprice: priceValidator,
openInterest: priceValidator,
clampMin: priceValidator,
clampMax: priceValidator
}
})
}
}
module.exports = StatusMessagesDerivWS