@@ -16,8 +16,7 @@ const hcUnitConverter = type => {
16
16
const autoAdjustGetData = ( api , symbol , start , end , style = 'ticks' , granularity = 60 ) => {
17
17
const secs = end - start ;
18
18
const ticksCount = secs / 2 ;
19
- if ( ticksCount >= 5000 ) {
20
- style = 'candles' ;
19
+ if ( ticksCount >= 5000 || style === 'candles' ) {
21
20
const idealGranularity = secs / 4999 ;
22
21
granularities . forEach ( ( g , i ) => {
23
22
if ( idealGranularity > g && idealGranularity <= granularities [ i + 1 ] ) {
@@ -31,18 +30,18 @@ const autoAdjustGetData = (api, symbol, start, end, style = 'ticks', granularity
31
30
end,
32
31
adjust_start_time : 1 ,
33
32
count : 4999 ,
34
- style,
33
+ style : 'candles' ,
35
34
granularity,
36
35
}
37
- ) . then ( r => ohlcDataToTicks ( r . candles ) ) ;
36
+ ) . then ( r => style === 'ticks' ? ohlcDataToTicks ( r . candles ) : r . candles ) ;
38
37
}
39
38
return api . getTickHistory ( symbol ,
40
39
{
41
40
start,
42
41
end,
43
42
adjust_start_time : 1 ,
44
43
count : 4999 ,
45
- style,
44
+ style : 'ticks' ,
46
45
}
47
46
) . then ( r => {
48
47
const ticks = r . history . times . map ( ( t , idx ) => {
@@ -60,11 +59,11 @@ const autoAdjustGetData = (api, symbol, start, end, style = 'ticks', granularity
60
59
* @param durationCount
61
60
* @param durationType
62
61
*/
63
- export function getDataForSymbol ( api , symbol , durationCount = 1 , durationType = 'all' ) {
62
+ export function getDataForSymbol ( api , symbol , durationCount = 1 , durationType = 'all' , style = 'ticks' ) {
64
63
const durationUnit = hcUnitConverter ( durationType ) ;
65
64
const end = nowEpoch ( ) ;
66
65
const start = end - durationToSecs ( durationCount , durationUnit ) ;
67
- return autoAdjustGetData ( api , symbol , start , end ) ;
66
+ return autoAdjustGetData ( api , symbol , start , end , style ) ;
68
67
}
69
68
70
69
/**
@@ -73,7 +72,9 @@ export function getDataForSymbol(api, symbol, durationCount = 1, durationType =
73
72
* @param getContract - function that accept nothing and return a Promise containing contract
74
73
* @param durationCount - number of duration
75
74
* @param durationType - type of duration, check http://api.highcharts.com/highstock#rangeSelector.buttons
76
- * @param style - one of ['ticks', 'candles'], check https://developers.binary.com/api/#ticks_history
75
+ * @param style - one of ['ticks', 'candles'], this will affect the return data shape,
76
+ * internally library might not always use this param when requesting, eg. when data is too large,
77
+ * library will use `candles` instead of `ticks`, this is handle by library so user do not need to worry
77
78
* @param granularity - default to 60, check https://developers.binary.com/api/#ticks_history
78
79
* @returns {*|Promise.<TResult> }
79
80
*/
@@ -87,8 +88,7 @@ export function getDataForContract(
87
88
) {
88
89
const getAllData = ( ) =>
89
90
getContract ( )
90
- . then ( r => {
91
- const contract = r . proposal_open_contract ;
91
+ . then ( contract => {
92
92
const symbol = contract . underlying ;
93
93
if ( contract . tick_count ) {
94
94
const start = contract . purchase_time ;
0 commit comments