-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCancelRouteEx.py
More file actions
178 lines (122 loc) · 6.24 KB
/
Copy pathCancelRouteEx.py
File metadata and controls
178 lines (122 loc) · 6.24 KB
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
# CancelRouteEx.py
import blpapi
import sys
SESSION_STARTED = blpapi.Name("SessionStarted")
SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure")
SERVICE_OPENED = blpapi.Name("ServiceOpened")
SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure")
ERROR_INFO = blpapi.Name("ErrorInfo")
CANCEL_ROUTE = blpapi.Name("CancelRouteEx")
d_service="//blp/emapisvc_beta"
#d_service="//blp/emapisvc"
d_host="localhost"
d_port=8194
bEnd=False
class SessionEventHandler():
def processEvent(self, event, session):
try:
if event.eventType() == blpapi.Event.SESSION_STATUS:
self.processSessionStatusEvent(event,session)
elif event.eventType() == blpapi.Event.SERVICE_STATUS:
self.processServiceStatusEvent(event,session)
elif event.eventType() == blpapi.Event.RESPONSE:
self.processResponseEvent(event)
else:
self.processMiscEvents(event)
except:
print ("Exception: %s" % sys.exc_info()[0])
return False
def processSessionStatusEvent(self,event,session):
print ("Processing SESSION_STATUS event")
for msg in event:
if msg.messageType() == SESSION_STARTED:
print ("Session started...")
session.openServiceAsync(d_service)
elif msg.messageType() == SESSION_STARTUP_FAILURE:
print("Error: Session startup failed", file=sys.stderr)
else:
print (msg)
def processServiceStatusEvent(self,event,session):
print ("Processing SERVICE_STATUS event")
for msg in event:
if msg.messageType() == SERVICE_OPENED:
print ("Service opened...")
service = session.getService(d_service)
request = service.createRequest("CancelRouteEx")
#request.set("EMSX_REQUEST_SEQ", 1)
# UUID of trader who owns the order.
# Only required if this differs from the UUID sending the request
#request.set("EMSX_TRADER_UUID", 1234567)
orderRoutes = request.getElement("ID_TYPE").setChoice("OrderRoute")
orderRoute = orderRoutes.appendElement()
orderRoute.setElement("EMSX_ROUTE_ID",1)
orderRoute.setElement("EMSX_SEQUENCE",1234567)
#multilegs = request.getElement("ID_TYPE").setChoice("OrderRoute")
#multileg = multilegs.appendElement()
#multileg.setElement("EMSX_ML_ID", 123456)
# This value is used to indicate that this instruction is the result of a fully automated workflow (False) or manual workflow (True)
#request.set("EMSX_MANUAL_ORD_INDICATOR", False)
print ("Request: %s" % request.toString())
self.requestID = blpapi.CorrelationId()
session.sendRequest(request, correlationId=self.requestID )
elif msg.messageType() == SERVICE_OPEN_FAILURE:
print("Error: Service failed to open", file=sys.stderr)
def processResponseEvent(self, event):
print ("Processing RESPONSE event")
for msg in event:
print ("MESSAGE: %s" % msg.toString())
print ("CORRELATION ID: %d" % msg.correlationIds()[0].value())
if msg.correlationIds()[0].value() == self.requestID.value():
print ("MESSAGE TYPE: %s" % msg.messageType())
if msg.messageType() == ERROR_INFO:
errorCode = msg.getElementAsInteger("ERROR_CODE")
errorMessage = msg.getElementAsString("ERROR_MESSAGE")
print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage))
elif msg.messageType() == CANCEL_ROUTE:
status = msg.getElementAsInteger("STATUS")
message = msg.getElementAsString("MESSAGE")
print ("STATUS: %d\tMESSAGE: %s" % (status,message))
global bEnd
bEnd = True
def processMiscEvents(self, event):
print ("Processing " + event.eventType() + " event")
for msg in event:
print ("MESSAGE: %s" % (msg.tostring()))
def main():
sessionOptions = blpapi.SessionOptions()
sessionOptions.setServerHost(d_host)
sessionOptions.setServerPort(d_port)
print ("Connecting to %s:%d" % (d_host,d_port))
eventHandler = SessionEventHandler()
session = blpapi.Session(sessionOptions, eventHandler.processEvent)
if not session.startAsync():
print ("Failed to start session.")
return
global bEnd
while bEnd==False:
pass
session.stop()
if __name__ == "__main__":
print ("Bloomberg - EMSX API Example - CancelRoute")
try:
main()
except KeyboardInterrupt:
print ("Ctrl+C pressed. Stopping...")
__copyright__ = """
Copyright 2024. Bloomberg Finance L.P.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: The above
copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
"""