-
Notifications
You must be signed in to change notification settings - Fork 4
/
kline.go
87 lines (72 loc) · 2.13 KB
/
kline.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
package kline
import (
"sync"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/zenchainprotocol/zenchain-node/x/backend"
"github.com/zenchainprotocol/zenchain-node/x/dex"
"github.com/zenchainprotocol/zenchain-node/x/stream/common"
"github.com/zenchainprotocol/zenchain-node/x/stream/types"
)
var (
marketIDMap = make(map[string]int64, 200)
initMapOnce sync.Once
)
func InitTokenPairMap(ctx sdk.Context, dexKeeper types.DexKeeper) {
initMapOnce.Do(func() {
tokenPairs := dexKeeper.GetTokenPairs(ctx)
for i := 0; i < len(tokenPairs); i++ {
marketIDMap[tokenPairs[i].Name()] = int64(tokenPairs[i].ID)
}
})
}
func GetMarketIDMap() map[string]int64 {
return marketIDMap
}
type MarketConfig struct {
MarketServiceEnable bool
MarketNacosUrls string
MarketNacosNamespaceId string
MarketNacosClusters []string
MarketNacosServiceName string
MarketNacosGroupName string
}
func NewMarketConfig(enable bool, urls, nameSpace string, clusters []string, serviceName, groupName string) MarketConfig {
return MarketConfig{
MarketServiceEnable: enable,
MarketNacosUrls: urls,
MarketNacosNamespaceId: nameSpace,
MarketNacosClusters: clusters,
MarketNacosServiceName: serviceName,
MarketNacosGroupName: groupName,
}
}
type KlineData struct {
Height int64
matchResults []*backend.MatchResult
newTokenPairs []*dex.TokenPair
}
func NewKlineData() *KlineData {
return &KlineData{
matchResults: make([]*backend.MatchResult, 0),
}
}
func (kd KlineData) BlockHeight() int64 {
return kd.Height
}
func (kd KlineData) DataType() types.StreamDataKind {
return types.StreamDataKlineKind
}
func (kd *KlineData) SetData(ctx sdk.Context, orderKeeper types.OrderKeeper, cache *common.Cache) {
kd.Height = ctx.BlockHeight()
kd.matchResults = common.GetMatchResults(ctx, orderKeeper)
kd.newTokenPairs = cache.GetNewTokenPairs()
}
func (kd *KlineData) GetNewTokenPairs() []*dex.TokenPair {
return kd.newTokenPairs
}
func (kd *KlineData) GetMatchResults() []*backend.MatchResult {
return kd.matchResults
}
func (kd *KlineData) SetMatchResults(matchResults []*backend.MatchResult) {
kd.matchResults = matchResults
}