diff --git a/client_unified.go b/client_unified.go index 83d5440..0ebcb2a 100644 --- a/client_unified.go +++ b/client_unified.go @@ -157,7 +157,7 @@ func (client *Client) StockKLine930(category uint16, market uint8, code string, // 当前数据是不是当前交易日 data := proto.SecurityBar{} if cast.ToUint32(v.DateTime.Format("20060102")) == info.Date { - if trans, err := client.StockFullTransaction(market, code); err == nil { + if trans, err := client.StockTransaction(market, code, 0, 1); err == nil { data.Open = trans[0].Price data.High = trans[0].Price data.Low = trans[0].Price @@ -172,7 +172,7 @@ func (client *Client) StockKLine930(category uint16, market uint8, code string, list = append(list, data) } } else { - if trans, err := client.StockHistoryFullTransaction(cast.ToUint32(v.DateTime.Format("20060102")), market, code); err == nil { + if trans, err := client.StockHistoryTransaction(cast.ToUint32(v.DateTime.Format("20060102")), market, code, 0, 1); err == nil { // if len(trans) > 0 && trans[0].Time.Format(time.TimeOnly) < "09:30:00" { data.Open = trans[0].Price data.High = trans[0].Price @@ -1064,7 +1064,7 @@ func (client *Client) loadFloatSharesMap(qc *Client, keys []stockKey) map[stockK func applyTurnoverToSecurityQuotes(items []proto.SecurityQuote, shares map[stockKey]float64) { for i := range items { if floatShares := shares[stockKey{Market: items[i].Market, Code: items[i].Code}]; floatShares > 0 { - items[i].Turnover = round2(float64(items[i].Vol) * 10000 / floatShares) + items[i].Turnover = round2(float64(items[i].Vol) / floatShares) } } } @@ -1072,7 +1072,7 @@ func applyTurnoverToSecurityQuotes(items []proto.SecurityQuote, shares map[stock func applyTurnoverToQuoteList(items []proto.QuoteListItem, shares map[stockKey]float64) { for i := range items { if floatShares := shares[stockKey{Market: items[i].Market, Code: items[i].Code}]; floatShares > 0 { - items[i].Turnover = round2(float64(items[i].Vol) * 10000 / floatShares) + items[i].Turnover = round2(float64(items[i].Vol) / floatShares) } } } @@ -1082,7 +1082,7 @@ func applyTurnoverToBars(items []proto.SecurityBar, floatShares float64) { return } for i := range items { - items[i].Turnover = round2(items[i].Vol * 100 / floatShares) + items[i].Turnover = round2(items[i].Vol * 100 / (floatShares * 10000)) } } @@ -1090,7 +1090,7 @@ func applyTurnoverToVolumeProfile(reply *proto.GetVolumeProfileReply, floatShare if reply == nil || floatShares <= 0 { return } - reply.Turnover = round2(float64(reply.Vol) * 10000 / floatShares) + reply.Turnover = round2(float64(reply.Vol) / floatShares) } func round2(v float64) float64 { diff --git a/client_unified_test.go b/client_unified_test.go index ad9ba11..bb96ad9 100644 --- a/client_unified_test.go +++ b/client_unified_test.go @@ -77,42 +77,42 @@ func TestNewMACExUsesMacExAddressAsPrimary(t *testing.T) { func TestApplyTurnoverHelpers(t *testing.T) { shares := map[stockKey]float64{ - {Market: types.MarketSZ.Uint8(), Code: "000001"}: 1000000, + {Market: types.MarketSZ.Uint8(), Code: "000001"}: 100000, } quotes := []proto.SecurityQuote{{ Market: types.MarketSZ.Uint8(), Code: "000001", - Vol: 12345, + Vol: 100000, }} applyTurnoverToSecurityQuotes(quotes, shares) - if quotes[0].Turnover != 123.45 { + if quotes[0].Turnover != 1.0 { t.Fatalf("unexpected security quote turnover: %.2f", quotes[0].Turnover) } quoteList := []proto.QuoteListItem{{ Market: types.MarketSZ.Uint8(), Code: "000001", - Vol: 23456, + Vol: 150000, }} applyTurnoverToQuoteList(quoteList, shares) - if quoteList[0].Turnover != 234.56 { + if quoteList[0].Turnover != 1.5 { t.Fatalf("unexpected quote list turnover: %.2f", quoteList[0].Turnover) } - bars := []proto.SecurityBar{{Vol: 12345}} - applyTurnoverToBars(bars, 1000000) - if bars[0].Turnover != 1.23 { + bars := []proto.SecurityBar{{Vol: 2000000}} + applyTurnoverToBars(bars, 2000) + if bars[0].Turnover != 10.0 { t.Fatalf("unexpected bar turnover: %.2f", bars[0].Turnover) } reply := &proto.GetVolumeProfileReply{ Market: types.MarketSZ.Uint8(), Code: "000001", - Vol: 34567, + Vol: 200000, } - applyTurnoverToVolumeProfile(reply, 1000000) - if reply.Turnover != 345.67 { + applyTurnoverToVolumeProfile(reply, 100000) + if reply.Turnover != 2.0 { t.Fatalf("unexpected volume profile turnover: %.2f", reply.Turnover) } }