|
|
|
@ -658,7 +658,7 @@ func (svc *ExchangeService) ExchangeInstanceState(req *pb.ReqExchangeInstanceSta |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
MaxHistoryKlines = 100 |
|
|
|
MaxHistoryKlines = 200 |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// HistoryKline 获取交易产品历史k线 (before < klines... < after)
|
|
|
|
// HistoryKline 获取交易产品历史k线 (before < klines... < after)
|
|
|
|
@ -691,7 +691,7 @@ func (svc *ExchangeService) HistoryKline(ctx context.Context, req *pb.ReqHistory |
|
|
|
} |
|
|
|
} |
|
|
|
// 拉取最新的
|
|
|
|
// 拉取最新的
|
|
|
|
lastTs := int64(0) |
|
|
|
lastTs := int64(0) |
|
|
|
if afterTs == 0 { |
|
|
|
if req.After == 0 { |
|
|
|
liveK := exchangeInst.LiveKline.Get(interval) |
|
|
|
liveK := exchangeInst.LiveKline.Get(interval) |
|
|
|
lastTs = liveK.Ts |
|
|
|
lastTs = liveK.Ts |
|
|
|
if !liveK.Confirm { |
|
|
|
if !liveK.Confirm { |
|
|
|
@ -707,6 +707,21 @@ func (svc *ExchangeService) HistoryKline(ctx context.Context, req *pb.ReqHistory |
|
|
|
if beforeTs == 0 { |
|
|
|
if beforeTs == 0 { |
|
|
|
beforeTs = max(intervalAdder(afterTs, -count+1), KlineBefore0) |
|
|
|
beforeTs = max(intervalAdder(afterTs, -count+1), KlineBefore0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 开区间
|
|
|
|
|
|
|
|
if req.Open { |
|
|
|
|
|
|
|
if req.After != 0 { |
|
|
|
|
|
|
|
afterTs = max(intervalAdder(afterTs, -1), beforeTs) |
|
|
|
|
|
|
|
if req.Before == 0 { |
|
|
|
|
|
|
|
beforeTs = max(intervalAdder(beforeTs, -1), KlineBefore0) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if req.Before != 0 { |
|
|
|
|
|
|
|
beforeTs = min(intervalAdder(beforeTs, 1), afterTs) |
|
|
|
|
|
|
|
if req.After == 0 { |
|
|
|
|
|
|
|
afterTs = min(intervalAdder(beforeTs, 1), lastTs) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if beforeTs > afterTs { |
|
|
|
if beforeTs > afterTs { |
|
|
|
err = fmt.Errorf("time range invalid: before must less then after") |
|
|
|
err = fmt.Errorf("time range invalid: before must less then after") |
|
|
|
return |
|
|
|
return |
|
|
|
@ -726,6 +741,10 @@ func (svc *ExchangeService) HistoryKline(ctx context.Context, req *pb.ReqHistory |
|
|
|
if len(klines) == 0 { |
|
|
|
if len(klines) == 0 { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 检查k线是否连续进行补齐
|
|
|
|
|
|
|
|
if err = svc.paddingKlinesIfNotSeries(exchange, req.InstId, interval, klines); err != nil { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
lastK := klines[len(klines)-1] |
|
|
|
lastK := klines[len(klines)-1] |
|
|
|
// vmtsdb 数据刷盘30s延迟, 使用内存数据替代第一根k线
|
|
|
|
// vmtsdb 数据刷盘30s延迟, 使用内存数据替代第一根k线
|
|
|
|
@ -740,7 +759,7 @@ func (svc *ExchangeService) HistoryKline(ctx context.Context, req *pb.ReqHistory |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 降序排序
|
|
|
|
// 降序排序
|
|
|
|
if !req.Asc { |
|
|
|
if req.Desc { |
|
|
|
collect.Reverse(klines) |
|
|
|
collect.Reverse(klines) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -748,10 +767,10 @@ func (svc *ExchangeService) HistoryKline(ctx context.Context, req *pb.ReqHistory |
|
|
|
if req.Live && len(klines) > 0 { |
|
|
|
if req.Live && len(klines) > 0 { |
|
|
|
liveK := exchangeInst.LiveKline.Get(interval) |
|
|
|
liveK := exchangeInst.LiveKline.Get(interval) |
|
|
|
if latest := intervalAdder(lastK.Ts, 1) == liveK.Ts; latest { |
|
|
|
if latest := intervalAdder(lastK.Ts, 1) == liveK.Ts; latest { |
|
|
|
if req.Asc { |
|
|
|
if req.Desc { |
|
|
|
klines = append(klines, &liveK) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
klines = append([]*types.Kline{&liveK}, klines...) |
|
|
|
klines = append([]*types.Kline{&liveK}, klines...) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
klines = append(klines, &liveK) |
|
|
|
} |
|
|
|
} |
|
|
|
rsp.Live = true |
|
|
|
rsp.Live = true |
|
|
|
} |
|
|
|
} |
|
|
|
|