package markinfo import "fmt" import "math" const ( EURUSD = iota GBPUSD USDJPY USDCHF AUDUSD USDCAD NZDUSD EURGBP EURJPY EURCHF EURAUD EURCAD GBPCHF GBPJPY CHFJPY CADJPY AUDJPY AUDCAD USDMXN AUDNZD XAGUSD XAUUSD OILUSD USDTRY GBPAUD //from lmax symbol list GBPCAD EURCZK GBPCZK USDCZK EURDKK GBPDKK USDDKK EURHKD GBPHKD USDHKD EURHUF GBPHUF USDHUF EURMXN GBPMXN EURNOK GBPNOK USDNOK EURNZD GBPNZD EURPLN GBPPLN USDPLN EURSEK GBPSEK USDSEK EURSGD GBPSGD USDSGD EURTRY GBPTRY EURZAR GBPZAR USDZAR NZDJPY AUDCHF CADCHF NZDCAD NZDCHF NZDSGD SGDJPY CurrencyCount UK100 WS30 SPX NDX GDAXI FCHI JAPEN225 STOXX50E AEX CLQ2 CLU2 CLV2 LCOQ2 LCOU2 LCOV2 GCQ2 LGON2 LGOQ2 LGOU2 FXCount SH000300 IFMI FuturesCount SymbolCount ) var symbolMap map[string]int var symbols = map[int]string{ EURUSD: "EURUSD", GBPUSD: "GBPUSD", USDJPY: "USDJPY", USDCHF: "USDCHF", AUDUSD: "AUDUSD", USDCAD: "USDCAD", NZDUSD: "NZDUSD", EURGBP: "EURGBP", EURJPY: "EURJPY", EURCHF: "EURCHF", EURAUD: "EURAUD", EURCAD: "EURCAD", GBPCHF: "GBPCHF", GBPJPY: "GBPJPY", CHFJPY: "CHFJPY", CADJPY: "CADJPY", AUDJPY: "AUDJPY", AUDCAD: "AUDCAD", USDMXN: "USDMXN", AUDNZD: "AUDNZD", XAGUSD: "XAGUSD", XAUUSD: "XAUUSD", OILUSD: "OILUSD", USDTRY: "USDTRY", GBPAUD: "GBPAUD", GBPCAD: "GBPCAD", EURCZK: "EURCZK", GBPCZK: "GBPCZK", USDCZK: "USDCZK", EURDKK: "EURDKK", GBPDKK: "GBPDKK", USDDKK: "USDDKK", EURHKD: "EURHKD", GBPHKD: "GBPHKD", USDHKD: "USDHKD", EURHUF: "EURHUF", GBPHUF: "GBPHUF", USDHUF: "USDHUF", EURMXN: "EURMXN", GBPMXN: "GBPMXN", EURNOK: "EURNOK", GBPNOK: "GBPNOK", USDNOK: "USDNOK", EURNZD: "EURNZD", GBPNZD: "GBPNZD", EURPLN: "EURPLN", GBPPLN: "GBPPLN", USDPLN: "USDPLN", EURSEK: "EURSEK", GBPSEK: "GBPSEK", USDSEK: "USDSEK", EURSGD: "EURSGD", GBPSGD: "GBPSGD", USDSGD: "USDSGD", EURTRY: "EURTRY", GBPTRY: "GBPTRY", EURZAR: "EURZAR", GBPZAR: "GBPZAR", USDZAR: "USDZAR", NZDJPY: "NZDJPY", AUDCHF: "AUDCHF", CADCHF: "CADCHF", NZDCAD: "NZDCAD", NZDCHF: "NZDCHF", NZDSGD: "NZDSGD", SGDJPY: "SGDJPY", UK100: "UK100", WS30: "WS30", SPX: "SPX", NDX: "NDX", GDAXI: "GDAXI", FCHI: "FCHI", JAPEN225: "JAPEN225", STOXX50E: "STOXX50E", AEX: "AEX", CLQ2: "CLQ2", CLU2: "CLU2", CLV2: "CLV2", LCOQ2: "LCOQ2", LCOU2: "LCOU2", LCOV2: "LCOV2", GCQ2: "GCQ2", LGON2: "LGON2", LGOQ2: "LGOQ2", LGOU2: "LGOU2", FXCount: "FXCount", SH000300: "SH000300", IFMI: "IFMI", FuturesCount: "FuturesCount", SymbolCount: "SymbolCount", } var symbolUnit map[string]float64 var symbolUnitInt = map[int]float64{ EURUSD: 0.00001, GBPUSD: 0.00001, USDJPY: 0.001, USDCHF: 0.00001, AUDUSD: 0.00001, USDCAD: 0.00001, NZDUSD: 0.00001, EURGBP: 0.00001, EURJPY: 0.001, EURCHF: 0.00001, EURAUD: 0.00001, EURCAD: 0.00001, GBPCHF: 0.00001, GBPJPY: 0.001, CHFJPY: 0.001, CADJPY: 0.001, AUDJPY: 0.001, AUDCAD: 0.00001, USDMXN: 0.00001, AUDNZD: 0.00001, XAGUSD: 0.001, XAUUSD: 0.001, OILUSD: 0.001, USDTRY: 0.00001, GBPAUD: 0.00001, GBPCAD: 0.00001, EURCZK: 0.0001, GBPCZK: 0.0001, USDCZK: 0.0001, EURDKK: 0.00001, GBPDKK: 0.00001, USDDKK: 0.00001, EURHKD: 0.00001, GBPHKD: 0.00001, USDHKD: 0.00001, EURHUF: 0.001, GBPHUF: 0.001, USDHUF: 0.001, EURMXN: 0.00001, GBPMXN: 0.00001, EURNOK: 0.00001, GBPNOK: 0.00001, USDNOK: 0.00001, EURNZD: 0.00001, GBPNZD: 0.00001, EURPLN: 0.00001, GBPPLN: 0.00001, USDPLN: 0.00001, EURSEK: 0.00001, GBPSEK: 0.00001, USDSEK: 0.00001, EURSGD: 0.00001, GBPSGD: 0.00001, USDSGD: 0.00001, EURTRY: 0.00001, GBPTRY: 0.00001, EURZAR: 0.00001, GBPZAR: 0.00001, USDZAR: 0.00001, NZDJPY: 0.001, AUDCHF: 0.00001, CADCHF: 0.00001, NZDCAD: 0.00001, NZDCHF: 0.00001, NZDSGD: 0.00001, SGDJPY: 0.001, UK100: 0.1, WS30: 0.1, SPX: 0.1, NDX: 0.1, GDAXI: 0.1, FCHI: 0.1, JAPEN225: 1.0, STOXX50E: 0.1, AEX: 0.1, CLQ2: 0.1, CLU2: 0.1, CLV2: 0.1, LCOQ2: 0.1, LCOU2: 0.1, LCOV2: 0.1, GCQ2: 0.1, LGON2: 0.1, LGOQ2: 0.1, LGOU2: 0.1, SH000300: 0.01, IFMI: 0.01, } var symbolIdBookId map[int]int var bookIdSymbolId = map[int]int{ 4008: AUDJPY, 4007: AUDUSD, 4009: CHFJPY, 4016: EURAUD, 4015: EURCAD, 4011: EURCHF, 4003: EURGBP, 4006: EURJPY, 4001: EURUSD, 4017: GBPAUD, 4014: GBPCAD, 4012: GBPCHF, 4005: GBPJPY, 4002: GBPUSD, 4013: USDCAD, 4010: USDCHF, 4004: USDJPY, 100479: EURCZK, 100481: GBPCZK, 100483: USDCZK, 100485: EURDKK, 100487: GBPDKK, 100489: USDDKK, 100491: EURHKD, 100493: GBPHKD, 100495: USDHKD, 100497: EURHUF, 100499: GBPHUF, 100501: USDHUF, 100503: EURMXN, 100505: GBPMXN, 100507: USDMXN, 100509: EURNOK, 100511: GBPNOK, 100513: USDNOK, 100515: EURNZD, 100517: GBPNZD, 100519: EURPLN, 100521: GBPPLN, 100523: USDPLN, 100525: EURSEK, 100527: GBPSEK, 100529: USDSEK, 100531: EURSGD, 100533: GBPSGD, 100535: USDSGD, 100537: EURTRY, 100539: GBPTRY, 100541: USDTRY, 100543: EURZAR, 100545: GBPZAR, 100547: USDZAR, 100613: NZDUSD, 100615: AUDNZD, 100617: NZDJPY, 100619: AUDCHF, 100667: AUDCAD, 100671: CADCHF, 100669: CADJPY, 100673: NZDCAD, 100675: NZDCHF, 100677: NZDSGD, 100678: SGDJPY, 100089: UK100, 100091: WS30, 100093: SPX, 100095: NDX, 100097: GDAXI, 100099: FCHI, 100101: STOXX50E, 100103: AEX, 100105: JAPEN225, 100637: XAUUSD, 100639: XAGUSD, 100699: CLQ2, 100705: CLU2, 100711: CLV2, 100697: LCOQ2, 100703: LCOU2, 100709: LCOV2, 100659: GCQ2, 100695: LGON2, 100701: LGOQ2, 100707: LGOU2, } func init() { //symbol map symbolMap = make(map[string]int) for k, v := range symbols { symbolMap[v] = k } //symbolIdBookId symbolIdBookId = make(map[int]int) for k, v := range bookIdSymbolId { symbolIdBookId[v] = k } //单位初始化 symbolUnit = make(map[string]float64) for k, v := range symbolUnitInt { symbolUnit[symbols[k]] = v } } const ( DIRECT_RATES = iota INDIRECT_RATES CROSS_RATES FUTURES_RATES ) func BookIdToSymbolId(bookId int) (symbolId int, err error) { if symbolId, ok := bookIdSymbolId[bookId]; ok { return symbolId, nil } return 0, fmt.Errorf("BookIdToSymbolId:: bookId %d error.", bookId) } func SymbolIdToBookId(symbolId int) (bookId int, err error) { if bookId, ok := symbolIdBookId[symbolId]; ok { return bookId, nil } return 0, fmt.Errorf("SymbolIdToBookId:: symbolId %d error.", symbolId) } func GetPoint(sid int, price1, price2 float64) (float64, error) { if sid < 0 || sid >= SymbolCount { return 0.0, fmt.Errorf("GetPoint symbolId %d not exist", sid) } correct := 1.0 if sid == XAUUSD { correct = 10.0 } offset := price1 - price2 unit := symbolUnitInt[sid] ret := offset / (10 * unit * correct) return ret, nil } func PointCorrect(symbol string) float64 { if symbol == "XAUUSD" { return 10.0 } if symbol == "XAGUSD" || symbol == "OILUSD" { return 1.0 } return 1.0 } func BaseCorrect(symbol string) float64 { if symbol == "XAUUSD" { return 1000.0 } if symbol == "XAGUSD" || symbol == "OILUSD" { return 100.0 } return 1.0 } func SymbolType(symbol string) (t int, err error) { id, ok := symbolMap[symbol] if !ok { return 0, fmt.Errorf("SymbolGetType symbol %s not exist", symbol) } r := []rune(symbol) if string(r[0:3]) == "USD" { return INDIRECT_RATES, nil } if string(r[3:]) == "USD" { return DIRECT_RATES, nil } if id > FXCount && id < FuturesCount { return FUTURES_RATES, nil } return CROSS_RATES, nil } func SymbolPartId(symbol string, part int) (int, error) { var symbolPart string if len(symbol) != 6 { return -1, fmt.Errorf("SymbolPartId error symbol name %s", symbol) } r := []rune(symbol) if part == 1 { symbolPart = string(r[0:3]) } else { symbolPart = string(r[3:]) } symbolPart1 := symbolPart + "USD" if id, ok := symbolMap[symbolPart1]; ok { return id, nil } symbolPart1 = "USD" + symbolPart if id, ok := symbolMap[symbolPart1]; ok { return id, nil } return -1, fmt.Errorf("symbolPartId error symbol name %s not a cross symbol", symbol) } func SymbolUint(symbol string) (t float64, err error) { value, ok := symbolUnit[symbol] if !ok { return 0, fmt.Errorf("SymbolGetUint symbol %s not exist", symbol) } return value, nil } func SymbolPoint(symbol string) (t int, err error) { unit, err := SymbolUint(symbol) if err != nil { return 0, err } return -int(math.Log10(unit)), nil } func SymbolId(symbol string) (t int, err error) { value, ok := symbolMap[symbol] if !ok { return 0, fmt.Errorf("SymbolID symbol %s not exist", symbol) } return value, nil } func SymbolName(id int) (t string, err error) { value, ok := symbols[id] if !ok { return "", fmt.Errorf("SymbolName symbol_id %d not exist", id) } return value, nil } func SymbolMap() (t map[string]int) { return symbolMap }