Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions client_unified.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -1064,15 +1064,15 @@ 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)
}
}
}

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)
}
}
}
Expand All @@ -1082,15 +1082,15 @@ 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))
}
}

func applyTurnoverToVolumeProfile(reply *proto.GetVolumeProfileReply, floatShares float64) {
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 {
Expand Down
22 changes: 11 additions & 11 deletions client_unified_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down