如何通过CustomBarSeriesProvider
获取自定义数据或国信特色数据?
对于一些自定义数据或者国信特色数据,是通过CustomBarSeriesProvider
传递到客户端的,虽然该组件的适应性较广,可以按照代码、指标等来接收数据,同样造成的问题是该组件的使用性上并非那么简便。目前,通过CustomBarSeriesProvider
发布的指标和数据有:成交额(TURNOVER)、换手率(TURNOVERRATE)、大单流入流出指标(DDX),全市场平均股价指标(AVGPRICE)等。
名称 | 最小粒度 | 是否有历史 | 是否bar内叠加(累计值/截面值) |
---|---|---|---|
TURNOVER | tick | 是 | 是 |
TURNOVERRATE | tick | 否 | 否 |
DYNAMICPE | tick | 否 | 否 |
IOPV | tick | 否 | 否 |
DDX | min | 是 | 否(KDB已迭代) |
UNDOWN | min | 是 | 否 |
UNDOWNUP | min | 是 | 否 |
UNDOWNDOWN | min | 是 | 否 |
UNDOWNEVEN | min | 是 | 否 |
AVGPRICE | min | 是 | 否 |
1.使用CustomBarSeriesProvider
获取成交额(turnover
)数据
using tsdata.marketdata;
using tsdata.common;
vars:
CustomBarSeriesProvider CSP(null),
string sym("000001.SH");
method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
begin
CSP = new CustomBarSeriesProvider;
CSP.Symbol = sym;
CSP.CustomBarType = "turnover";
CSP.Interval.IntervalType = tsdata.marketdata.DataIntervalType.Minutes;
CSP.Interval.IntervalSpan = 1;
CSP.Range.Type = tsdata.marketdata.DataRangeType.Bars;
CSP.Range.Bars = 1;
CSP.Updated += CSP_Updated;
CSP.StateChanged += CSP_StateChanged;
CSP.Load = TRUE;
end;
Method void CSP_Updated(elsystem.Object sender, tsdata.marketdata.CustomBarSeriesUpdatedEventArgs args)
Begin
End;
Method void CSP_StateChanged(elsystem.Object sender, tsdata.common.StateChangedEventArgs args)
vars: int loop;
Begin
if(args.NewState = DataState.Loaded)then
Begin
print("Count:",CSP.Count);
For loop = 0 to CSP.Count-1
Begin
print(CSP.Close[0]); //单位:万元
End;
End;
End;
在指标或策略中可以使用如下方式:
var: tsdata.marketdata.CustomBarSeriesProvider CB_Turnover(NULL);
method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
begin
CB_Turnover = new tsdata.marketdata.CustomBarSeriesProvider;
CB_Turnover.Symbol = symbol;
CB_Turnover.CustomBarType = "TURNOVER";
CB_Turnover.Interval.ChartType = tsdata.marketdata.DataChartType.Bars;
CB_Turnover.Interval.IntervalType = tsdata.marketdata.DataIntervalType.Daily;
CB_Turnover.Interval.IntervalSpan = 1;
CB_Turnover.Range.Type = tsdata.marketdata.DataRangeType.Date;
CB_Turnover.UseNaturalHours = false;
CB_Turnover.Realtime = true;
CB_Turnover.TimeZone = tsdata.common.TimeZone.local;
CB_Turnover.Load = false;
CB_Turnover.Name = "CB_Turnover";
end;
once
begin
CB_Turnover.Range.FirstDate = BarDateTime[MaxBarsBack];
CB_Turnover.LoadProvider();
end;
print(date+19000000,",",time,",", CB_Turnover.Close[0] );
plot1(CB_Turnover.Close[0],"TurnOver");
//打印示例
//20180511.00,1500.00,46897.34
2.使用CustomBarSeriesProvider
获取换手率(turnoverrate
)数据
var: tsdata.marketdata.CustomBarSeriesProvider CB_Turnover(NULL);
method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
begin
CB_Turnover = new tsdata.marketdata.CustomBarSeriesProvider;
CB_Turnover.Symbol = symbol;
CB_Turnover.CustomBarType = "turnoverrate";
CB_Turnover.Interval.ChartType = tsdata.marketdata.DataChartType.Bars;
CB_Turnover.Interval.IntervalType = tsdata.marketdata.DataIntervalType.Daily;
CB_Turnover.Interval.IntervalSpan = 1;
CB_Turnover.Range.Type = tsdata.marketdata.DataRangeType.Date;
CB_Turnover.UseNaturalHours = false;
CB_Turnover.Realtime = true;
CB_Turnover.TimeZone = tsdata.common.TimeZone.local;
CB_Turnover.Load = false;
CB_Turnover.Name = "CB_Turnover";
end;
once
begin
CB_Turnover.Range.FirstDate = BarDateTime[MaxBarsBack];
CB_Turnover.LoadProvider();
end;
print(date+19000000,",",time,",", CB_Turnover.Close[0] ); //仅实时数据有效//
plot1(CB_Turnover.Close[0],"TurnOverRate");
3.使用CustomBarSeriesProvider
获取基金净值(IOPV
)数据
var: tsdata.marketdata.CustomBarSeriesProvider cb_IOPV(NULL);
method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
begin
cb_IOPV = new tsdata.marketdata.CustomBarSeriesProvider;
cb_IOPV.Symbol = symbol;
cb_IOPV.CustomBarType = "IOPV";
cb_IOPV.Interval.ChartType = tsdata.marketdata.DataChartType.Bars;
cb_IOPV.Interval.IntervalType = tsdata.marketdata.DataIntervalType.Daily;
cb_IOPV.Interval.IntervalSpan = 1;
cb_IOPV.Range.Type = tsdata.marketdata.DataRangeType.Bars;
cb_IOPV.Range.Bars = 10;
cb_IOPV.UseNaturalHours = false;
cb_IOPV.Realtime = true;
cb_IOPV.TimeZone = tsdata.common.TimeZone.local;
cb_IOPV.Load = false;
end;
once
begin
cb_IOPV.Range.FirstDate = BarDateTime[MaxBarsBack];
cb_IOPV.LoadProvider();
end;
print(date+19000000,",",time,",", cb_IOPV.Close[0] );
plot1(cb_IOPV.Close[0],"IOPV");
4.使用CustomBarSeriesProvider
获取动态市盈率(Dynamic PE
)数据
var: tsdata.marketdata.CustomBarSeriesProvider cb_PE(NULL);
method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
begin
cb_PE = new tsdata.marketdata.CustomBarSeriesProvider;
cb_PE.Symbol = symbol;
cb_PE.CustomBarType = "DynamicPE";
cb_PE.Interval.ChartType = tsdata.marketdata.DataChartType.Bars;
cb_PE.Interval.IntervalType = tsdata.marketdata.DataIntervalType.Daily;
cb_PE.Interval.IntervalSpan = 1;
cb_PE.Range.Type = tsdata.marketdata.DataRangeType.Date;
cb_PE.UseNaturalHours = false;
cb_PE.Realtime = true;
cb_PE.TimeZone = tsdata.common.TimeZone.local;
cb_PE.Load = false;
end;
once
begin
cb_PE.Range.FirstDate = BarDateTime[MaxBarsBack];
cb_PE.LoadProvider();
end;
print(date+19000000,",",time,",", cb_PE.Close[0] );
plot1(cb_PE.Close[0],"DynamicPE");
5.使用CustomBarSeriesProvider
获取大单流入流出指标(DDX
)
var: tsdata.marketdata.CustomBarSeriesProvider cb_DDX(NULL);
method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
begin
cb_DDX = new tsdata.marketdata.CustomBarSeriesProvider;
cb_DDX.Symbol = symbol;
cb_DDX.CustomBarType = "DDX";
cb_DDX.Interval.ChartType = tsdata.marketdata.DataChartType.Bars;
cb_DDX.Interval.IntervalType = tsdata.marketdata.DataIntervalType.Minutes;
cb_DDX.Interval.IntervalSpan = 1;
cb_DDX.Range.Type = tsdata.marketdata.DataRangeType.Date;
cb_DDX.UseNaturalHours = false;
cb_DDX.Realtime = true;
cb_DDX.TimeZone = tsdata.common.TimeZone.local;
cb_DDX.Load = false;
end;
once
begin
cb_DDX.Range.FirstDate = BarDateTime[MaxBarsBack];
cb_DDX.LoadProvider();
end;
print(date+19000000,",",time,",", cb_DDX.Close[0] );
plot1(cb_DDX.Close[0],"DDX");
6.使用CustomBarSeriesProvider
获取全市场平均股价(AvgPrice
)
var: tsdata.marketdata.CustomBarSeriesProvider cb_AvgPrice(NULL);
method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
begin
cb_AvgPrice = new tsdata.marketdata.CustomBarSeriesProvider;
cb_AvgPrice.Symbol = symbol;
cb_AvgPrice.CustomBarType = "AvgPrice";
cb_AvgPrice.Interval.ChartType = tsdata.marketdata.DataChartType.Bars;
cb_AvgPrice.Interval.IntervalType = tsdata.marketdata.DataIntervalType.Minutes;
cb_AvgPrice.Interval.IntervalSpan = 1;
cb_AvgPrice.Range.Type = tsdata.marketdata.DataRangeType.Date;
cb_AvgPrice.UseNaturalHours = false;
cb_AvgPrice.Realtime = true;
cb_AvgPrice.TimeZone = tsdata.common.TimeZone.local;
cb_AvgPrice.Load = false;
end;
once
begin
cb_AvgPrice.Range.FirstDate = BarDateTime[MaxBarsBack];
cb_AvgPrice.LoadProvider();
end;
print(date+19000000,",",time,",", cb_AvgPrice.Close[0] );
plot1(cb_AvgPrice.Close[0],"Average Price");