2 Star 14 Fork 16

王布衣/engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
command_print.go 4.48 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-10-08 17:19 +08:00 . 调整缓存机制的时间函数的package归属
package command
import (
"fmt"
"gitee.com/quant1x/engine/cache"
"gitee.com/quant1x/engine/datasets"
"gitee.com/quant1x/engine/flash"
"gitee.com/quant1x/gotdx/proto"
"gitee.com/quant1x/gotdx/securities"
"gitee.com/quant1x/gotdx/trading"
"gitee.com/quant1x/gox/tags"
"github.com/olekukonko/tablewriter"
cmder "github.com/spf13/cobra"
"os"
"strings"
)
var (
tradeDate = ""
f10Code = "" // F10
exchangeCode = "" // Exchange
maCode = "" // 移动平均线
boxCode = "" // 平台
)
// CmdPrint 打印命令
var CmdPrint = &cmder.Command{
Use: "print",
Example: Application + " print sh000001",
Short: "打印K线概要",
//Args: cmder.MinimumNArgs(1),
Run: func(cmd *cmder.Command, args []string) {
tradeDate = trading.FixTradeDate(tradeDate)
if len(exchangeCode) > 0 {
//printExchange(exchangeCode)
} else if len(f10Code) > 0 {
printF10(f10Code)
} else if len(maCode) > 0 {
//printMA(maCode)
} else if len(boxCode) > 0 {
//printBox(boxCode)
} else {
if len(args) != 1 {
fmt.Println(cmd.Help())
return
}
// 默认输出K线信息
securityCode := args[0]
printKline(securityCode)
}
},
}
func init() {
CmdPrint.Flags().StringVar(&f10Code, "f10", "", "查看快照扩展数据")
CmdPrint.Flags().StringVar(&exchangeCode, "exchange", "", "查看快照扩展数据")
CmdPrint.Flags().StringVar(&maCode, "ma", "", "查看均线")
CmdPrint.Flags().StringVar(&boxCode, "box", "", "查看平台数据")
CmdPrint.Flags().StringVar(&tradeDate, "date", cache.DefaultCanReadDate(), "指定日期")
}
//// 输出K线概要数据列表
//func v1PrintKline(securityCode string) {
// securityCode = proto.CorrectSecurityCode(securityCode)
// name := securities.GetStockName(securityCode)
// fmt.Printf("%s: %s\n", securityCode, name)
// df := datasets.KLine(securityCode)
// fmt.Println(df)
//}
// 输出K线概要数据列表
func printKline(securityCode string) {
securityCode = proto.CorrectSecurityCode(securityCode)
name := securities.GetStockName(securityCode)
fmt.Printf("%s: %s, %s\n", securityCode, name, tradeDate)
df := datasets.BasicKLine(securityCode)
fmt.Println(df)
}
func checkoutTable(v any) (headers []string, records [][]string) {
headers = []string{"字段", "数值"}
fields := tags.GetHeadersByTags(v)
values := tags.GetValuesByTags(v)
num := len(fields)
if num > len(values) {
num = len(values)
}
for i := 0; i < num; i++ {
records = append(records, []string{fields[i], strings.TrimSpace(values[i])})
}
return
}
func printF10(securityCode string) {
securityCode = proto.CorrectSecurityCode(securityCode)
name := securities.GetStockName(securityCode)
fmt.Printf("%s: %s, %s\n", securityCode, name, tradeDate)
value := flash.GetL5F10(securityCode, tradeDate)
headers, records := checkoutTable(value)
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader(headers)
table.SetColumnAlignment([]int{tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_LEFT})
table.AppendBulk(records)
table.Render()
}
//func printExchange(securityCode string) {
// securityCode = proto.CorrectSecurityCode(securityCode)
// name := securities.GetStockName(securityCode)
// fmt.Printf("%s: %s, %s\n", securityCode, name, tradeDate)
// value := flash.GetL5Exchange(securityCode, tradeDate)
// headers, records := checkoutTable(value)
// table := tablewriter.NewWriter(os.Stdout)
// table.SetHeader(headers)
// table.SetColumnAlignment([]int{tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_LEFT})
// table.AppendBulk(records)
// table.Render()
//}
//
//func printMA(securityCode string) {
// securityCode = proto.CorrectSecurityCode(securityCode)
// name := securities.GetStockName(securityCode)
// fmt.Printf("%s: %s, %s\n", securityCode, name, tradeDate)
// value := flash.GetL5MovingAverage(securityCode, tradeDate)
// headers, records := checkoutTable(value)
// table := tablewriter.NewWriter(os.Stdout)
// table.SetHeader(headers)
// table.SetColumnAlignment([]int{tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_LEFT})
// table.AppendBulk(records)
// table.Render()
//}
//
//func printBox(securityCode string) {
// securityCode = proto.CorrectSecurityCode(securityCode)
// name := securities.GetStockName(securityCode)
// fmt.Printf("%s: %s, %s\n", securityCode, name, tradeDate)
// value := flash.GetL5Box(securityCode, tradeDate)
// headers, records := checkoutTable(value)
// table := tablewriter.NewWriter(os.Stdout)
// table.SetHeader(headers)
// table.SetColumnAlignment([]int{tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_LEFT})
// table.AppendBulk(records)
// table.Render()
//}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quant1x/engine.git
git@gitee.com:quant1x/engine.git
quant1x
engine
engine
v0.1.8

搜索帮助