@@ -14,7 +14,9 @@ type ratesSource interface {
14
14
}
15
15
16
16
type calculator struct {
17
- mu sync.RWMutex
17
+ mu sync.RWMutex
18
+ // The source contains complex logic hidden in the ratesSource interface, which is not available in the open source version
19
+ // See the Mock description for details
18
20
source ratesSource
19
21
todayRates , yesterdayRates , weekRates , monthRates map [string ]float64
20
22
marketsTonPrice []Market
@@ -54,7 +56,6 @@ func (c *calculator) refresh() {
54
56
if err != nil {
55
57
return
56
58
}
57
-
58
59
todayRates , err := c .source .GetRates (today .Unix ())
59
60
if err != nil {
60
61
return
@@ -72,13 +73,13 @@ func (c *calculator) refresh() {
72
73
return
73
74
}
74
75
75
- c .mu .RLock ()
76
+ c .mu .Lock ()
76
77
c .todayRates = todayRates
77
78
c .yesterdayRates = yesterdayRates
78
79
c .weekRates = weekRates
79
80
c .monthRates = monthRates
80
81
c .marketsTonPrice = marketsTonPrice
81
- c .mu .RUnlock ()
82
+ c .mu .Unlock ()
82
83
}
83
84
84
85
func (c * calculator ) GetRates (date int64 ) (map [string ]float64 , error ) {
@@ -115,11 +116,16 @@ func (c *calculator) GetMarketsTonPrice() ([]Market, error) {
115
116
}
116
117
117
118
type Mock struct {
118
- TonApiToken string
119
+ // TonApiToken the token for TonApi to increase HTTP limits is obtained from https://tonconsole.com/tonapi
120
+ TonApiToken string
121
+ // URL to the CSV file from the analytics service https://tonconsole.com/analytics (data is sourced from the TonApi analytics database)
119
122
StonFiResultUrl string
123
+ // URL to the CSV file from the analytics service https://tonconsole.com/analytics (data is sourced from the TonApi analytics database)
120
124
DedustResultUrl string
121
125
}
122
126
127
+ // GetRates cannot request data for a specific date in the open source version
128
+ // It will always return data for the current day
123
129
func (m Mock ) GetRates (date int64 ) (map [string ]float64 , error ) {
124
130
return m .GetCurrentRates ()
125
131
}
@@ -128,6 +134,8 @@ func (m Mock) GetMarketsTonPrice() ([]Market, error) {
128
134
return m .GetCurrentMarketsTonPrice ()
129
135
}
130
136
137
+ // GetRatesChart cannot be used to request charts for jettons in the open source version
138
+ // To use this method, you must save today's data from GetRates and then override the method
131
139
func (m Mock ) GetRatesChart (token string , currency string , pointsCount int , startDate * int64 , endDate * int64 ) ([][]any , error ) {
132
140
return [][]any {}, nil
133
141
}
0 commit comments