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.
502 lines
10 KiB
502 lines
10 KiB
2 months ago
|
package data
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"go.mongodb.org/mongo-driver/bson"
|
||
|
"go.mongodb.org/mongo-driver/mongo"
|
||
|
"wss-pool/dictionary"
|
||
|
"wss-pool/logging/applogger"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
StockIndexList = "stockIndexList"
|
||
|
StockUs = "stockListUs" // US Real time
|
||
|
StockUsDaily = "stockUsDaily" // Us daily data
|
||
|
StockUsWeekly = "stockUsWeekly" // Us Weekly data
|
||
|
StockUsMonthly = "stockUsMonthly" // Us Monthly data
|
||
|
StockUsHour = "stockUsHour" // Us Hourly data
|
||
|
StockUsFiveMinutes = "stockUsFiveMinutes" // Us Data every five minutes
|
||
|
StockUsOneMinute = "stockUsOneMinute" // Us Data every minutes
|
||
|
StockNews = "stockNews"
|
||
|
OptionList = "optionList" // list
|
||
|
ForexList = "forexList" // forex list
|
||
|
ForexListBak = "forexListBak" // forex list
|
||
|
ForexTradeList = "forexTradeList" // forex trade list
|
||
|
ForexKLine = "forexKLine" // forex kline
|
||
|
)
|
||
|
|
||
|
var StockList string
|
||
|
|
||
|
// Create_stockList_index New Stock List Index
|
||
|
func Create_stockList_index() {
|
||
|
c := MgoConnect(StockList)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"Code", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"Symbol", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"Exchange", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"Vol", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"Source", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"Country", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"NumericCode", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Create_stockIndixList_index() {
|
||
|
c := MgoConnect(StockIndexList)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"Code", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"Exchange", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"Sort", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"State", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"Country", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func CreateOptionList() {
|
||
|
c := MgoConnect(OptionList)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"Code", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"Percent", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"DateTime", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"Country", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func CreateOptionindex() {
|
||
|
for _, value := range dictionary.OptionCodeList {
|
||
|
tableName := GetOptionTableName(value)
|
||
|
c := MgoConnect(tableName)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"code", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
tableName = GetOptionExpiryTableName(value)
|
||
|
c = MgoConnect(tableName)
|
||
|
indexModel = []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"code", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"expiry", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"expiry_date", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err = c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 外汇索引
|
||
|
func CreateForexList() {
|
||
|
c := MgoConnect(ForexList)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"ticker", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"updated", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"day.o", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"day.l", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"day.h", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"day.c", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
func CreateForexListNew() {
|
||
|
c := MgoConnect(ForexListBak)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"code", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"name", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"category", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"symbol", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
func CreateForexTradeLis() {
|
||
|
// {"ev":"T","code":"NZDCAD","seq":"75468393","tick_time":"1732274869856","price":"0.81696","volume":"92500.00","turnover":"0.00000","trade_direction":0}
|
||
|
c := MgoConnect(ForexTradeList)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"code", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"tick_time", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
func CreateForexKLine() {
|
||
|
c := MgoConnect(ForexKLine)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"code", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"timestamp", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Create_stockUs_index 美股实时数据索引
|
||
|
func Create_stockUs_index() {
|
||
|
c := MgoConnect(StockUs)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"s", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"se", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"t", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Create_stockUs_index
|
||
|
func Create_SpotKline_index() {
|
||
|
for _, value := range dictionary.TimeCycle {
|
||
|
tableName := GetStockKLineTableName(value)
|
||
|
c := MgoConnect(tableName)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"channel", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"timestamp", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"code", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Create_ContractKline_index() {
|
||
|
for _, value := range dictionary.ContractTime {
|
||
|
tableName := GetContractKLineTableName(value)
|
||
|
c := MgoConnect(tableName)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"channel", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"timestamp", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"code", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Create_ContractPriceKline_index() {
|
||
|
for _, value := range dictionary.ContractPriceTime {
|
||
|
tableName := GetContractPriceKLineTableName(value)
|
||
|
c := MgoConnect(tableName)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"channel", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"timestamp", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"code", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Create_Stock_News() {
|
||
|
c := MgoConnect(StockNews)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"code", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"country", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Create_Stock_index() {
|
||
|
for _, value := range dictionary.StockCodeList {
|
||
|
tableName := GetStockTableName(value)
|
||
|
c := MgoConnect(tableName)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"stock_code", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"symbol", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"timestamp", -1},
|
||
|
}}, {
|
||
|
Keys: bson.D{
|
||
|
{"price", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
//DAY K WEEK
|
||
|
for _, v := range dictionary.StockSouthAsiaListTime {
|
||
|
c := MgoConnect(fmt.Sprintf("%s%s", tableName, v))
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"stock_code", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"symbol", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"timestamp", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"high_price", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"low_price", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Create_SpockIndexKline() {
|
||
|
tableName := GetStockIndexTableName()
|
||
|
c := MgoConnect(tableName)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"stock_code", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"timestamp", -1},
|
||
|
}}, {
|
||
|
Keys: bson.D{
|
||
|
{"price", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
//DAY K WEEK
|
||
|
for _, v := range dictionary.StockSouthAsiaListTime {
|
||
|
c := MgoConnect(fmt.Sprintf("%s%s", tableName, v))
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"stock_code", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"timestamp", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"high_price", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"low_price", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Create_StockUsList_index() {
|
||
|
for _, value := range dictionary.StockUsListTime {
|
||
|
tableName := GetStockUsTableName(value)
|
||
|
c := MgoConnect(tableName)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"timestamp", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"code", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Create_SpotKlineTest_index() {
|
||
|
for _, value := range dictionary.TimeCycle {
|
||
|
tableName := GetStockKLineTestTableName(value)
|
||
|
c := MgoConnect(tableName)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"channel", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"timestamp", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"code", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Create_ContractKlineTest_index() {
|
||
|
for _, value := range dictionary.ContractTime {
|
||
|
tableName := GetContractKLineTestTableName(value)
|
||
|
c := MgoConnect(tableName)
|
||
|
indexModel := []mongo.IndexModel{
|
||
|
{Keys: bson.D{
|
||
|
{"channel", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"timestamp", -1},
|
||
|
}},
|
||
|
{Keys: bson.D{
|
||
|
{"code", -1},
|
||
|
}},
|
||
|
}
|
||
|
_, err := c.Indexes().CreateMany(context.TODO(), indexModel)
|
||
|
if err != nil {
|
||
|
applogger.Error("Failed to create index:%v", err)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|