-
Notifications
You must be signed in to change notification settings - Fork 27
/
index.js
110 lines (98 loc) · 3.63 KB
/
index.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
import historyProvider from './historyProvider'
import stream from './stream'
import { data } from './pairs'
const supportedResolutions = ["1", "3", "5", "15", "30", "60", "120", "240", "D", "W"]
const config = {
supported_resolutions: supportedResolutions
};
export default {
onReady: cb => {
// console.log('=====onReady running')
setTimeout(() => cb(config), 0)
},
searchSymbols: (userInput, exchange, symbolType, onResultReadyCallback) => {
for (var i = 0; i < data.length; ++i) {
if (!data[i].params) {
data[i].params = [];
}
}
if (typeof data.s == 'undefined' || data.s != 'error') {
onResultReadyCallback(data);
} else {
onResultReadyCallback([]);
}
// console.log('====Search Symbols running')
},
resolveSymbol: (symbolName, onSymbolResolvedCallback, onResolveErrorCallback) => {
// expects a symbolInfo object in response
// console.log('======resolveSymbol running')
// console.log('resolveSymbol:',{symbolName})
var split_data = symbolName.split(/[:/]/)
// console.log({split_data})
var symbol_stub = {
name: symbolName,
description: '',
type: 'crypto',
session: '24x7',
timezone: 'Etc/UTC',
ticker: symbolName,
minmov: 1,
pricescale: 100000000,
has_intraday: true,
intraday_multipliers: ['1', '60'],
supported_resolution: supportedResolutions,
volume_precision: 8,
data_status: 'streaming',
}
if (split_data[1].match(/USD|EUR|JPY|AUD|GBP|KRW|CNY/)) {
symbol_stub.pricescale = 100
}
setTimeout(function() {
onSymbolResolvedCallback(symbol_stub)
// console.log('Resolving that symbol....', symbol_stub)
}, 0)
// onResolveErrorCallback('Not feeling it today')
},
getBars: function(symbolInfo, resolution, from, to, onHistoryCallback, onErrorCallback, firstDataRequest) {
// console.log('=====getBars running')
// console.log('function args',arguments)
// console.log(`Requesting bars between ${new Date(from * 1000).toISOString()} and ${new Date(to * 1000).toISOString()}`)
historyProvider.getBars(symbolInfo, resolution, from, to, firstDataRequest)
.then(bars => {
if (bars.length) {
onHistoryCallback(bars, {noData: false})
} else {
onHistoryCallback(bars, {noData: true})
}
}).catch(err => {
// console.log({err})
onErrorCallback(err)
})
},
subscribeBars: (symbolInfo, resolution, onRealtimeCallback, subscribeUID, onResetCacheNeededCallback) => {
// console.log('=====subscribeBars runnning')
stream.subscribeBars(symbolInfo, resolution, onRealtimeCallback, subscribeUID, onResetCacheNeededCallback)
},
unsubscribeBars: subscriberUID => {
// console.log('=====unsubscribeBars running')
stream.unsubscribeBars(subscriberUID)
},
calculateHistoryDepth: (resolution, resolutionBack, intervalBack) => {
//optional
// console.log('=====calculateHistoryDepth running')
// while optional, this makes sure we request 24 hours of minute data at a time
// CryptoCompare's minute data endpoint will throw an error if we request data beyond 7 days in the past, and return no data
return resolution < 60 ? {resolutionBack: 'D', intervalBack: '1'} : undefined
},
getMarks: (symbolInfo, startDate, endDate, onDataCallback, resolution) => {
//optional
// console.log('=====getMarks running')
},
getTimeScaleMarks: (symbolInfo, startDate, endDate, onDataCallback, resolution) => {
//optional
// console.log('=====getTimeScaleMarks running')
},
getServerTime: cb => {
// console.log('=====getServerTime running')
}
}