github.com/polygon-io/client-go@v1.16.4/rest/models/indicators_test.go (about)

     1  package models_test
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/polygon-io/client-go/rest/models"
     8  )
     9  
    10  func TestGetSMAParams(t *testing.T) {
    11  	timespan := models.Week
    12  	timestamp := models.Millis(time.Date(2022, 7, 25, 0, 0, 0, 0, time.UTC))
    13  	series := models.Close
    14  	expand := true
    15  	adjusted := true
    16  	order := models.Asc
    17  	limit := 100
    18  	window := 5
    19  	expect := models.GetSMAParams{
    20  		Timespan:         &timespan,
    21  		TimestampEQ:      &timestamp,
    22  		TimestampLT:      &timestamp,
    23  		TimestampLTE:     &timestamp,
    24  		TimestampGT:      &timestamp,
    25  		TimestampGTE:     &timestamp,
    26  		SeriesType:       &series,
    27  		ExpandUnderlying: &expand,
    28  		Adjusted:         &adjusted,
    29  		Order:            &order,
    30  		Limit:            &limit,
    31  		Window:           &window,
    32  	}
    33  	actual := models.GetSMAParams{}.
    34  		WithTimespan(timespan).
    35  		WithTimestamp(models.EQ, timestamp).
    36  		WithTimestamp(models.LT, timestamp).
    37  		WithTimestamp(models.LTE, timestamp).
    38  		WithTimestamp(models.GT, timestamp).
    39  		WithTimestamp(models.GTE, timestamp).
    40  		WithSeriesType(series).
    41  		WithExpandUnderlying(expand).
    42  		WithAdjusted(adjusted).
    43  		WithOrder(order).
    44  		WithLimit(limit).
    45  		WithWindow(window)
    46  
    47  	checkParams(t, expect, *actual)
    48  }
    49  
    50  func TestGetEMAParams(t *testing.T) {
    51  	timespan := models.Week
    52  	timestamp := models.Millis(time.Date(2022, 7, 25, 0, 0, 0, 0, time.UTC))
    53  	series := models.Close
    54  	expand := true
    55  	adjusted := true
    56  	order := models.Asc
    57  	limit := 100
    58  	window := 5
    59  	expect := models.GetEMAParams{
    60  		Timespan:         &timespan,
    61  		TimestampEQ:      &timestamp,
    62  		TimestampLT:      &timestamp,
    63  		TimestampLTE:     &timestamp,
    64  		TimestampGT:      &timestamp,
    65  		TimestampGTE:     &timestamp,
    66  		SeriesType:       &series,
    67  		ExpandUnderlying: &expand,
    68  		Adjusted:         &adjusted,
    69  		Order:            &order,
    70  		Limit:            &limit,
    71  		Window:           &window,
    72  	}
    73  	actual := models.GetEMAParams{}.
    74  		WithTimespan(timespan).
    75  		WithTimestamp(models.EQ, timestamp).
    76  		WithTimestamp(models.LT, timestamp).
    77  		WithTimestamp(models.LTE, timestamp).
    78  		WithTimestamp(models.GT, timestamp).
    79  		WithTimestamp(models.GTE, timestamp).
    80  		WithSeriesType(series).
    81  		WithExpandUnderlying(expand).
    82  		WithAdjusted(adjusted).
    83  		WithOrder(order).
    84  		WithLimit(limit).
    85  		WithWindow(window)
    86  
    87  	checkParams(t, expect, *actual)
    88  }
    89  
    90  func TestGetRSIParams(t *testing.T) {
    91  	timespan := models.Week
    92  	timestamp := models.Millis(time.Date(2022, 7, 25, 0, 0, 0, 0, time.UTC))
    93  	series := models.Close
    94  	expand := true
    95  	adjusted := true
    96  	order := models.Asc
    97  	limit := 100
    98  	window := 5
    99  	expect := models.GetRSIParams{
   100  		Timespan:         &timespan,
   101  		TimestampEQ:      &timestamp,
   102  		TimestampLT:      &timestamp,
   103  		TimestampLTE:     &timestamp,
   104  		TimestampGT:      &timestamp,
   105  		TimestampGTE:     &timestamp,
   106  		SeriesType:       &series,
   107  		ExpandUnderlying: &expand,
   108  		Adjusted:         &adjusted,
   109  		Order:            &order,
   110  		Limit:            &limit,
   111  		Window:           &window,
   112  	}
   113  	actual := models.GetRSIParams{}.
   114  		WithTimespan(timespan).
   115  		WithTimestamp(models.EQ, timestamp).
   116  		WithTimestamp(models.LT, timestamp).
   117  		WithTimestamp(models.LTE, timestamp).
   118  		WithTimestamp(models.GT, timestamp).
   119  		WithTimestamp(models.GTE, timestamp).
   120  		WithSeriesType(series).
   121  		WithExpandUnderlying(expand).
   122  		WithAdjusted(adjusted).
   123  		WithOrder(order).
   124  		WithLimit(limit).
   125  		WithWindow(window)
   126  
   127  	checkParams(t, expect, *actual)
   128  }
   129  
   130  func TestGetMACDParams(t *testing.T) {
   131  	timespan := models.Week
   132  	timestamp := models.Millis(time.Date(2022, 7, 25, 0, 0, 0, 0, time.UTC))
   133  	series := models.Close
   134  	expand := true
   135  	adjusted := true
   136  	order := models.Asc
   137  	limit := 100
   138  	shortWindow := 12
   139  	longWindow := 26
   140  	signalWindow := 9
   141  	expect := models.GetMACDParams{
   142  		Timespan:         &timespan,
   143  		TimestampEQ:      &timestamp,
   144  		TimestampLT:      &timestamp,
   145  		TimestampLTE:     &timestamp,
   146  		TimestampGT:      &timestamp,
   147  		TimestampGTE:     &timestamp,
   148  		SeriesType:       &series,
   149  		ExpandUnderlying: &expand,
   150  		Adjusted:         &adjusted,
   151  		Order:            &order,
   152  		Limit:            &limit,
   153  		ShortWindow:      &shortWindow,
   154  		LongWindow:       &longWindow,
   155  		SignalWindow:     &signalWindow,
   156  	}
   157  	actual := models.GetMACDParams{}.
   158  		WithTimespan(timespan).
   159  		WithTimestamp(models.EQ, timestamp).
   160  		WithTimestamp(models.LT, timestamp).
   161  		WithTimestamp(models.LTE, timestamp).
   162  		WithTimestamp(models.GT, timestamp).
   163  		WithTimestamp(models.GTE, timestamp).
   164  		WithSeriesType(series).
   165  		WithExpandUnderlying(expand).
   166  		WithAdjusted(adjusted).
   167  		WithOrder(order).
   168  		WithLimit(limit).
   169  		WithShortWindow(shortWindow).
   170  		WithLongWindow(longWindow).
   171  		WithSignalWindow(signalWindow)
   172  
   173  	checkParams(t, expect, *actual)
   174  }