-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspotprice.go
72 lines (61 loc) · 1.43 KB
/
spotprice.go
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
package main
import (
"github.com/go-resty/resty/v2"
"log"
"time"
)
type SpotPriceEntry struct {
Id int
StartDate string
EndDate string
Price float64
}
//var SpotCount = 0
func GetSpotPrice() (float64, bool) {
var SpotPrices []SpotPriceEntry
client := resty.New()
_, err := client.R().
EnableTrace().
SetResult(&SpotPrices).
Get(Cfg.Tscapi + "/api/ChargingCost/GetSpotPrices")
if err != nil {
log.Fatal(err)
return 0, false
}
currentTime := time.Now()
location, err := time.LoadLocation("UTC")
if err != nil {
panic(err)
}
SpotPriceDateLayout := "2006-01-02T15:04:05"
SpotPriceDateLayout2 := "2006-01-02T15:04:05Z"
//SpotPriceDateLayout := time.RFC3339
//SpotCount++
// For Testing
//if SpotCount > 10 {
// return 100, true
//}
//return -2, true
for _, entry := range SpotPrices {
StartDate, err := time.ParseInLocation(SpotPriceDateLayout, entry.StartDate, location)
if err != nil {
StartDate, err = time.ParseInLocation(SpotPriceDateLayout2, entry.StartDate, location)
if err != nil {
panic(err)
}
}
EndDate, err := time.ParseInLocation(SpotPriceDateLayout, entry.EndDate, location)
if err != nil {
EndDate, err = time.ParseInLocation(SpotPriceDateLayout2, entry.EndDate, location)
if err != nil {
panic(err)
}
}
if currentTime.After(StartDate) &&
currentTime.Before(EndDate) {
//fmt.Println("FOUND")
return entry.Price, true
}
}
return 0, false
}