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.
89 lines
2.3 KiB
89 lines
2.3 KiB
2 months ago
|
package model
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
"wss-pool/dictionary"
|
||
|
"wss-pool/logging/applogger"
|
||
|
)
|
||
|
|
||
|
func ToJson(v interface{}) (string, error) {
|
||
|
result, err := json.Marshal(v)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
return string(result), nil
|
||
|
}
|
||
|
|
||
|
func InterceptStr(symbol string) string {
|
||
|
var name string
|
||
|
ch := strings.Split(symbol, ".")
|
||
|
if len(ch) >= 2 {
|
||
|
name = strings.Replace(ch[1], dictionary.TypeUnit, "", 1)
|
||
|
}
|
||
|
return name
|
||
|
}
|
||
|
|
||
|
func InterceptCtStr(symbol string) string {
|
||
|
var name string
|
||
|
symbol = strings.Replace(symbol, "-", "", 1)
|
||
|
ch := strings.Split(symbol, ".")
|
||
|
if len(ch) >= 2 {
|
||
|
name = strings.Replace(ch[1], dictionary.TypeUnit, "", 1)
|
||
|
}
|
||
|
return strings.ToLower(name)
|
||
|
}
|
||
|
|
||
|
// SymbolListString []string
|
||
|
func SymbolListString(key []string) map[string][]string {
|
||
|
var symbolList = make(map[string][]string)
|
||
|
for _, value := range dictionary.Symbol {
|
||
|
symbolName := fmt.Sprintf("%v%v", value, dictionary.TypeUnit)
|
||
|
symbolList[symbolName] = key
|
||
|
}
|
||
|
applogger.Info("symbol data-key:%v", symbolList)
|
||
|
return symbolList
|
||
|
}
|
||
|
|
||
|
// SymbolCtListString []string
|
||
|
func SymbolCtListString(key []string) map[string][]string {
|
||
|
var symbolList = make(map[string][]string)
|
||
|
for _, value := range dictionary.ContractCodeList {
|
||
|
// TODO: 合约放开所有标识
|
||
|
//for _, vue := range dictionarykey.ContractCode {
|
||
|
//symbolName := fmt.Sprintf("%v%v", strings.ToUpper(value), vue)
|
||
|
//symbolList[symbolName] = key
|
||
|
//}
|
||
|
// TODO: 目前只支持永续合约
|
||
|
symbolName := fmt.Sprintf("%v", value)
|
||
|
symbolList[symbolName] = key
|
||
|
}
|
||
|
applogger.Info("symbol data-key:%v", symbolList)
|
||
|
return symbolList
|
||
|
}
|
||
|
|
||
|
// SymbolCtListInt []int
|
||
|
func SymbolCtListInt(key []int) map[string][]int {
|
||
|
var symbolList = make(map[string][]int)
|
||
|
for _, value := range dictionary.Symbol {
|
||
|
for _, vue := range dictionary.ContractCode {
|
||
|
symbolName := fmt.Sprintf("%v%v", strings.ToUpper(value), vue)
|
||
|
symbolList[symbolName] = key
|
||
|
}
|
||
|
}
|
||
|
applogger.Info("symbol data-key:%v", symbolList)
|
||
|
return symbolList
|
||
|
}
|
||
|
|
||
|
// SymbolListInt []int
|
||
|
func SymbolListInt(key []int) map[string][]int {
|
||
|
var symbolList = make(map[string][]int)
|
||
|
for _, value := range dictionary.Symbol {
|
||
|
symbolName := fmt.Sprintf("%v%v", value, dictionary.TypeUnit)
|
||
|
symbolList[symbolName] = key
|
||
|
}
|
||
|
applogger.Info("symbol data-key:%v", symbolList)
|
||
|
return symbolList
|
||
|
}
|