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.
60 lines
1.9 KiB
60 lines
1.9 KiB
2 months ago
|
package selfMarketSpot
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"github.com/shopspring/decimal"
|
||
|
"go.mongodb.org/mongo-driver/bson"
|
||
|
"wss-pool/internal/data"
|
||
|
)
|
||
|
|
||
|
func GetNewPrice(contractCode string) []data.MongoTick {
|
||
|
filter := bson.M{"channel": fmt.Sprintf("market.%s.kline.1min", contractCode)}
|
||
|
tableName := data.GetStockKLineTableName("1min")
|
||
|
pagedData, _ := data.MgoLimitFind(tableName, filter, int64(1))
|
||
|
return pagedData
|
||
|
}
|
||
|
|
||
|
func GetNewPriceAll(contractCode, period string) []data.MongoTick {
|
||
|
filter := bson.M{"channel": fmt.Sprintf("market.%s.kline.%s", contractCode, period)}
|
||
|
tableName := data.GetStockKLineTableName(period)
|
||
|
pagedData, _ := data.MgoLimitFind(tableName, filter, int64(1))
|
||
|
return pagedData
|
||
|
}
|
||
|
|
||
|
func GetTimeNewPrice(contractCode string, from, to int64, period string) (decimal.Decimal, decimal.Decimal, decimal.Decimal, decimal.Decimal, decimal.Decimal) {
|
||
|
filter := bson.M{"channel": fmt.Sprintf("market.%s.kline.%s", contractCode, period), "code": bson.M{"$gte": from, "$lte": to}}
|
||
|
tableName := data.GetStockKLineTableName(period)
|
||
|
pagedData, _ := data.MgoLimitFind(tableName, filter, int64(0))
|
||
|
var low, high, vol, amount, count decimal.Decimal
|
||
|
for key, v := range pagedData {
|
||
|
lows, _ := decimal.NewFromString(v.Low)
|
||
|
highs, _ := decimal.NewFromString(v.High)
|
||
|
vols, _ := decimal.NewFromString(v.Vol)
|
||
|
amounts, _ := decimal.NewFromString(v.Amount)
|
||
|
var counts decimal.Decimal
|
||
|
if countItem, ok := v.Count.(string); ok {
|
||
|
counts, _ = decimal.NewFromString(countItem)
|
||
|
} else if countItem, ok := v.Count.(int64); ok {
|
||
|
counts = decimal.NewFromInt(countItem)
|
||
|
}
|
||
|
if key == 0 {
|
||
|
low = lows
|
||
|
high = highs
|
||
|
vol = vols
|
||
|
amount = amounts
|
||
|
count = counts
|
||
|
continue
|
||
|
}
|
||
|
vol = vol.Add(vols)
|
||
|
amount = vol.Add(amounts)
|
||
|
count = vol.Add(counts)
|
||
|
if low.GreaterThan(lows) {
|
||
|
low = lows
|
||
|
}
|
||
|
if high.LessThan(highs) {
|
||
|
high = highs
|
||
|
}
|
||
|
}
|
||
|
return low, high, vol, amount, count
|
||
|
}
|