11# CreateBasket.py
22
3- import blpapi
43import sys
4+ import blpapi
55
66
77SESSION_STARTED = blpapi .Name ("SessionStarted" )
88SESSION_STARTUP_FAILURE = blpapi .Name ("SessionStartupFailure" )
99SERVICE_OPENED = blpapi .Name ("ServiceOpened" )
1010SERVICE_OPEN_FAILURE = blpapi .Name ("ServiceOpenFailure" )
1111ERROR_INFO = blpapi .Name ("ErrorInfo" )
12- CREATE_ORDER = blpapi .Name ("CreateOrder " )
12+ CREATE_BASKET = blpapi .Name ("CreateBasket " )
1313
1414d_service = "//blp/emapisvc_beta"
1515d_host = "localhost"
@@ -33,87 +33,87 @@ def processEvent(self, event, session):
3333 self .processMiscEvents (event )
3434
3535 except :
36- print ("Exception: %s" % sys .exc_info ()[0 ])
36+ print ("Exception: %s" % sys .exc_info ()[0 ])
3737
3838 return False
3939
4040
4141 def processSessionStatusEvent (self ,event ,session ):
42- print ("Processing SESSION_STATUS event" )
42+ print ("Processing SESSION_STATUS event" )
4343
4444 for msg in event :
4545 if msg .messageType () == SESSION_STARTED :
46- print ("Session started..." )
46+ print ("Session started..." )
4747 session .openServiceAsync (d_service )
4848
4949 elif msg .messageType () == SESSION_STARTUP_FAILURE :
50- print >> sys . stderr , ("Error: Session startup failed" )
50+ print ("Error: Session startup failed" )
5151
5252 else :
53- print (msg )
53+ print (msg )
5454
5555
5656 def processServiceStatusEvent (self ,event ,session ):
57- print ("Processing SERVICE_STATUS event" )
57+ print ("Processing SERVICE_STATUS event" )
5858
5959 for msg in event :
6060
6161 if msg .messageType () == SERVICE_OPENED :
62- print ("Service opened..." )
62+ print ("Service opened..." )
6363
6464 service = session .getService (d_service )
6565
6666 request = service .createRequest ("CreateBasket" )
6767
68- # The fields below are mandatory
69- # Specify the basket name
70- request .set ("EMSX_BASKET_NAME" , "TEST" )
68+ # define the basket name
69+ request .set ("EMSX_BASKET_NAME" , "TestBasket" )
7170
72- # Multiple order numbers can be added.
73- # EMSX Order# or OrderID before the date on the new EMSX blotter
74- request .append ("EMSX_SEQUENCE" , 4313227 )
71+ # add any number of orders
72+ request .append ("EMSX_SEQUENCE" , 4313227 )
7573 request .append ("EMSX_SEQUENCE" , 4313228 )
76-
77- print ("Request: %s" % request .toString ())
74+ #request.append("EMSX_SEQUENCE", 4313184)
75+
76+ print ("Request: %s" % request .toString ())
7877
7978 self .requestID = blpapi .CorrelationId ()
8079
8180 session .sendRequest (request , correlationId = self .requestID )
82-
81+
8382 elif msg .messageType () == SERVICE_OPEN_FAILURE :
84- print >> sys .stderr , ("Error: Service failed to open" )
83+ print ("Error: Service failed to open" )
84+
8585
8686 def processResponseEvent (self , event ):
87- print ("Processing RESPONSE event" )
87+ print ("Processing RESPONSE event" )
8888
8989 for msg in event :
9090
91- print ("MESSAGE: %s" % msg .toString ())
92- print ("CORRELATION ID: %d" % msg .correlationIds ()[0 ].value ())
91+ print ("MESSAGE: %s" % msg .toString ())
92+ print ("CORRELATION ID: %d" % msg .correlationIds ()[0 ].value ())
9393
9494
9595 if msg .correlationIds ()[0 ].value () == self .requestID .value ():
96- print ("MESSAGE TYPE: %s" % msg .messageType ())
96+ print ("MESSAGE TYPE: %s" % msg .messageType ())
9797
9898 if msg .messageType () == ERROR_INFO :
9999 errorCode = msg .getElementAsInteger ("ERROR_CODE" )
100100 errorMessage = msg .getElementAsString ("ERROR_MESSAGE" )
101- print ("ERROR CODE: %d\t ERROR MESSAGE: %s" % (errorCode ,errorMessage ))
102- elif msg .messageType () == CREATE_ORDER :
101+ print ("ERROR CODE: %d\t ERROR MESSAGE: %s" % (errorCode ,errorMessage ))
102+ elif msg .messageType () == CREATE_BASKET :
103103 emsx_sequence = msg .getElementAsInteger ("EMSX_SEQUENCE" )
104104 message = msg .getElementAsString ("MESSAGE" )
105- print ("EMSX_SEQUENCE: %d\t MESSAGE: %s" % (emsx_sequence ,message ))
105+ print ("EMSX_SEQUENCE: %d\t MESSAGE: %s" % (emsx_sequence ,message ))
106106
107107 global bEnd
108108 bEnd = True
109109
110110 def processMiscEvents (self , event ):
111111
112- print ("Processing " + event .eventType () + " event" )
112+ print ("Processing " + event .eventType () + " event" )
113113
114114 for msg in event :
115115
116- print ("MESSAGE: %s" % (msg .tostring ()))
116+ print ("MESSAGE: %s" % (msg .tostring ()))
117117
118118
119119def main ():
@@ -122,14 +122,14 @@ def main():
122122 sessionOptions .setServerHost (d_host )
123123 sessionOptions .setServerPort (d_port )
124124
125- print ("Connecting to %s:%d" % (d_host ,d_port ))
125+ print ("Connecting to %s:%d" % (d_host ,d_port ))
126126
127127 eventHandler = SessionEventHandler ()
128128
129129 session = blpapi .Session (sessionOptions , eventHandler .processEvent )
130130
131131 if not session .startAsync ():
132- print ("Failed to start session." )
132+ print ("Failed to start session." )
133133 return
134134
135135 global bEnd
@@ -139,15 +139,16 @@ def main():
139139 session .stop ()
140140
141141if __name__ == "__main__" :
142- print ("Bloomberg - EMSX API Example - CreateOrder " )
142+ print ("Bloomberg - EMSX API Example - CreateBasket " )
143143 try :
144144 main ()
145145 except KeyboardInterrupt :
146- print ("Ctrl+C pressed. Stopping..." )
146+ print ("Ctrl+C pressed. Stopping..." )
147147
148148
149149__copyright__ = """
150- Copyright 2017. Bloomberg Finance L.P.
150+ Copyright 2018. Bloomberg Finance L.P.
151+
151152Permission is hereby granted, free of charge, to any person obtaining a copy
152153of this software and associated documentation files (the "Software"), to
153154deal in the Software without restriction, including without limitation the
@@ -156,11 +157,12 @@ def main():
156157furnished to do so, subject to the following conditions: The above
157158copyright notice and this permission notice shall be included in all copies
158159or substantial portions of the Software.
160+
159161THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
160162IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
161163FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
162164AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
163165LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
164166FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
165167IN THE SOFTWARE.
166- """
168+ """
0 commit comments