21
21
22
22
namespace dxf_client
23
23
{
24
- public class SnapshotPrinter :
25
- IDxOrderSnapshotListener ,
26
- IDxCandleSnapshotListener ,
27
- IDxTimeAndSaleSnapshotListener ,
28
- IDxSpreadOrderSnapshotListener ,
29
- IDxGreeksSnapshotListener ,
30
- IDxSeriesSnapshotListener
31
- {
32
- private readonly int recordsPrintLimit ;
33
-
34
- public SnapshotPrinter ( int recordsPrintLimit )
35
- {
36
- this . recordsPrintLimit = recordsPrintLimit ;
37
- }
38
-
39
- #region Implementation of IDxCandleSnapshotListener
40
-
41
- /// <summary>
42
- /// On Candle snapshot event received.
43
- /// </summary>
44
- /// <typeparam name="TB">Event buffer type.</typeparam>
45
- /// <typeparam name="TE">Event type.</typeparam>
46
- /// <param name="buf">Event buffer object.</param>
47
- public void OnCandleSnapshot < TB , TE > ( TB buf )
48
- where TB : IDxEventBuf < TE >
49
- where TE : IDxCandle
50
- {
51
- PrintSnapshot ( buf ) ;
52
- }
53
-
54
- #endregion //IDxCandleSnapshotListener
55
-
56
- #region Implementation of IDxGreeksSnapshotListener
57
-
58
- public void OnGreeksSnapshot < TB , TE > ( TB buf )
59
- where TB : IDxEventBuf < TE >
60
- where TE : IDxGreeks
61
- {
62
- PrintSnapshot ( buf ) ;
63
- }
64
-
65
- #endregion
66
-
67
- #region Implementation of IDxOrderSnapshotListener
68
-
69
- /// <summary>
70
- /// On Order snapshot event received.
71
- /// </summary>
72
- /// <typeparam name="TB">Event buffer type.</typeparam>
73
- /// <typeparam name="TE">Event type.</typeparam>
74
- /// <param name="buf">Event buffer object.</param>
75
- public void OnOrderSnapshot < TB , TE > ( TB buf )
76
- where TB : IDxEventBuf < TE >
77
- where TE : IDxOrder
78
- {
79
- PrintSnapshot ( buf ) ;
80
- }
81
-
82
- #endregion //IDxOrderSnapshotListener
83
-
84
- #region Implementation of IDxSeriesSnapshotListener
85
-
86
- public void OnSeriesSnapshot < TB , TE > ( TB buf )
87
- where TB : IDxEventBuf < TE >
88
- where TE : IDxSeries
89
- {
90
- PrintSnapshot ( buf ) ;
91
- }
92
-
93
- #endregion
94
-
95
- #region Implementation of IDxSpreadOrderSnapshotListener
96
-
97
- /// <summary>
98
- /// On SpreadOrder snapshot event received.
99
- /// </summary>
100
- /// <typeparam name="TB">Event buffer type.</typeparam>
101
- /// <typeparam name="TE">Event type.</typeparam>
102
- /// <param name="buf">Event buffer object.</param>
103
- public void OnSpreadOrderSnapshot < TB , TE > ( TB buf )
104
- where TB : IDxEventBuf < TE >
105
- where TE : IDxSpreadOrder
106
- {
107
- PrintSnapshot ( buf ) ;
108
- }
109
-
110
- #endregion
111
-
112
- #region Implementation of IDxTimeAndSaleSnapshotListener
113
-
114
- /// <summary>
115
- /// On TimeAndSale snapshot event received.
116
- /// </summary>
117
- /// <typeparam name="TB">Event buffer type.</typeparam>
118
- /// <typeparam name="TE">Event type.</typeparam>
119
- /// <param name="buf">Event buffer object.</param>
120
- public void OnTimeAndSaleSnapshot < TB , TE > ( TB buf )
121
- where TB : IDxEventBuf < TE >
122
- where TE : IDxTimeAndSale
123
- {
124
- PrintSnapshot ( buf ) ;
125
- }
126
-
127
- #endregion //IDxTimeAndSaleSnapshotListener
128
-
129
- private void PrintSnapshot < TE > ( IDxEventBuf < TE > buf )
130
- {
131
- Console . WriteLine ( string . Format ( CultureInfo . InvariantCulture ,
132
- "Snapshot {0} {{Symbol: '{1}', RecordsCount: {2}}}" ,
133
- buf . EventType , buf . Symbol , buf . Size ) ) ;
134
-
135
- var count = 0 ;
136
- foreach ( var o in buf )
137
- {
138
- Console . WriteLine ( $ " {{ { o } }}") ;
139
-
140
- if ( ++ count < recordsPrintLimit || recordsPrintLimit == 0 ) continue ;
141
-
142
- Console . WriteLine ( $ " {{ ... { buf . Size - count } records left ...}}") ;
143
-
144
- break ;
145
- }
146
- }
147
- }
148
-
149
24
internal class InputParam < T >
150
25
{
151
26
private T value ;
@@ -248,10 +123,10 @@ private static bool TryParseTaggedStringParam(string tag, string paramTagString,
248
123
249
124
private static void Main ( string [ ] args )
250
125
{
251
- if ( args . Length < 3 || args . Length > 13 )
126
+ if ( args . Length < 3 || ( args . Length > 0 && args [ 0 ] . Equals ( "-h" ) ) )
252
127
{
253
128
Console . WriteLine (
254
- "Usage: dxf_client <host:port>|<path> <event> <symbol> [<date>] [<source>] [snapshot] [-l <records_print_limit>] [-T <token>] [-s <subscr_data>] [-p] [-b]\n " +
129
+ "Usage: dxf_client <host:port>|<path> <event> <symbol> [<date>] [<source>] [snapshot] [-l <records_print_limit>] [-T <token>] [-s <subscr_data>] [-p] [-b] [-q] \n " +
255
130
"where\n " +
256
131
" host:port - The address of dxfeed server (demo.dxfeed.com:7300)\n " +
257
132
" path - The path to file with candle data (non zipped Candle Web Service output) or `tape` file\n " +
@@ -279,7 +154,8 @@ private static void Main(string[] args)
279
154
" -T <token> - The authorization token\n \n " +
280
155
" -s <subscr_data> - The subscription data: ticker|TICKER, stream|STREAM, history|HISTORY\n " +
281
156
" -p - Enables the data transfer logging\n " +
282
- " -b - Enables the server's heartbeat logging to console\n \n " +
157
+ " -b - Enables the server's heartbeat logging to console\n " +
158
+ " -q - Quiet mode (do not print events and snapshots)\n \n " +
283
159
"examples:\n " +
284
160
" events: dxf_client demo.dxfeed.com:7300 Quote,Trade MSFT.TEST,IBM.TEST\n " +
285
161
" events: dxf_client demo.dxfeed.com:7300 Quote,Trade MSFT.TEST,IBM.TEST -s stream\n " +
@@ -318,6 +194,7 @@ private static void Main(string[] args)
318
194
var subscriptionData = new InputParam < EventSubscriptionFlag > ( EventSubscriptionFlag . Default ) ;
319
195
var logDataTransferFlag = false ;
320
196
var logServerHeartbeatsFlag = false ;
197
+ var quiteMode = false ;
321
198
322
199
for ( var i = SymbolIndex + 1 ; i < args . Length ; i ++ )
323
200
{
@@ -363,6 +240,13 @@ private static void Main(string[] args)
363
240
continue ;
364
241
}
365
242
243
+ if ( quiteMode == false && args [ i ] . Equals ( "-q" ) )
244
+ {
245
+ quiteMode = true ;
246
+
247
+ continue ;
248
+ }
249
+
366
250
if ( ! sources . IsSet )
367
251
TryParseSourcesParam ( args [ i ] , sources ) ;
368
252
}
@@ -377,37 +261,45 @@ private static void Main(string[] args)
377
261
NativeTools . LoadConfigFromString ( "logger.level = \" debug\" \n " ) ;
378
262
NativeTools . InitializeLogging ( "dxf_client.log" , true , true , logDataTransferFlag ) ;
379
263
380
- var listener = new EventPrinter ( ) ;
264
+ var eventPrinter = quiteMode ? ( IEventPrinter ) new DummyEventPrinter ( ) : new EventPrinter ( ) ;
265
+
381
266
using ( var con = token . IsSet
382
- ? new NativeConnection ( address , token . Value , DisconnectHandler , ConnectionStatusChangeHandler )
383
- : new NativeConnection ( address , DisconnectHandler , ConnectionStatusChangeHandler ) )
267
+ ? new NativeConnection ( address , token . Value , DisconnectHandler , ConnectionStatusChangeHandler )
268
+ : new NativeConnection ( address , DisconnectHandler , ConnectionStatusChangeHandler ) )
384
269
{
385
270
if ( logServerHeartbeatsFlag )
271
+ {
386
272
con . SetOnServerHeartbeatHandler ( ( connection , time , lagMark , rtt ) =>
387
273
{
388
274
Console . Error . WriteLine (
389
275
$ "##### Server time (UTC) = { time } , Server lag = { lagMark } us, RTT = { rtt } us #####") ;
390
276
} ) ;
277
+ }
391
278
392
279
IDxSubscription s = null ;
393
280
try
394
281
{
395
282
if ( dateTime . IsSet && ( events & ( EventType . Order | EventType . SpreadOrder ) ) != 0 )
396
283
{
397
- Console . Error . WriteLine ( "Date and event type Order or SpreadOrder cannot be used for subscription" ) ;
284
+ Console . Error . WriteLine (
285
+ "Date and event type Order or SpreadOrder cannot be used for subscription" ) ;
398
286
}
399
-
287
+
400
288
if ( isSnapshot . Value )
289
+ {
401
290
s = con . CreateSnapshotSubscription ( events , dateTime . Value ,
402
- new SnapshotPrinter ( recordsPrintLimit . Value ) ) ;
291
+ quiteMode
292
+ ? ( ISnapshotPrinter ) new DummySnapshotPrinter ( )
293
+ : new SnapshotPrinter ( recordsPrintLimit . Value ) ) ;
294
+ }
403
295
else if ( dateTime . IsSet )
404
296
s = subscriptionData . IsSet
405
- ? con . CreateSubscription ( events , dateTime . Value , subscriptionData . Value , listener )
406
- : con . CreateSubscription ( events , dateTime . Value , listener ) ;
297
+ ? con . CreateSubscription ( events , dateTime . Value , subscriptionData . Value , eventPrinter )
298
+ : con . CreateSubscription ( events , dateTime . Value , eventPrinter ) ;
407
299
else
408
300
s = subscriptionData . IsSet
409
- ? con . CreateSubscription ( events , subscriptionData . Value , listener )
410
- : con . CreateSubscription ( events , listener ) ;
301
+ ? con . CreateSubscription ( events , subscriptionData . Value , eventPrinter )
302
+ : con . CreateSubscription ( events , eventPrinter ) ;
411
303
412
304
if ( events . HasFlag ( EventType . Order ) && sources . Value . Length > 0 )
413
305
s . SetSource ( sources . Value ) ;
0 commit comments