Skip to content

Commit b4700f3

Browse files
update the rates service to calculate the jettons price by the liquidity pool
1 parent 10df47b commit b4700f3

File tree

6 files changed

+373
-173
lines changed

6 files changed

+373
-173
lines changed

pkg/rates/calculator.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ type ratesSource interface {
1414
}
1515

1616
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
1820
source ratesSource
1921
todayRates, yesterdayRates, weekRates, monthRates map[string]float64
2022
marketsTonPrice []Market
@@ -54,7 +56,6 @@ func (c *calculator) refresh() {
5456
if err != nil {
5557
return
5658
}
57-
5859
todayRates, err := c.source.GetRates(today.Unix())
5960
if err != nil {
6061
return
@@ -72,13 +73,13 @@ func (c *calculator) refresh() {
7273
return
7374
}
7475

75-
c.mu.RLock()
76+
c.mu.Lock()
7677
c.todayRates = todayRates
7778
c.yesterdayRates = yesterdayRates
7879
c.weekRates = weekRates
7980
c.monthRates = monthRates
8081
c.marketsTonPrice = marketsTonPrice
81-
c.mu.RUnlock()
82+
c.mu.Unlock()
8283
}
8384

8485
func (c *calculator) GetRates(date int64) (map[string]float64, error) {
@@ -115,11 +116,16 @@ func (c *calculator) GetMarketsTonPrice() ([]Market, error) {
115116
}
116117

117118
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)
119122
StonFiResultUrl string
123+
// URL to the CSV file from the analytics service https://tonconsole.com/analytics (data is sourced from the TonApi analytics database)
120124
DedustResultUrl string
121125
}
122126

127+
// GetRates cannot request data for a specific date in the open source version
128+
// It will always return data for the current day
123129
func (m Mock) GetRates(date int64) (map[string]float64, error) {
124130
return m.GetCurrentRates()
125131
}
@@ -128,6 +134,8 @@ func (m Mock) GetMarketsTonPrice() ([]Market, error) {
128134
return m.GetCurrentMarketsTonPrice()
129135
}
130136

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
131139
func (m Mock) GetRatesChart(token string, currency string, pointsCount int, startDate *int64, endDate *int64) ([][]any, error) {
132140
return [][]any{}, nil
133141
}

0 commit comments

Comments
 (0)