-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwsRtdServerTopic.cs
114 lines (96 loc) · 3.61 KB
/
TwsRtdServerTopic.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
/* 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;
namespace TwsRtdServer
{
// class represents RTD server topic (id, value, string name) (e.g. [25, 177.55, "BID"])
public class TwsRtdServerTopic
{
// vars
private int m_topicId = -1;
private Object m_topicValue;
private string m_topicStr;
// constructor
public TwsRtdServerTopic(string topicStr, int topicId)
{
m_topicStr = topicStr;
m_topicId = topicId;
m_topicValue = "";
}
public int TopicId()
{
return m_topicId;
}
public Object TopicValue()
{
return m_topicValue;
}
public string TopicStr()
{
return m_topicStr;
}
public void TopicValue(Object topicValue)
{
m_topicValue = topicValue;
}
public static string ParseTopicStrings(Array strings)
{
string topicStr = null;
if (strings != null)
{
foreach (string s in strings)
{
if (topicStr == null && s.ToLower().IndexOf(TwsRtdServerData.QT) >= 0)
{
// parse string like "qt=Bid"
// "qt" string should have priority than topic specified at other places
topicStr = s.Substring(TwsRtdServerData.QT.Length, s.Length - TwsRtdServerData.QT.Length).ToUpper();
if (Array.IndexOf(TwsRtdServerData.AllowedTopics(), topicStr) >= 0)
{
return topicStr;
}
else
{
// if invalid "qt" is specified
return null;
}
}
if (topicStr == null && !s.ToLower().Contains(TwsRtdServerData.LOCALSYMBOL_STR) && s.ToLower().Contains(TwsRtdServerData.CHAR_SPACE.ToString()))
{
// pasre string like "IBM Bid" or "BRK B Bid"
topicStr = s.Substring(s.LastIndexOf(TwsRtdServerData.CHAR_SPACE) + 1, s.Length - 1 - s.LastIndexOf(TwsRtdServerData.CHAR_SPACE)).ToUpper();
if (Array.IndexOf(TwsRtdServerData.AllowedTopics(), topicStr) >= 0)
{
return topicStr;
}
else
{
topicStr = null;
continue;
}
}
if (topicStr == null)
{
// pasre string like "Bid"
topicStr = s.ToUpper();
if (Array.IndexOf(TwsRtdServerData.AllowedTopics(), topicStr) >= 0)
{
return topicStr;
}
else
{
topicStr = null;
continue;
}
}
}
}
if (topicStr == null)
{
// topic not found, use default
topicStr = TwsRtdServerData.LAST;
}
return topicStr;
}
}
}