|
|
@@ -5,10 +5,13 @@ import (
|
|
|
"fmt"
|
|
|
"math"
|
|
|
"mtp2_if/db"
|
|
|
+ "mtp2_if/pb"
|
|
|
"mtp2_if/utils"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
+
|
|
|
+ "google.golang.org/protobuf/proto"
|
|
|
)
|
|
|
|
|
|
// Hsbygoodsex 商品扩展表
|
|
|
@@ -615,6 +618,7 @@ type HsbyMyGoods struct {
|
|
|
Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
|
|
|
Goodsstatus int64 `json:"goodsstatus" xorm:"'GOODSSTATUS'"` // 商品状态- 1:待审核 2:未上市 3:上市 4:已注销 5:审核拒绝 6:退市 7:待退市
|
|
|
Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 所属市场ID
|
|
|
+ Quoteminunit int64 `json:"quoteminunit" xorm:"'QUOTEMINUNIT'"` // 行情最小变动单位 [整数,报价小数位一起使用]
|
|
|
|
|
|
Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
|
|
|
Goodsprice float64 `json:"goodsprice" xorm:"'GOODSPRICE'"` // 商品价格
|
|
|
@@ -624,6 +628,13 @@ type HsbyMyGoods struct {
|
|
|
Trademode int32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
|
|
|
|
|
|
Buyaverageprice float64 `json:"buyaverageprice" xorm:"-"` // 持仓均价
|
|
|
+
|
|
|
+ Last float64 `json:"last" xorm:"-"` // 现价(仅使用于挂牌点选)
|
|
|
+ Limitup float64 `json:"limitup" xorm:"-"` // 涨停价(仅使用于挂牌点选)
|
|
|
+ Limitdown float64 `json:"limitdown" xorm:"-"` // 跌停价(仅使用于挂牌点选)
|
|
|
+ StepValue float64 `json:"stepvalue" xorm:"-"` // 价格最小变动单位
|
|
|
+ LotSize int `json:"lotsize" xorm:"-"` // 手数最小变动单位
|
|
|
+ Buymaxqty int `json:"buymaxqty" xorm:"'-'"` // 购买上限 [71] - 0为不限
|
|
|
}
|
|
|
|
|
|
// GetHsbyMyGoods 获取“我的商品”信息
|
|
|
@@ -637,7 +648,7 @@ func GetHsbyMyGoods(accountIDs string) ([]HsbyMyGoods, error) {
|
|
|
// 此定制版本,只查询出当前手数(期末)大于0的数据 (TRADEPOSITION.BUYCURPOSITIONQTY > 0)
|
|
|
if err := engine.Table("TRADEPOSITION TP").
|
|
|
Select(`TP.*, (TP.BUYCURPOSITIONQTY - TP.BUYFROZENQTY - TP.BUYOTHERFROZENQTY) ENABLEQTY,
|
|
|
- G.GOODSCODE, G.GOODSNAME, G.DECIMALPLACE, G.AGREEUNIT, G.GOODSSTATUS, G.MARKETID,
|
|
|
+ G.GOODSCODE, G.GOODSNAME, G.DECIMALPLACE, G.AGREEUNIT, G.GOODSSTATUS, G.MARKETID, G.QUOTEMINUNIT,
|
|
|
GX.PICURLS, GX.GOODSPRICE,
|
|
|
E.PARAM2 CURRENCYSIGN,
|
|
|
M.TRADEMODE`).
|
|
|
@@ -655,6 +666,61 @@ func GetHsbyMyGoods(accountIDs string) ([]HsbyMyGoods, error) {
|
|
|
// 持仓均价
|
|
|
averagePrice := myGoods.Buycurholderamount / float64(myGoods.Buycurpositionqty) / myGoods.Agreeunit
|
|
|
myGoods.Buyaverageprice, _ = strconv.ParseFloat(utils.FormatFloat(averagePrice, int(myGoods.Decimalplace)), 64)
|
|
|
+
|
|
|
+ // 获取商品现价和涨跌停价(挂牌点选)
|
|
|
+ if myGoods.Trademode == 16 {
|
|
|
+ quoteDays, err := GetQuoteDays(myGoods.Goodscode)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ if len(quoteDays) > 0 {
|
|
|
+ if quoteDays[0].Last != 0 {
|
|
|
+ myGoods.Last = utils.IntToFloat64(int(quoteDays[0].Last), int(myGoods.Decimalplace))
|
|
|
+ }
|
|
|
+ // 没有现价则尝试用昨结
|
|
|
+ if myGoods.Last == 0 && quoteDays[0].Presettle != 0 {
|
|
|
+ myGoods.Last = utils.IntToFloat64(int(quoteDays[0].Presettle), int(myGoods.Decimalplace))
|
|
|
+ }
|
|
|
+ if quoteDays[0].Limitup != 0 {
|
|
|
+ myGoods.Limitup = utils.IntToFloat64(int(quoteDays[0].Limitup), int(myGoods.Decimalplace))
|
|
|
+ }
|
|
|
+ if quoteDays[0].Limitdown != 0 {
|
|
|
+ myGoods.Limitdown = utils.IntToFloat64(int(quoteDays[0].Limitdown), int(myGoods.Decimalplace))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算价格最小变动单位
|
|
|
+ stepValue := float64(myGoods.Quoteminunit) * math.Pow(0.1, float64(myGoods.Decimalplace))
|
|
|
+ myGoods.StepValue, _ = strconv.ParseFloat(utils.FormatFloat(stepValue, int(myGoods.Decimalplace)), 64)
|
|
|
+
|
|
|
+ // 获取交易规则
|
|
|
+ accountID, err := strconv.Atoi(accountIDs)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ rule, err := GetTodayAccountTradeRule(accountID, int(myGoods.Goodsid))
|
|
|
+ if err != nil {
|
|
|
+ // 查询失败
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ if rule != nil {
|
|
|
+ tradeRuleInfoStruct := &pb.TradeRuleInfoStruct{}
|
|
|
+ if err := proto.Unmarshal([]byte(rule.Infocontent), tradeRuleInfoStruct); err != nil {
|
|
|
+ // 查询失败
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ // INSERT INTO TRADERULEDESCRIPTION (RULEID, RULENAME, REGEXPRESS, DEFAULTVALUE, REMARK) VALUES (103, '单笔最小交易量', '^[1-9]\d*$', 1, '请输入正整数!');
|
|
|
+ for _, v := range tradeRuleInfoStruct.TradeRules {
|
|
|
+ if int(*v.RuleID) == 103 {
|
|
|
+ myGoods.LotSize = int(*v.ParamValue)
|
|
|
+ }
|
|
|
+ // 挂牌点选的最大建仓手数与预售的不一样,直接从规则里取
|
|
|
+ if int(*v.RuleID) == 104 {
|
|
|
+ myGoods.Buymaxqty = int(*v.ParamValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return hsbyMyGoodses, nil
|