-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwsRtdServerMktDataRequest.cs
678 lines (614 loc) · 30.6 KB
/
TwsRtdServerMktDataRequest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
/* Copyright (C) 2018 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
* and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using IBApi;
using System.Text;
using System.Globalization;
namespace TwsRtdServer
{
public class TwsRtdServerMktDataRequest
{
private IDictionary<string, TwsRtdServerTopic> m_topics = new ConcurrentDictionary<string, TwsRtdServerTopic>(); // map of topics
private string m_mktDataRequestStr;
private int m_twsReqId; // TWS API reqMktData current reqId
private TwsRtdServerMktDataTicks m_mktDataTicks = new TwsRtdServerMktDataTicks(); // latest ticks (we should save ticks in case of non-streaming market data)
private TwsRtdServerConnection m_twsRtdServerConnection;
private Tuple<int, string> m_error;
// constructor
public TwsRtdServerMktDataRequest(string mktDataRequestStr, int twsReqId, TwsRtdServerConnection twsRtdServerConnection){
try
{
SetError(TwsRtdServerErrors.NO_ERROR);
m_twsRtdServerConnection = twsRtdServerConnection;
m_mktDataRequestStr = mktDataRequestStr;
m_twsReqId = twsReqId;
// create empty contract
Contract contract = new Contract();
// parse string into contract
contract = ExtractContract(m_mktDataRequestStr);
if (GetErrorCode() != TwsRtdServerErrors.NO_ERROR)
{
return;
}
// extract mkt data options
List<TagValue> mktDataOptions = ExtractOptions(m_mktDataRequestStr);
if (GetErrorCode() != TwsRtdServerErrors.NO_ERROR)
{
return;
}
// extract generic ticks
string genericTicks = ExtractGenericTicks(m_mktDataRequestStr, contract.SecType);
if (GetErrorCode() != TwsRtdServerErrors.NO_ERROR)
{
return;
}
// request market data
EClientSocket socket = twsRtdServerConnection.Socket();
if (socket == null)
{
SetError(TwsRtdServerErrors.SOCKET_IS_NULL);
return;
}
socket.reqMktData(m_twsReqId, contract, genericTicks, false, false, mktDataOptions);
}
catch
{
SetError(TwsRtdServerErrors.REQUEST_MKT_DATA_ERROR);
}
}
public int GetErrorCode()
{
return m_error.Item1;
}
public string GetErrorText()
{
return m_error.Item2;
}
public void SetError(int code)
{
m_error = new Tuple<int, string>(code, TwsRtdServerErrors.GetErrorText(code));
}
public void SetError(int code, string text)
{
m_error = new Tuple<int, string>(code, text);
}
public void TwsRtdServerMktDataRequestCancel(int reqId, TwsRtdServerConnection connection)
{
// cancel market data
connection.Socket().cancelMktData(reqId);
}
public List<int> SetAllTopicsValues(string value)
{
// set all topic values to value (e.g. in case of error) and return list of updated topic ids
List<int> m_updatedTopicIds = new List<int>();
foreach (TwsRtdServerTopic topic in m_topics.Values)
{
topic.TopicValue(value);
m_updatedTopicIds.Add(topic.TopicId());
}
return m_updatedTopicIds;
}
public List<int> SetAllLiveTopicsValues(string value)
{
// set all live topic values to value (e.g. in case of error) and return list of updated topic ids
List<int> m_updatedTopicIds = new List<int>();
foreach (TwsRtdServerTopic topic in m_topics.Values)
{
if (Array.IndexOf(TwsRtdServerData.DelayedTopics(), topic.TopicStr()) < 0)
{
topic.TopicValue(value);
m_updatedTopicIds.Add(topic.TopicId());
}
}
return m_updatedTopicIds;
}
public TwsRtdServerTopic GetOrAddTopic(string topicStr, int topicId)
{
// find topic (to reuse existing topic and not create new one)
TwsRtdServerTopic topic = null;
if (topicStr != null && !m_topics.TryGetValue(topicStr, out topic))
{
// if topic was not found, then create new one
topic = new TwsRtdServerTopic(topicStr, topicId);
// add [topicStr=>topic] mapping to collection of topics
m_topics.Add(topicStr, topic);
// set initial value of topic (in case of non-streaming market data)
topic.TopicValue(m_mktDataTicks.GetValue(topicStr));
}
return topic;
}
public bool ContainsTopic(string topicStr)
{
return m_topics.ContainsKey(topicStr);
}
public int TopicsCount()
{
return m_topics.Count;
}
public TwsRtdServerTopic GetTopic(string topicStr)
{
TwsRtdServerTopic topic;
return m_topics.TryGetValue(topicStr, out topic) ? topic : null;
}
public void RemoveTopic(string topicStr)
{
m_topics.Remove(topicStr);
}
public string MktDataRequestStr()
{
return m_mktDataRequestStr;
}
public int TwsReqId()
{
return m_twsReqId;
}
public Contract ExtractContract(string mktDataRequest)
{
Contract contract = new Contract();
string[] strings = mktDataRequest.Split(TwsRtdServerData.CHAR_UNDERSCORE);
if (strings.Length != 16)
{
SetError(TwsRtdServerErrors.CANNOT_EXTRACT_CONTRACT, "Cannot extract contract from " + mktDataRequest);
return contract;
}
try
{
if (strings[0] != null && strings[0].Length > 0)
{
contract.ConId = StrToInt(strings[0]);
}
contract.Symbol = strings[1];
contract.SecType = strings[2];
contract.LastTradeDateOrContractMonth = strings[3];
if (strings[4] != null && strings[4].Length > 0)
{
contract.Strike = StrToDouble(strings[4]);
}
contract.Right = strings[5];
contract.Multiplier = strings[6];
contract.Exchange = strings[7];
contract.PrimaryExch = strings[8];
contract.Currency = strings[9];
contract.LocalSymbol = strings[10];
contract.TradingClass = strings[11];
}
catch
{
SetError(TwsRtdServerErrors.CANNOT_EXTRACT_CONTRACT, "Exception during contract extraction from " + mktDataRequest);
return contract;
}
// parse combo legs
string comboStr = strings[12];
try
{
if (comboStr != null && comboStr.Length > 0)
{
contract.ComboLegs = new List<ComboLeg>();
string[] comboLegsStr = comboStr.Split(TwsRtdServerData.CHAR_SEMICOLON);
foreach (string comboLegStr in comboLegsStr)
{
if (comboLegStr != null && comboLegStr.Length > 0)
{
ComboLeg comboLeg = new ComboLeg();
string[] comboParams = comboLegStr.Split(TwsRtdServerData.CHAR_HASH);
if (comboParams.Length == 4)
{
comboLeg.ConId = StrToInt(comboParams[0]);
comboLeg.Ratio = StrToInt(comboParams[1]);
string action = comboParams[2];
if (action != null && action.Length > 0)
{
if (action == TwsRtdServerData.ACTION_SELL_1 || (action == TwsRtdServerData.ACTION_SELL_2))
{
comboLeg.Action = TwsRtdServerData.ACTION_SELL_1;
}
else if (action == TwsRtdServerData.ACTION_SELL_SHORT_1 || (action == TwsRtdServerData.ACTION_SELL_SHORT_2))
{
comboLeg.Action = TwsRtdServerData.ACTION_SELL_SHORT_1;
}
else // default
{
comboLeg.Action = TwsRtdServerData.ACTION_BUY_1;
}
}
comboLeg.Exchange = comboParams[3];
contract.ComboLegs.Add(comboLeg);
}
else
{
SetError(TwsRtdServerErrors.CANNOT_EXTRACT_COMBO_LEGS, "Cannot extract combo legs from " + comboStr);
return contract;
}
}
}
}
}
catch
{
SetError(TwsRtdServerErrors.CANNOT_EXTRACT_COMBO_LEGS, "Exception during combo legs extraction from " + comboStr);
return contract;
}
// parse delta-neutral contract
string deltaNeutralContractStr = strings[13];
try
{
if (deltaNeutralContractStr != null && deltaNeutralContractStr.Length > 0)
{
contract.DeltaNeutralContract = new DeltaNeutralContract();
string[] deltaNeutralContractParams = deltaNeutralContractStr.Split(TwsRtdServerData.CHAR_HASH);
if (deltaNeutralContractParams != null && deltaNeutralContractParams.Length >= 3)
{
try
{
contract.DeltaNeutralContract.ConId = StrToInt(deltaNeutralContractParams[0]);
}
catch
{
SetError(TwsRtdServerErrors.CANNOT_EXTRACT_DELTA_NEUTRAL_CONTRACT, "Cannot convert conid from " + deltaNeutralContractParams[0] + " : " + StrToInt(deltaNeutralContractParams[0]));
return contract;
}
try
{
contract.DeltaNeutralContract.Delta = StrToDouble(deltaNeutralContractParams[1]);
}
catch
{
SetError(TwsRtdServerErrors.CANNOT_EXTRACT_DELTA_NEUTRAL_CONTRACT, "Cannot convert delta from " + deltaNeutralContractParams[1] + " : " + StrToDouble(deltaNeutralContractParams[1]));
return contract;
}
try
{
contract.DeltaNeutralContract.Price = StrToDouble(deltaNeutralContractParams[2]);
}
catch
{
SetError(TwsRtdServerErrors.CANNOT_EXTRACT_DELTA_NEUTRAL_CONTRACT, "Cannot convert price from " + deltaNeutralContractParams[2] + " : " + StrToDouble(deltaNeutralContractParams[2]));
return contract;
}
}
else
{
SetError(TwsRtdServerErrors.CANNOT_EXTRACT_DELTA_NEUTRAL_CONTRACT, "Cannot extract delta-neutral contract from " + deltaNeutralContractStr);
return contract;
}
}
}
catch
{
SetError(TwsRtdServerErrors.CANNOT_EXTRACT_DELTA_NEUTRAL_CONTRACT, "Exception during delta-neutral contract extraction from " + deltaNeutralContractStr);
}
return contract;
}
public List<TagValue> ExtractOptions(string mktDataRequest)
{
List<TagValue> options = new List<TagValue>();
try
{
string[] strings = mktDataRequest.Split(TwsRtdServerData.CHAR_UNDERSCORE);
if (strings.Length == 16)
{
// parse options
string optionsStr = strings[14];
if (optionsStr != null && optionsStr.Length > 0)
{
string[] optionsParams = optionsStr.Split(TwsRtdServerData.CHAR_SEMICOLON);
foreach (string optionsParam in optionsParams)
{
if (optionsParam != null && optionsParam.Length > 0)
{
TagValue tagValue = new TagValue();
string[] tagValueStr = optionsParam.Split(TwsRtdServerData.CHAR_HASH);
if (tagValueStr.Length == 2)
{
tagValue.Tag = tagValueStr[0];
tagValue.Value = tagValueStr[1];
}
options.Add(tagValue);
}
}
}
}
}
catch
{
SetError(TwsRtdServerErrors.CANNOT_EXTRACT_OPTIONS);
}
return options;
}
public string ExtractGenericTicks(string mktDataRequest, string secTypeStr)
{
string genericTicksStr = null;
try
{
string[] strings = mktDataRequest.Split(TwsRtdServerData.CHAR_UNDERSCORE);
if (strings.Length == 16)
{
// parse generic ticks list
genericTicksStr = strings[15];
}
if ((genericTicksStr == null || genericTicksStr == "") && secTypeStr != null)
{
// generic ticks
switch (secTypeStr)
{
case "STK":
genericTicksStr = TwsRtdServerData.GENERIC_TICKS_STK;
break;
case "OPT":
genericTicksStr = TwsRtdServerData.GENERIC_TICKS_OPT;
break;
case "FUT":
case "FOP":
case "WAR":
case "CFD":
case "BOND":
case "CASH":
genericTicksStr = TwsRtdServerData.GENERIC_TICKS_FUT;
break;
case "IND":
genericTicksStr = TwsRtdServerData.GENERIC_TICKS_IND;
break;
default:
genericTicksStr = TwsRtdServerData.GENERIC_TICKS_BASE;
break;
}
}
}
catch
{
SetError(TwsRtdServerErrors.CANNOT_EXTRACT_GENERIC_TICKS);
}
return genericTicksStr;
}
private static double StrToDouble(string str)
{
NumberFormatInfo provider = new NumberFormatInfo();
provider.NumberDecimalSeparator = TwsRtdServerData.CHAR_DOT.ToString();
double num;
return (double.TryParse(str, NumberStyles.AllowDecimalPoint, provider, out num) ? num : 0);
}
private int StrToInt(string str){
int number;
return (int.TryParse(str, out number) ? number : 0);
}
public static string ParseMktDataRequestStrings(Array strings)
{
string mktDataRequestStr = null;
// contract
string symbolStr = null;
string exchStr = null;
string primExchStr = null;
string secTypeStr = null;
string expirationStr = null;
string rightStr = null;
string strikeStr = null;
string currencyStr = null;
string multiplierStr = null;
string localSymbolStr = null;
string conIdStr = null;
string tradingClassStr = null;
string comboStr = null;
string deltaNeutralContractStr = null;
string optionsStr = null;
string genTicksStr = null;
if (strings != null)
{
// simple syntax: first string should represent ticker
if (strings.Length > 0)
{
string tickerStr = (string)strings.GetValue(0);
if (tickerStr.IndexOf(TwsRtdServerData.CHAR_EQUAL) < 0)
{
if (tickerStr.IndexOf(TwsRtdServerData.CHAR_SPACE) >= 0)
{
// parse ticker string like IBM@SMART Bid, BRK B@SMART Bid, where the topic is specified within the ticker string itself
string lastStr = tickerStr.Substring(tickerStr.LastIndexOf(TwsRtdServerData.CHAR_SPACE) + 1, tickerStr.Length - 1 - tickerStr.LastIndexOf(TwsRtdServerData.CHAR_SPACE)).ToUpper();
if (Array.IndexOf(TwsRtdServerData.AllowedTopics(), lastStr) >= 0)
{
tickerStr = tickerStr.ToUpper().Substring(0, tickerStr.LastIndexOf(TwsRtdServerData.CHAR_SPACE));
}
}
if (tickerStr.IndexOf(TwsRtdServerData.CHAR_DOT) >= 0 && tickerStr.ToLower().IndexOf(TwsRtdServerData.HOST_STR) < 0 &&
tickerStr.ToLower().IndexOf(TwsRtdServerData.DELTANEUTRALCONTRACT_STR) < 0 && tickerStr.ToUpper().IndexOf(TwsRtdServerData.CHAR_SLASH + TwsRtdServerData.CASH_STR) >= 0)
{
// parse string like "EUR.USD/CASH"
string[] contractStrings = tickerStr.ToUpper().Split(TwsRtdServerData.CHAR_SLASH);
if (contractStrings.Length >= 2)
{
secTypeStr = contractStrings[1].ToUpper();
}
// "EUR.USD"
string symbolAndCashStr = contractStrings[0].ToUpper();
symbolStr = symbolAndCashStr.Substring(0, symbolAndCashStr.IndexOf(TwsRtdServerData.CHAR_DOT));
currencyStr = symbolAndCashStr.Substring(symbolAndCashStr.IndexOf(TwsRtdServerData.CHAR_DOT) + 1, symbolAndCashStr.Length - symbolAndCashStr.IndexOf(TwsRtdServerData.CHAR_DOT) - 1);
exchStr = TwsRtdServerData.DEFAULT_CASH_EXCHANGE;
//break;
}
else if (tickerStr.IndexOf(TwsRtdServerData.CHAR_SLASH) >= 0)
{
// parse string like "IBM@SMART/NYSE/OPT/201701/C/90/USD"
string[] contractStrings = tickerStr.ToUpper().Split(TwsRtdServerData.CHAR_SLASH);
if (contractStrings.Length >= 7)
{
currencyStr = contractStrings[6].ToUpper();
}
if (contractStrings.Length >= 6)
{
strikeStr = contractStrings[5].ToUpper();
}
if (contractStrings.Length >= 5)
{
rightStr = contractStrings[4].ToUpper();
}
if (contractStrings.Length >= 4)
{
expirationStr = contractStrings[3].ToUpper();
}
if (contractStrings.Length >= 3)
{
secTypeStr = contractStrings[2].ToUpper();
}
if (contractStrings.Length >= 2)
{
primExchStr = contractStrings[1].ToUpper();
}
string symbolAndExchStr = contractStrings[0].ToUpper();
if (symbolAndExchStr.IndexOf(TwsRtdServerData.CHAR_AT) >= 0)
{
// symbol can contain dot (".") and case sensitive
symbolStr = symbolAndExchStr.Substring(0, symbolAndExchStr.IndexOf(TwsRtdServerData.CHAR_AT));
exchStr = symbolAndExchStr.Substring(symbolAndExchStr.IndexOf(TwsRtdServerData.CHAR_AT) + 1, symbolAndExchStr.Length - symbolAndExchStr.IndexOf(TwsRtdServerData.CHAR_AT) - 1);
}
else
{
symbolStr = symbolAndExchStr;
exchStr = TwsRtdServerData.DEFAULT_EXCHANGE;
}
//break;
}
else if (tickerStr.IndexOf(TwsRtdServerData.CHAR_AT) >= 0)
{
// parse string like "IBM@ARCA"
symbolStr = tickerStr.ToUpper().Substring(0, tickerStr.IndexOf(TwsRtdServerData.CHAR_AT));
exchStr = tickerStr.ToUpper().Substring(tickerStr.IndexOf(TwsRtdServerData.CHAR_AT) + 1, tickerStr.Length - tickerStr.IndexOf(TwsRtdServerData.CHAR_AT) - 1);
//break;
}
else
{
// parse string like "IBM"
symbolStr = tickerStr.ToUpper();
}
}
}
// complex syntax
foreach (string s in strings)
{
if (symbolStr == null && s.ToLower().IndexOf(TwsRtdServerData.SYMBOL_STR) >= 0)
{
// parse string like "sym=IBM"
symbolStr = s.Substring(TwsRtdServerData.SYMBOL_STR.Length, s.Length - TwsRtdServerData.SYMBOL_STR.Length);
}
if (secTypeStr == null && s.ToLower().IndexOf(TwsRtdServerData.SECTYPE_STR) >= 0)
{
// parse string like "sec=OPT"
secTypeStr = s.Substring(TwsRtdServerData.SECTYPE_STR.Length, s.Length - TwsRtdServerData.SECTYPE_STR.Length).ToUpper();
}
if (expirationStr == null && s.ToLower().IndexOf(TwsRtdServerData.EXPIRATION_STR) >= 0)
{
// parse string like "exp=20170101"
expirationStr = s.Substring(TwsRtdServerData.EXPIRATION_STR.Length, s.Length - TwsRtdServerData.EXPIRATION_STR.Length).ToUpper();
}
if (strikeStr == null && s.ToLower().IndexOf(TwsRtdServerData.STRIKE_STR) >= 0)
{
// parse string like "strike=90"
strikeStr = s.Substring(TwsRtdServerData.STRIKE_STR.Length, s.Length - TwsRtdServerData.STRIKE_STR.Length).ToUpper();
}
if (rightStr == null && s.ToLower().IndexOf(TwsRtdServerData.RIGHT_STR) >= 0)
{
// parse string like "right=C"
rightStr = s.Substring(TwsRtdServerData.RIGHT_STR.Length, s.Length - TwsRtdServerData.RIGHT_STR.Length).ToUpper();
}
if (multiplierStr == null && s.ToLower().IndexOf(TwsRtdServerData.MULTIPLIER_STR) >= 0)
{
// parse string like "mult=100"
multiplierStr = s.Substring(TwsRtdServerData.MULTIPLIER_STR.Length, s.Length - TwsRtdServerData.MULTIPLIER_STR.Length).ToUpper();
}
if (exchStr == null && s.ToLower().IndexOf(TwsRtdServerData.EXCHANGE_STR) >= 0)
{
// parse string like "exch=SMART"
exchStr = s.Substring(TwsRtdServerData.EXCHANGE_STR.Length, s.Length - TwsRtdServerData.EXCHANGE_STR.Length).ToUpper();
}
if (primExchStr == null && s.ToLower().IndexOf(TwsRtdServerData.PRIMARYEXCH_STR) >= 0)
{
// parse string like "prim=NYSE"
primExchStr = s.Substring(TwsRtdServerData.PRIMARYEXCH_STR.Length, s.Length - TwsRtdServerData.PRIMARYEXCH_STR.Length).ToUpper();
}
if (currencyStr == null && s.ToLower().IndexOf(TwsRtdServerData.CURRENCY_STR) >= 0)
{
// parse string like "cur=USD"
currencyStr = s.Substring(TwsRtdServerData.CURRENCY_STR.Length, s.Length - TwsRtdServerData.CURRENCY_STR.Length).ToUpper();
}
if (conIdStr == null && s.ToLower().IndexOf(TwsRtdServerData.CONID_STR) >= 0)
{
// parse string like "conid=8314"
conIdStr = s.Substring(TwsRtdServerData.CONID_STR.Length, s.Length - TwsRtdServerData.CONID_STR.Length).ToUpper();
}
if (localSymbolStr == null && s.ToLower().IndexOf(TwsRtdServerData.LOCALSYMBOL_STR) >= 0)
{
// parse string like "loc=IBM1DM7"
localSymbolStr = s.Substring(TwsRtdServerData.LOCALSYMBOL_STR.Length, s.Length - TwsRtdServerData.LOCALSYMBOL_STR.Length);
}
if (tradingClassStr == null && s.ToLower().IndexOf(TwsRtdServerData.TRADINGCLASS_STR) >= 0)
{
// parse string like "tc=IBM1D"
tradingClassStr = s.Substring(TwsRtdServerData.TRADINGCLASS_STR.Length, s.Length - TwsRtdServerData.TRADINGCLASS_STR.Length).ToUpper();
}
if (comboStr == null && s.ToLower().IndexOf(TwsRtdServerData.COMBO_STR) >= 0)
{
// parse string like "cmb=..."
comboStr = s.Substring(TwsRtdServerData.COMBO_STR.Length, s.Length - TwsRtdServerData.COMBO_STR.Length).ToUpper();
}
if (deltaNeutralContractStr == null && s.ToLower().IndexOf(TwsRtdServerData.DELTANEUTRALCONTRACT_STR) >= 0)
{
// parse string like "und=..."
deltaNeutralContractStr = s.Substring(TwsRtdServerData.DELTANEUTRALCONTRACT_STR.Length, s.Length - TwsRtdServerData.DELTANEUTRALCONTRACT_STR.Length).ToUpper();
}
if (optionsStr == null && s.ToLower().IndexOf(TwsRtdServerData.OPTIONS_STR) >= 0)
{
// parse string like "opt=..."
optionsStr = s.Substring(TwsRtdServerData.OPTIONS_STR.Length, s.Length - TwsRtdServerData.OPTIONS_STR.Length).ToUpper();
}
if (genTicksStr == null && s.ToLower().IndexOf(TwsRtdServerData.GENTICKS_STR) >= 0)
{
// parse string like "genticks=..."
genTicksStr = s.Substring(TwsRtdServerData.GENTICKS_STR.Length, s.Length - TwsRtdServerData.GENTICKS_STR.Length).ToUpper();
}
}
}
// defaults
if (localSymbolStr == null || localSymbolStr.Length <= 0)
{
if ((secTypeStr == null || secTypeStr.Length <= 0) && conIdStr == null)
{
secTypeStr = TwsRtdServerData.DEFAULT_SECTYPE;
}
if (exchStr == null || exchStr.Length <= 0)
{
exchStr = TwsRtdServerData.DEFAULT_EXCHANGE;
}
if ((currencyStr == null || currencyStr.Length <= 0) && conIdStr == null)
{
currencyStr = TwsRtdServerData.DEFAULT_CURRENCY;
}
}
mktDataRequestStr = conIdStr + TwsRtdServerData.CHAR_UNDERSCORE +
symbolStr + TwsRtdServerData.CHAR_UNDERSCORE +
secTypeStr + TwsRtdServerData.CHAR_UNDERSCORE +
expirationStr + TwsRtdServerData.CHAR_UNDERSCORE +
strikeStr + TwsRtdServerData.CHAR_UNDERSCORE +
rightStr + TwsRtdServerData.CHAR_UNDERSCORE +
multiplierStr + TwsRtdServerData.CHAR_UNDERSCORE +
exchStr + TwsRtdServerData.CHAR_UNDERSCORE +
primExchStr + TwsRtdServerData.CHAR_UNDERSCORE +
currencyStr + TwsRtdServerData.CHAR_UNDERSCORE +
localSymbolStr + TwsRtdServerData.CHAR_UNDERSCORE +
tradingClassStr + TwsRtdServerData.CHAR_UNDERSCORE +
comboStr + TwsRtdServerData.CHAR_UNDERSCORE +
deltaNeutralContractStr + TwsRtdServerData.CHAR_UNDERSCORE +
optionsStr + TwsRtdServerData.CHAR_UNDERSCORE +
genTicksStr;
return mktDataRequestStr;
}
public void SetMktDataTickValue(string topicStr, Object value)
{
m_mktDataTicks.SetValue(topicStr, value);
}
public Object GetMktDataTickValue(string topicStr)
{
return m_mktDataTicks.GetValue(topicStr);
}
}
}