-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem_coin.go
135 lines (120 loc) · 4.56 KB
/
mem_coin.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"fmt"
"strconv"
"time"
s "github.com/ValidatorCenter/prs3r/strc"
"github.com/go-redis/redis"
)
// Создать/обновить информационную запись о Монете
func updCoinInfoRds(db *redis.Client, dt *s.CoinMarketCapData) bool {
if dt.CoinSymbol != "" {
m2 := map[string]interface{}{
"coin_url": dt.CoinURL,
"coin_logo_img": dt.CoinLogoImg,
"coin_desciption": dt.CoinDesc,
"time_update": dt.TimeUpdate.Format("2006-01-02T15:04:05.999999-07:00"),
"volume_now_f32": dt.VolumeNow,
"reserve_balance_now_f32": dt.ReserveBalanceNow,
"amnt_trans_24x7": dt.AmntTrans24x7,
}
err := db.HMSet(fmt.Sprintf("%s_info", dt.CoinSymbol), m2).Err()
if err != nil {
log("ERR", fmt.Sprint("[mem_coin.go] updCoinInfoRds(hmset...", dt.CoinSymbol, ") - ", err), "")
return false
}
} else {
log("ERR", "[mem_coin.go] updCoinInfoRds(...) Coin = '???'", "")
return false
}
log("INF", "INSERT/UPDATE", fmt.Sprintf("%s_info", dt.CoinSymbol))
return true
}
// Обновить информацию о 3-х View записях в Монете (coin_url, coin_logo_img, coin_desciption)
func updCoinInfoRds_3v(db *redis.Client, dt *s.CoinMarketCapData) bool {
if dt.CoinSymbol != "" {
m2 := map[string]interface{}{
"coin_url": dt.CoinURL,
"coin_logo_img": dt.CoinLogoImg,
"coin_desciption": dt.CoinDesc,
}
err := db.HMSet(fmt.Sprintf("%s_info", dt.CoinSymbol), m2).Err()
if err != nil {
log("ERR", fmt.Sprint("[mem_coin.go] updCoinInfoRds_3v(hmset...", dt.CoinSymbol, ") - ", err), "")
return false
}
} else {
log("ERR", "[mem_coin.go] updCoinInfoRds_3v(...) Coin = '???'", "")
return false
}
log("INF", "UPDATE", fmt.Sprintf("%s_info(3v)", dt.CoinSymbol))
return true
}
// Поиск информации о Монете
func srchCoinInfoRds(db *redis.Client, dt *s.CoinMarketCapData) bool {
if dt.CoinSymbol != "" {
_lbRes, err := db.HGetAll(fmt.Sprintf("%s_info", dt.CoinSymbol)).Result()
if err != nil {
log("ERR", fmt.Sprint("[mem_coin.go] srchCoinInfoRds(hgetall...", dt.CoinSymbol, ") - ", err), "")
return false
}
// Всё "хорошо", заносим в dt новые данные
dt.CoinURL = _lbRes["coin_url"]
dt.CoinLogoImg = _lbRes["coin_logo_img"]
dt.CoinDesc = _lbRes["coin_desciption"]
dt.TimeUpdate, _ = time.Parse(time.RFC3339, _lbRes["time_update"])
dt_VolumeNow, _ := strconv.ParseFloat(_lbRes["volume_now_f32"], 32)
dt.VolumeNow = float32(dt_VolumeNow)
dt_ReserveBalanceNow, _ := strconv.ParseFloat(_lbRes["reserve_balance_now_f32"], 32)
dt.ReserveBalanceNow = float32(dt_ReserveBalanceNow)
dt.AmntTrans24x7, _ = strconv.Atoi(_lbRes["amnt_trans_24x7"])
} else {
log("ERR", "[mem_coin.go] srchCoinInfoRds(...) = '???'", "")
return false
}
return true
}
// Обновить данные о паре-монет (redis)
func updCoin2Redis(db *redis.Client, dt *s.PairCoins) bool {
if dt.CoinToBuy != "" && dt.CoinToSell != "" {
m2 := map[string]interface{}{
"coin_to_buy": dt.CoinToBuy,
"coin_to_sell": dt.CoinToSell,
"price_buy_f32": dt.PriceBuy,
"price_sell_f32": dt.PriceSell,
"volume_24_f32": dt.Volume24,
"change_24_f32": dt.Change24,
"time_update": dt.TimeUpdate.Format("2006-01-02T15:04:05.999999-07:00"),
}
err := db.HMSet(fmt.Sprintf("%s%s_c2c", dt.CoinToBuy, dt.CoinToSell), m2).Err()
if err != nil {
log("ERR", fmt.Sprint("[mem_coin.go] updCoin2Redis(hmset...", dt.CoinToBuy, ") - ", err), "")
return false
}
} else {
log("ERR", "[mem_coin.go] updCoin2Redis(...) Coin_1 = '???' & Coin_2 = '???'", "")
return false
}
log("INF", "INSERT/UPDATE", fmt.Sprintf("%s%s_c2c", dt.CoinToBuy, dt.CoinToSell))
return true
}
// Обновить информацию о 3-х записях в Монете (time_update, volume_now_f32, reserve_balance_now_f32)
func updCoinInfoRds_3(db *redis.Client, dt *s.CoinMarketCapData) bool {
if dt.CoinSymbol != "" {
m2 := map[string]interface{}{
"time_update": dt.TimeUpdate.Format("2006-01-02T15:04:05.999999-07:00"),
"volume_now_f32": dt.VolumeNow,
"reserve_balance_now_f32": dt.ReserveBalanceNow,
}
err := db.HMSet(fmt.Sprintf("%s_info", dt.CoinSymbol), m2).Err()
if err != nil {
log("ERR", fmt.Sprint("[mem_coin.go] updCoinInfoRds_3(hmset...", dt.CoinSymbol, ") - ", err), "")
return false
}
} else {
log("ERR", "[mem_coin.go] updCoinInfoRds_3(...) Coin = '???'", "")
return false
}
log("INF", "UPDATE", fmt.Sprintf("%s_info(3)", dt.CoinSymbol))
return true
}