You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.6 KiB
103 lines
2.6 KiB
2 months ago
|
package memory
|
||
|
|
||
|
import (
|
||
|
"github.com/allegro/bigcache"
|
||
|
"github.com/shopspring/decimal"
|
||
|
"matchmaking-system/internal/pkg/utils"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
MoneyForexCache *bigcache.BigCache // 综合-外汇买一卖一报价缓存
|
||
|
MoneyForexPriceSetUp *bigcache.BigCache // 综合-外汇插针价格缓存
|
||
|
MoneyForexImmediateCache *bigcache.BigCache // 综合-外汇即时报价缓存
|
||
|
MoneySpotsCache *bigcache.BigCache // 综合-现货行情缓存
|
||
|
MoneyContractCache *bigcache.BigCache // 综合-合约行情缓存
|
||
|
MoneyContractPriceSetUp *bigcache.BigCache // 综合-合约插针价格缓存
|
||
|
MoneyTotalFloating *bigcache.BigCache // 综合-(现货|合约|外汇)统计总浮动盈亏
|
||
|
)
|
||
|
|
||
|
// init
|
||
|
//
|
||
|
// @Description: 初始化内存缓存
|
||
|
func init() {
|
||
|
MoneyForexCache = NewBigCache()
|
||
|
MoneyForexPriceSetUp = NewBigCache()
|
||
|
MoneyForexImmediateCache = NewBigCache()
|
||
|
MoneySpotsCache = NewBigCache()
|
||
|
MoneyContractCache = NewBigCache()
|
||
|
MoneyContractPriceSetUp = NewBigCache()
|
||
|
MoneyTotalFloating = NewBigCache()
|
||
|
}
|
||
|
|
||
|
// GetMoneySpotsCache
|
||
|
//
|
||
|
// @Description: 综合-现货行情数据
|
||
|
// @param key
|
||
|
// @return []byte
|
||
|
// @return error
|
||
|
func GetMoneySpotsCache(key string) ([]byte, error) {
|
||
|
conN, err := MoneySpotsCache.Get(key)
|
||
|
if err != nil {
|
||
|
return []byte{}, err
|
||
|
}
|
||
|
|
||
|
return conN, err
|
||
|
}
|
||
|
|
||
|
// GetMoneyContractCache
|
||
|
//
|
||
|
// @Description: 综合-合约行情数据
|
||
|
// @param key
|
||
|
// @return []byte
|
||
|
// @return error
|
||
|
func GetMoneyContractCache(key string) ([]byte, error) {
|
||
|
conP, err := MoneyContractPriceSetUp.Get(key)
|
||
|
if err != nil || string(conP) == decimal.Zero.String() || len(utils.StrReplace(string(conP))) == 0 {
|
||
|
conN, errs := MoneyContractCache.Get(key)
|
||
|
if errs != nil {
|
||
|
return []byte{}, errs
|
||
|
}
|
||
|
return conN, nil
|
||
|
}
|
||
|
|
||
|
return conP, err
|
||
|
}
|
||
|
|
||
|
// GetMoneyImmediateCache
|
||
|
//
|
||
|
// @Description: 综合-外汇实时行情
|
||
|
// @param key
|
||
|
// @return []byte
|
||
|
// @return error
|
||
|
func GetMoneyForexImmediateCache(key string) ([]byte, error) {
|
||
|
conP, err := MoneyForexPriceSetUp.Get(key)
|
||
|
if err != nil || string(conP) == decimal.Zero.String() || len(utils.StrReplace(string(conP))) == 0 {
|
||
|
conN, errs := MoneyForexImmediateCache.Get(key)
|
||
|
if errs != nil {
|
||
|
return []byte{}, errs
|
||
|
}
|
||
|
return conN, nil
|
||
|
}
|
||
|
|
||
|
return conP, err
|
||
|
}
|
||
|
|
||
|
// GetMoneyCache
|
||
|
//
|
||
|
// @Description: 综合-外汇(买一卖一)实时行情
|
||
|
// @param key
|
||
|
// @return []byte
|
||
|
// @return error
|
||
|
func GetMoneyForexCache(key string) ([]byte, error) {
|
||
|
conP, err := MoneyForexPriceSetUp.Get(key)
|
||
|
if err != nil || string(conP) == decimal.Zero.String() || len(utils.StrReplace(string(conP))) == 0 {
|
||
|
conN, errs := MoneyForexCache.Get(key)
|
||
|
if errs != nil {
|
||
|
return []byte{}, errs
|
||
|
}
|
||
|
return conN, nil
|
||
|
}
|
||
|
|
||
|
return conP, err
|
||
|
}
|