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.
92 lines
2.2 KiB
92 lines
2.2 KiB
package memory
|
|
|
|
import (
|
|
"github.com/allegro/bigcache"
|
|
"github.com/shopspring/decimal"
|
|
"matchmaking-system/internal/pkg/utils"
|
|
)
|
|
|
|
var (
|
|
OptionInrCache *bigcache.BigCache // 期权印度股行情缓存
|
|
OptionInrChgMark *bigcache.BigCache // 期权印度股买涨|买跌-涨跌幅标识
|
|
OptionInrClosePrice *bigcache.BigCache // 期权印度股闭盘价格
|
|
OptionInrForcedClosure *bigcache.BigCache // 期权印度股设置强平阈值
|
|
OptionInrFloating *bigcache.BigCache // 期权印度股统计总浮动盈亏
|
|
OptionInrStrike *bigcache.BigCache // 期权印度股行权价
|
|
OptionInrBid *bigcache.BigCache // 期权印度买一价格
|
|
OptionInrAsk *bigcache.BigCache // 期权印度卖一价格
|
|
)
|
|
|
|
// init
|
|
//
|
|
// @Description: 初始化期权-内存缓存
|
|
func init() {
|
|
OptionInrCache = NewBigCache()
|
|
OptionInrChgMark = NewBigCache()
|
|
OptionInrClosePrice = NewBigCache()
|
|
OptionInrForcedClosure = NewBigCache()
|
|
OptionInrFloating = NewBigCache()
|
|
OptionInrStrike = NewBigCache()
|
|
OptionInrBid = NewBigCache()
|
|
OptionInrAsk = NewBigCache()
|
|
}
|
|
|
|
// GetOptionInrStrike
|
|
//
|
|
// @Description: 期权-印度行权价
|
|
// @param key
|
|
// @return []byte
|
|
// @return error
|
|
func GetOptionInrStrike(key string) ([]byte, error) {
|
|
inrP, err := OptionInrStrike.Get(key)
|
|
if err != nil {
|
|
return []byte("0"), nil
|
|
}
|
|
|
|
return inrP, nil
|
|
}
|
|
|
|
// GetOptionInrCache
|
|
//
|
|
// @Description: 期权-印度交易价格(用来计算浮动盈亏)
|
|
// @param key
|
|
// @return []byte
|
|
// @return error
|
|
func GetOptionInrCache(key string) ([]byte, error) {
|
|
inrP, err := OptionInrCache.Get(key)
|
|
if err != nil || string(inrP) == decimal.Zero.String() || len(utils.StrReplace(string(inrP))) == 0 {
|
|
return []byte("0"), nil
|
|
}
|
|
|
|
return inrP, nil
|
|
}
|
|
|
|
// GetOptionInrBid
|
|
//
|
|
// @Description: 期权-印度买一价格
|
|
// @param key
|
|
// @return []byte
|
|
// @return error
|
|
func GetOptionInrBid(key string) ([]byte, error) {
|
|
inrP, err := OptionInrBid.Get(key)
|
|
if err != nil {
|
|
return []byte("0"), nil
|
|
}
|
|
|
|
return inrP, nil
|
|
}
|
|
|
|
// GetOptionInrAsk
|
|
//
|
|
// @Description: 期权-印度卖一价格
|
|
// @param key
|
|
// @return []byte
|
|
// @return error
|
|
func GetOptionInrAsk(key string) ([]byte, error) {
|
|
inrP, err := OptionInrAsk.Get(key)
|
|
if err != nil {
|
|
return []byte("0"), nil
|
|
}
|
|
|
|
return inrP, nil
|
|
}
|
|
|