package models import ( "github.com/beego/beego/v2/client/orm" "time" ) type TradeGuangZhou struct { Code string `json:"code"` Msg string `json:"msg"` Param struct { TradeDate []string `json:"trade_date"` TradeType []string `json:"trade_type"` } `json:"param"` Data []struct { Variety string `json:"variety"` DiffI int `json:"diffI"` High int `json:"high"` Turnover float64 `json:"turnover"` ImpliedVolatility interface{} `json:"impliedVolatility"` Diff int `json:"diff"` Delta interface{} `json:"delta"` Close int `json:"close"` Diff1 int `json:"diff1"` LastClear int `json:"lastClear"` Open int `json:"open"` MatchQtySum int `json:"matchQtySum"` DelivMonth string `json:"delivMonth"` Low int `json:"low"` ClearPrice int `json:"clearPrice"` VarietyOrder string `json:"varietyOrder"` OpenInterest int `json:"openInterest"` Volumn int `json:"volumn"` } `json:"data"` Time int64 `json:"time"` } type BaseFromTradeGuangzhouClassify struct { BaseFromTradeGuangzhouClassifyId int `orm:"column(base_from_trade_guangzhou_classify_id);pk"` ClassifyName string `description:"分类名称"` ClassifyCode string `description:"分类编码"` ParentId int `description:"分类父级id"` ModifyTime time.Time `description:"修改时间"` CreateTime time.Time `description:"创建时间"` } type BaseFromTradeGuangzhouIndex struct { BaseFromTradeGuangzhouIndexId int `orm:"column(base_from_trade_guangzhou_index_id);pk"` BaseFromTradeGuangzhouClassifyId int `description:"分类id"` BaseFromTradeGuangzhouContractId int `description:"合约id"` IndexCode string `description:"指标编码"` IndexName string `description:"指标名称"` Frequency string `description:"频率"` Unit string `description:"单位"` StartDate string `description:"开始日期"` EndDate string `description:"结束日期"` CreateTime time.Time `description:"创建日期"` ModifyTime time.Time `description:"修改日期"` Value float64 `description:"数据值"` } type BaseFromTradeGuangzhouData struct { BaseFromTradeGuangzhouDataId int `orm:"column(base_from_trade_guangzhou_data_id);pk"` BaseFromTradeGuangzhouIndexId int `description:"指标id"` IndexCode string `description:"指标编码"` DataTime string `description:"数据日期"` Value float64 `description:"数据值"` QtySub float64 `description:"增减"` CreateTime time.Time `description:"创建日期"` ModifyTime time.Time `description:"修改日期"` } func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouClassifyAll(parentId int) (list []*BaseFromTradeGuangzhouClassify, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT * FROM base_from_trade_guangzhou_classify WHERE parent_id=? ` _, err = o.Raw(sql, parentId).QueryRows(&list) return list, err } func (obj *BaseFromTradeGuangzhouIndex) AddBaseFromTradeGuangzhouIndex() (lastId int64, err error) { o := orm.NewOrmUsingDB("data") lastId, err = o.Insert(obj) return } func (obj *BaseFromTradeGuangzhouIndex) AddBaseFromTradeGuangzhouClassify(classifyItem *BaseFromTradeGuangzhouClassify) (lastId int64, err error) { o := orm.NewOrmUsingDB("data") lastId, err = o.Insert(classifyItem) return } func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouIndexAll() (list []*BaseFromTradeGuangzhouIndex, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT * FROM base_from_trade_guangzhou_index ` _, err = o.Raw(sql).QueryRows(&list) return list, err } func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouDataByDate(date string) (list []*BaseFromTradeGuangzhouData, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT * FROM base_from_trade_guangzhou_data WHERE data_time=? ` _, err = o.Raw(sql, date).QueryRows(&list) return list, err } func (obj *BaseFromTradeGuangzhouIndex) AddBaseFromTradeGuangzhouData(dataList []*BaseFromTradeGuangzhouData) (err error) { o := orm.NewOrmUsingDB("data") _, err = o.InsertMulti(len(dataList), &dataList) return } // 修改 func (obj *BaseFromTradeGuangzhouIndex) UpdateGuangzhouData(updateParams, whereParam map[string]interface{}) (err error) { to := orm.NewOrmUsingDB("data") ptrStructOrTableName := "base_from_trade_guangzhou_data" qs := to.QueryTable(ptrStructOrTableName) for expr, exprV := range whereParam { qs = qs.Filter(expr, exprV) } _, err = qs.Update(updateParams) return } // 修改 func (obj *BaseFromTradeGuangzhouIndex) UpdateGuangzhouIndex(updateParams, whereParam map[string]interface{}) (err error) { to := orm.NewOrmUsingDB("data") ptrStructOrTableName := "base_from_trade_guangzhou_index" qs := to.QueryTable(ptrStructOrTableName) for expr, exprV := range whereParam { qs = qs.Filter(expr, exprV) } _, err = qs.Update(updateParams) return } // 合约 type GuangzhouContract struct { Code string `json:"code"` Msg string `json:"msg"` Param struct { Variety []string `json:"variety"` TradeDate []string `json:"trade_date"` } `json:"param"` Data []string `json:"data"` Time int64 `json:"time"` } type BaseFromTradeGuangzhouContract struct { BaseFromTradeGuangzhouContractId int `orm:"column(base_from_trade_guangzhou_contract_id);pk"` BaseFromTradeGuangzhouClassifyId int `description:"分类id"` ClassifyCode string `description:"分类编码"` Contract string `description:"合约编码"` TradeDate string `description:"合约日期"` } // 新增合约 func (obj *BaseFromTradeGuangzhouIndex) AddBaseFromTradeGuangzhouContract(item *BaseFromTradeGuangzhouContract) (err error) { o := orm.NewOrmUsingDB("data") _, err = o.Insert(item) return } // 获取所有合约 func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouContract(tradeDate string) (list []*BaseFromTradeGuangzhouContract, err error) { o := orm.NewOrmUsingDB("data") if tradeDate != "" { sql := ` SELECT * FROM base_from_trade_guangzhou_contract WHERE trade_date=? ` _, err = o.Raw(sql, tradeDate).QueryRows(&list) return } else { sql := ` SELECT * FROM base_from_trade_guangzhou_contract ` _, err = o.Raw(sql).QueryRows(&list) return } } // 广州交易所期货-日成交持仓排名 type GuangzhouDealPosiQuotes struct { Code string `json:"code"` Msg string `json:"msg"` Param struct { TradeDate []string `json:"trade_date"` TradeType []string `json:"trade_type"` Variety []string `json:"variety"` ContractId []string `json:"contract_id"` DataType []string `json:"data_type"` } `json:"param"` Data []struct { ContractId string `json:"contractId"` MemberId string `json:"memberId"` Abbr string `json:"abbr"` TodayQty int `json:"todayQty"` QtySub int `json:"qtySub"` CpFlag interface{} `json:"cpFlag"` } `json:"data"` Time int64 `json:"time"` } type GuangzhouWbillQty struct { Code string `json:"code"` Msg string `json:"msg"` Param struct { GenDate []string `json:"gen_date"` Variety []string `json:"variety"` } `json:"param"` Data []struct { VarietyOrder string `json:"varietyOrder"` GroupCodeOrder *string `json:"groupCodeOrder"` WhCodeOrder string `json:"whCodeOrder"` WhType string `json:"whType"` Variety string `json:"variety"` GenDate string `json:"genDate"` WhAbbr string `json:"whAbbr"` LastWbillQty int `json:"lastWbillQty"` RegWbillQty int `json:"regWbillQty"` LogoutWbillQty int `json:"logoutWbillQty"` WbillQty int `json:"wbillQty"` Diff int `json:"diff"` } `json:"data"` Time int64 `json:"time"` } type GuangzhouCongregateDeliveryQuotes struct { Code string `json:"code"` Msg string `json:"msg"` Param struct { ContractMonth []string `json:"contract_month"` } `json:"param"` Data []struct { VarietyId string `json:"varietyId"` VarietyName string `json:"varietyName"` ContractId string `json:"contractId"` WhName string `json:"whName"` WbillNum int `json:"wbillNum"` } `json:"data"` Time int64 `json:"time"` } type GuangzhouDataMinAndMaxDate struct { BaseFromTradeGuangzhouIndexId int `description:"指标id"` StartDate string `description:"开始日期"` EndDate string `description:"结束日期"` } // 获取所有合约 func (obj *BaseFromTradeGuangzhouIndex) GetBaseFromTradeGuangzhouDataMinAndMaxDate() (list []*GuangzhouDataMinAndMaxDate, err error) { o := orm.NewOrmUsingDB("data") sql := ` SELECT a.base_from_trade_guangzhou_index_id,MIN(a.data_time) AS start_date,MAX(a.data_time) AS end_date FROM base_from_trade_guangzhou_data AS a GROUP BY a.base_from_trade_guangzhou_index_id ` _, err = o.Raw(sql).QueryRows(&list) return }