├── .vs ├── ProjectSettings.json ├── slnx.sqlite ├── emsx_api_repository │ └── v16 │ │ ├── .suo │ │ └── Browse.VC.db └── VSWorkspaceState.json ├── orderState.pdf ├── routeState.pdf ├── order_states.pdf ├── route_states.pdf ├── EMSXFullSet_VBA.xlsm ├── README.md ├── EMSXFullSet_Python ├── GetTeams.py ├── GetTraders.py ├── GetTradeDesks.py ├── CancelOrderEx.py ├── DeleteOrder.py ├── SellSideAck.py ├── GetBrokersWithAssetClass.py ├── SellSideReject.py ├── CreateBasket.py ├── GetBrokerStrategiesWithAssetClass.py ├── CancelRoute.py ├── GetAllFieldMetaData.py ├── GetBrokerStrategyInfoWithAssetClass.py ├── GetFieldMetaData.py ├── ManualFill.py ├── ModifyOrderEx.py ├── AssignTrader.py ├── CreateOrderAndRouteManually.py └── CreateOrder.py └── EMSXFullSet_VBA ├── DeleteOrder.cls ├── GetTeams.cls ├── CreateBasket.cls ├── CancelRoute.cls ├── SellSideAck.cls ├── SellSideReject.cls ├── GetBrokersWithAssetClass.cls ├── GetBrokerStrategiesWithAssetClass.cls ├── GetAllFieldMetaData.cls ├── GetBrokerStrategyInfoWithAssetClass.cls └── GetFieldMetaData.cls /.vs/ProjectSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "CurrentProjectSetting": "No Configurations" 3 | } -------------------------------------------------------------------------------- /orderState.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tkim/emsx_api_repository/HEAD/orderState.pdf -------------------------------------------------------------------------------- /routeState.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tkim/emsx_api_repository/HEAD/routeState.pdf -------------------------------------------------------------------------------- /.vs/slnx.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tkim/emsx_api_repository/HEAD/.vs/slnx.sqlite -------------------------------------------------------------------------------- /order_states.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tkim/emsx_api_repository/HEAD/order_states.pdf -------------------------------------------------------------------------------- /route_states.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tkim/emsx_api_repository/HEAD/route_states.pdf -------------------------------------------------------------------------------- /EMSXFullSet_VBA.xlsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tkim/emsx_api_repository/HEAD/EMSXFullSet_VBA.xlsm -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EMSX API Repository 2 | 3 | EMSX API Code Samples in C++, C#/.Net, Java, Python and Excel/VBA. 4 | -------------------------------------------------------------------------------- /.vs/emsx_api_repository/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tkim/emsx_api_repository/HEAD/.vs/emsx_api_repository/v16/.suo -------------------------------------------------------------------------------- /.vs/emsx_api_repository/v16/Browse.VC.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tkim/emsx_api_repository/HEAD/.vs/emsx_api_repository/v16/Browse.VC.db -------------------------------------------------------------------------------- /.vs/VSWorkspaceState.json: -------------------------------------------------------------------------------- 1 | { 2 | "ExpandedNodes": [ 3 | "" 4 | ], 5 | "SelectedNode": "\\EMSXFullSet_C#", 6 | "PreviewInSolutionExplorer": false 7 | } -------------------------------------------------------------------------------- /EMSXFullSet_Python/GetTeams.py: -------------------------------------------------------------------------------- 1 | # GetTeams.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | GET_TEAMS = blpapi.Name("GetTeams") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | class SessionEventHandler(): 20 | 21 | def processEvent(self, event, session): 22 | try: 23 | if event.eventType() == blpapi.Event.SESSION_STATUS: 24 | self.processSessionStatusEvent(event,session) 25 | 26 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 27 | self.processServiceStatusEvent(event,session) 28 | 29 | elif event.eventType() == blpapi.Event.RESPONSE: 30 | self.processResponseEvent(event) 31 | 32 | else: 33 | self.processMiscEvents(event) 34 | 35 | except: 36 | print ("Exception: %s" % sys.exc_info()[0]) 37 | 38 | return False 39 | 40 | 41 | def processSessionStatusEvent(self,event,session): 42 | print ("Processing SESSION_STATUS event") 43 | 44 | for msg in event: 45 | if msg.messageType() == SESSION_STARTED: 46 | print ("Session started...") 47 | session.openServiceAsync(d_service) 48 | 49 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 50 | print >> sys.stderr, ("Error: Session startup failed") 51 | 52 | else: 53 | print (msg) 54 | 55 | 56 | def processServiceStatusEvent(self,event,session): 57 | print ("Processing SERVICE_STATUS event") 58 | 59 | for msg in event: 60 | 61 | if msg.messageType() == SERVICE_OPENED: 62 | print ("Service opened...") 63 | 64 | service = session.getService(d_service) 65 | 66 | request = service.createRequest("GetTeams") 67 | 68 | #request.set("EMSX_REQUEST_SEQ", 1) 69 | 70 | print ("Request: %s" % request.toString()) 71 | 72 | self.requestID = blpapi.CorrelationId() 73 | 74 | session.sendRequest(request, correlationId=self.requestID ) 75 | 76 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 77 | print >> sys.stderr, ("Error: Service failed to open") 78 | 79 | def processResponseEvent(self, event): 80 | print ("Processing RESPONSE event") 81 | 82 | for msg in event: 83 | 84 | print ("MESSAGE: %s" % msg.toString()) 85 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 86 | 87 | 88 | if msg.correlationIds()[0].value() == self.requestID.value(): 89 | print ("MESSAGE TYPE: %s" % msg.messageType()) 90 | 91 | if msg.messageType() == ERROR_INFO: 92 | errorCode = msg.getElementAsInteger("ERROR_CODE") 93 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 94 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 95 | elif msg.messageType() == GET_TEAMS: 96 | 97 | teams = msg.getElement("TEAMS") 98 | 99 | for t in teams.values(): 100 | print ("TEAM: %s" % (t)) 101 | 102 | global bEnd 103 | bEnd = True 104 | 105 | def processMiscEvents(self, event): 106 | 107 | print ("Processing " + event.eventType() + " event") 108 | 109 | for msg in event: 110 | 111 | print ("MESSAGE: %s" % (msg.tostring())) 112 | 113 | 114 | def main(): 115 | 116 | sessionOptions = blpapi.SessionOptions() 117 | sessionOptions.setServerHost(d_host) 118 | sessionOptions.setServerPort(d_port) 119 | 120 | print ("Connecting to %s:%d" % (d_host,d_port)) 121 | 122 | eventHandler = SessionEventHandler() 123 | 124 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 125 | 126 | if not session.startAsync(): 127 | print ("Failed to start session.") 128 | return 129 | 130 | global bEnd 131 | while bEnd==False: 132 | pass 133 | 134 | session.stop() 135 | 136 | if __name__ == "__main__": 137 | print ("Bloomberg - EMSX API Example - GetTeams") 138 | try: 139 | main() 140 | except KeyboardInterrupt: 141 | print ("Ctrl+C pressed. Stopping...") 142 | 143 | 144 | __copyright__ = """ 145 | Copyright 2017. Bloomberg Finance L.P. 146 | 147 | Permission is hereby granted, free of charge, to any person obtaining a copy 148 | of this software and associated documentation files (the "Software"), to 149 | deal in the Software without restriction, including without limitation the 150 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 151 | sell copies of the Software, and to permit persons to whom the Software is 152 | furnished to do so, subject to the following conditions: The above 153 | copyright notice and this permission notice shall be included in all copies 154 | or substantial portions of the Software. 155 | 156 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 157 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 158 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 159 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 160 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 161 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 162 | IN THE SOFTWARE. 163 | """ 164 | -------------------------------------------------------------------------------- /EMSXFullSet_Python/GetTraders.py: -------------------------------------------------------------------------------- 1 | # GetTraders.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | GET_TRADERS = blpapi.Name("GetTraders") 13 | 14 | # This is an AIM only function and thus there are no valid //blp/emapisvc_beta access. 15 | d_service="//blp/emapisvc" 16 | d_host="localhost" 17 | d_port=8194 18 | bEnd=False 19 | 20 | class SessionEventHandler(): 21 | 22 | def processEvent(self, event, session): 23 | try: 24 | if event.eventType() == blpapi.Event.SESSION_STATUS: 25 | self.processSessionStatusEvent(event,session) 26 | 27 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 28 | self.processServiceStatusEvent(event,session) 29 | 30 | elif event.eventType() == blpapi.Event.RESPONSE: 31 | self.processResponseEvent(event) 32 | 33 | else: 34 | self.processMiscEvents(event) 35 | 36 | except: 37 | print ("Exception: %s" % sys.exc_info()[0]) 38 | 39 | return False 40 | 41 | 42 | def processSessionStatusEvent(self,event,session): 43 | print ("Processing SESSION_STATUS event") 44 | 45 | for msg in event: 46 | if msg.messageType() == SESSION_STARTED: 47 | print ("Session started...") 48 | session.openServiceAsync(d_service) 49 | 50 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 51 | print >> sys.stderr, ("Error: Session startup failed") 52 | 53 | else: 54 | print (msg) 55 | 56 | 57 | def processServiceStatusEvent(self,event,session): 58 | print ("Processing SERVICE_STATUS event") 59 | 60 | for msg in event: 61 | 62 | if msg.messageType() == SERVICE_OPENED: 63 | print ("Service opened...") 64 | 65 | service = session.getService(d_service) 66 | 67 | request = service.createRequest("GetTraders") 68 | 69 | #request.set("EMSX_REQUEST_SEQ", 1) 70 | 71 | print ("Request: %s" % request.toString()) 72 | 73 | self.requestID = blpapi.CorrelationId() 74 | 75 | session.sendRequest(request, correlationId=self.requestID ) 76 | 77 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 78 | print >> sys.stderr, ("Error: Service failed to open") 79 | 80 | def processResponseEvent(self, event): 81 | print ("Processing RESPONSE event") 82 | 83 | for msg in event: 84 | 85 | print ("MESSAGE: %s" % msg.toString()) 86 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 87 | 88 | 89 | if msg.correlationIds()[0].value() == self.requestID.value(): 90 | print ("MESSAGE TYPE: %s" % msg.messageType()) 91 | 92 | if msg.messageType() == ERROR_INFO: 93 | errorCode = msg.getElementAsInteger("ERROR_CODE") 94 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 95 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 96 | elif msg.messageType() == GET_TRADERS: 97 | 98 | traders = msg.getElement("EMSX_TRADER_UUID") 99 | #print(msg) 100 | 101 | for t in traders.values(): 102 | print("TRADERS: %s" %(t)) 103 | 104 | global bEnd 105 | bEnd = True 106 | 107 | def processMiscEvents(self, event): 108 | 109 | print ("Processing " + event.eventType() + " event") 110 | 111 | for msg in event: 112 | 113 | print ("MESSAGE: %s" % (msg.tostring())) 114 | 115 | 116 | def main(): 117 | 118 | sessionOptions = blpapi.SessionOptions() 119 | sessionOptions.setServerHost(d_host) 120 | sessionOptions.setServerPort(d_port) 121 | 122 | print ("Connecting to %s:%d" % (d_host,d_port)) 123 | 124 | eventHandler = SessionEventHandler() 125 | 126 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 127 | 128 | if not session.startAsync(): 129 | print ("Failed to start session.") 130 | return 131 | 132 | global bEnd 133 | while bEnd==False: 134 | pass 135 | 136 | session.stop() 137 | 138 | if __name__ == "__main__": 139 | print ("Bloomberg - EMSX API Example - GetTraders") 140 | try: 141 | main() 142 | except KeyboardInterrupt: 143 | print ("Ctrl+C pressed. Stopping...") 144 | 145 | 146 | __copyright__ = """ 147 | Copyright 2017. Bloomberg Finance L.P. 148 | Permission is hereby granted, free of charge, to any person obtaining a copy 149 | of this software and associated documentation files (the "Software"), to 150 | deal in the Software without restriction, including without limitation the 151 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 152 | sell copies of the Software, and to permit persons to whom the Software is 153 | furnished to do so, subject to the following conditions: The above 154 | copyright notice and this permission notice shall be included in all copies 155 | or substantial portions of the Software. 156 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 157 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 158 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 159 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 160 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 161 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 162 | IN THE SOFTWARE. 163 | """ -------------------------------------------------------------------------------- /EMSXFullSet_Python/GetTradeDesks.py: -------------------------------------------------------------------------------- 1 | # GetTradeDesks.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | GET_TRADE_DESKS = blpapi.Name("GetTradeDesks") 13 | 14 | # This is an AIM only function and thus there are no valid //blp/emapisvc_beta access. 15 | d_service="//blp/emapisvc" 16 | d_host="localhost" 17 | d_port=8194 18 | bEnd=False 19 | 20 | class SessionEventHandler(): 21 | 22 | def processEvent(self, event, session): 23 | try: 24 | if event.eventType() == blpapi.Event.SESSION_STATUS: 25 | self.processSessionStatusEvent(event,session) 26 | 27 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 28 | self.processServiceStatusEvent(event,session) 29 | 30 | elif event.eventType() == blpapi.Event.RESPONSE: 31 | self.processResponseEvent(event) 32 | 33 | else: 34 | self.processMiscEvents(event) 35 | 36 | except: 37 | print ("Exception: %s" % sys.exc_info()[0]) 38 | 39 | return False 40 | 41 | 42 | def processSessionStatusEvent(self,event,session): 43 | print ("Processing SESSION_STATUS event") 44 | 45 | for msg in event: 46 | if msg.messageType() == SESSION_STARTED: 47 | print ("Session started...") 48 | session.openServiceAsync(d_service) 49 | 50 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 51 | print >> sys.stderr, ("Error: Session startup failed") 52 | 53 | else: 54 | print (msg) 55 | 56 | 57 | def processServiceStatusEvent(self,event,session): 58 | print ("Processing SERVICE_STATUS event") 59 | 60 | for msg in event: 61 | 62 | if msg.messageType() == SERVICE_OPENED: 63 | print ("Service opened...") 64 | 65 | service = session.getService(d_service) 66 | 67 | request = service.createRequest("GetTradeDesks") 68 | 69 | #request.set("EMSX_REQUEST_SEQ", 1) 70 | 71 | print ("Request: %s" % request.toString()) 72 | 73 | self.requestID = blpapi.CorrelationId() 74 | 75 | session.sendRequest(request, correlationId=self.requestID ) 76 | 77 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 78 | print >> sys.stderr, ("Error: Service failed to open") 79 | 80 | def processResponseEvent(self, event): 81 | print ("Processing RESPONSE event") 82 | 83 | for msg in event: 84 | 85 | print ("MESSAGE: %s" % msg.toString()) 86 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 87 | 88 | 89 | if msg.correlationIds()[0].value() == self.requestID.value(): 90 | print ("MESSAGE TYPE: %s" % msg.messageType()) 91 | 92 | if msg.messageType() == ERROR_INFO: 93 | errorCode = msg.getElementAsInteger("ERROR_CODE") 94 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 95 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 96 | elif msg.messageType() == GET_TRADE_DESKS: 97 | 98 | tradeDesks = msg.getElement("EMSX_TRADE_DESK") 99 | print(msg) 100 | 101 | for t in tradeDesks.values(): 102 | print("TRADEDESKS: %s" %(t)) 103 | 104 | global bEnd 105 | bEnd = True 106 | 107 | def processMiscEvents(self, event): 108 | 109 | print ("Processing " + event.eventType() + " event") 110 | 111 | for msg in event: 112 | 113 | print ("MESSAGE: %s" % (msg.tostring())) 114 | 115 | 116 | def main(): 117 | 118 | sessionOptions = blpapi.SessionOptions() 119 | sessionOptions.setServerHost(d_host) 120 | sessionOptions.setServerPort(d_port) 121 | 122 | print ("Connecting to %s:%d" % (d_host,d_port)) 123 | 124 | eventHandler = SessionEventHandler() 125 | 126 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 127 | 128 | if not session.startAsync(): 129 | print ("Failed to start session.") 130 | return 131 | 132 | global bEnd 133 | while bEnd==False: 134 | pass 135 | 136 | session.stop() 137 | 138 | if __name__ == "__main__": 139 | print ("Bloomberg - EMSX API Example - GetTraders") 140 | try: 141 | main() 142 | except KeyboardInterrupt: 143 | print ("Ctrl+C pressed. Stopping...") 144 | 145 | 146 | __copyright__ = """ 147 | Copyright 2017. Bloomberg Finance L.P. 148 | Permission is hereby granted, free of charge, to any person obtaining a copy 149 | of this software and associated documentation files (the "Software"), to 150 | deal in the Software without restriction, including without limitation the 151 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 152 | sell copies of the Software, and to permit persons to whom the Software is 153 | furnished to do so, subject to the following conditions: The above 154 | copyright notice and this permission notice shall be included in all copies 155 | or substantial portions of the Software. 156 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 157 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 158 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 159 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 160 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 161 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 162 | IN THE SOFTWARE. 163 | """ -------------------------------------------------------------------------------- /EMSXFullSet_Python/CancelOrderEx.py: -------------------------------------------------------------------------------- 1 | # CancelOrderEx.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | CANCEL_ORDER = blpapi.Name("CancelOrderEx") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | #d_service="//blp/emapisvc" 16 | d_host="localhost" 17 | d_port=8194 18 | bEnd=False 19 | 20 | class SessionEventHandler(): 21 | 22 | def processEvent(self, event, session): 23 | try: 24 | if event.eventType() == blpapi.Event.SESSION_STATUS: 25 | self.processSessionStatusEvent(event,session) 26 | 27 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 28 | self.processServiceStatusEvent(event,session) 29 | 30 | elif event.eventType() == blpapi.Event.RESPONSE: 31 | self.processResponseEvent(event) 32 | 33 | else: 34 | self.processMiscEvents(event) 35 | 36 | except: 37 | print ("Exception: %s" % sys.exc_info()[0]) 38 | 39 | return False 40 | 41 | 42 | def processSessionStatusEvent(self,event,session): 43 | print ("Processing SESSION_STATUS event") 44 | 45 | for msg in event: 46 | if msg.messageType() == SESSION_STARTED: 47 | print ("Session started...") 48 | session.openServiceAsync(d_service) 49 | 50 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 51 | print >> sys.stderr, ("Error: Session startup failed") 52 | 53 | else: 54 | print (msg) 55 | 56 | 57 | def processServiceStatusEvent(self,event,session): 58 | print ("Processing SERVICE_STATUS event") 59 | 60 | for msg in event: 61 | 62 | if msg.messageType() == SERVICE_OPENED: 63 | print ("Service opened...") 64 | 65 | service = session.getService(d_service) 66 | 67 | request = service.createRequest("CancelOrderEx") 68 | 69 | #request.set("EMSX_REQUEST_SEQ", 1) 70 | #request.set("EMSX_TRADER_UUID", 1234567) # UUID of trader who owns the order 71 | 72 | request.getElement("EMSX_SEQUENCE").appendValue(4733955) 73 | #request.getElement("EMSX_SEQUENCE").appendValue(1234567) 74 | 75 | print ("Request: %s" % request.toString()) 76 | 77 | self.requestID = blpapi.CorrelationId() 78 | 79 | session.sendRequest(request, correlationId=self.requestID ) 80 | 81 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 82 | print >> sys.stderr, ("Error: Service failed to open") 83 | 84 | def processResponseEvent(self, event): 85 | print ("Processing RESPONSE event") 86 | 87 | for msg in event: 88 | 89 | print ("MESSAGE: %s" % msg.toString()) 90 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 91 | 92 | 93 | if msg.correlationIds()[0].value() == self.requestID.value(): 94 | print ("MESSAGE TYPE: %s" % msg.messageType()) 95 | 96 | if msg.messageType() == ERROR_INFO: 97 | errorCode = msg.getElementAsInteger("ERROR_CODE") 98 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 99 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 100 | elif msg.messageType() == CANCEL_ORDER: 101 | status = msg.getElementAsInteger("STATUS") 102 | message = msg.getElementAsString("MESSAGE") 103 | print ("STATUS: %d\tMESSAGE: %s" % (status,message)) 104 | 105 | global bEnd 106 | bEnd = True 107 | 108 | def processMiscEvents(self, event): 109 | 110 | print ("Processing " + event.eventType() + " event") 111 | 112 | for msg in event: 113 | 114 | print ("MESSAGE: %s" % (msg.tostring())) 115 | 116 | 117 | def main(): 118 | 119 | sessionOptions = blpapi.SessionOptions() 120 | sessionOptions.setServerHost(d_host) 121 | sessionOptions.setServerPort(d_port) 122 | 123 | print ("Connecting to %s:%d" % (d_host,d_port)) 124 | 125 | eventHandler = SessionEventHandler() 126 | 127 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 128 | 129 | if not session.startAsync(): 130 | print ("Failed to start session.") 131 | return 132 | 133 | global bEnd 134 | while bEnd==False: 135 | pass 136 | 137 | session.stop() 138 | 139 | if __name__ == "__main__": 140 | print ("Bloomberg - EMSX API Example - CancelOrderEx") 141 | try: 142 | main() 143 | except KeyboardInterrupt: 144 | print ("Ctrl+C pressed. Stopping...") 145 | 146 | 147 | __copyright__ = """ 148 | Copyright 2017. Bloomberg Finance L.P. 149 | Permission is hereby granted, free of charge, to any person obtaining a copy 150 | of this software and associated documentation files (the "Software"), to 151 | deal in the Software without restriction, including without limitation the 152 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 153 | sell copies of the Software, and to permit persons to whom the Software is 154 | furnished to do so, subject to the following conditions: The above 155 | copyright notice and this permission notice shall be included in all copies 156 | or substantial portions of the Software. 157 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 158 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 159 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 160 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 161 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 162 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 163 | IN THE SOFTWARE. 164 | """ -------------------------------------------------------------------------------- /EMSXFullSet_Python/DeleteOrder.py: -------------------------------------------------------------------------------- 1 | # DeleteOrder.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | DELETE_ORDER = blpapi.Name("DeleteOrder") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | class SessionEventHandler(): 20 | 21 | def processEvent(self, event, session): 22 | try: 23 | if event.eventType() == blpapi.Event.SESSION_STATUS: 24 | self.processSessionStatusEvent(event,session) 25 | 26 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 27 | self.processServiceStatusEvent(event,session) 28 | 29 | elif event.eventType() == blpapi.Event.RESPONSE: 30 | self.processResponseEvent(event) 31 | 32 | else: 33 | self.processMiscEvents(event) 34 | 35 | except: 36 | print ("Exception: %s" % sys.exc_info()[0]) 37 | 38 | return False 39 | 40 | 41 | def processSessionStatusEvent(self,event,session): 42 | print ("Processing SESSION_STATUS event") 43 | 44 | for msg in event: 45 | if msg.messageType() == SESSION_STARTED: 46 | print ("Session started...") 47 | session.openServiceAsync(d_service) 48 | 49 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 50 | print >> sys.stderr, ("Error: Session startup failed") 51 | 52 | else: 53 | print (msg) 54 | 55 | 56 | def processServiceStatusEvent(self,event,session): 57 | print ("Processing SERVICE_STATUS event") 58 | 59 | for msg in event: 60 | 61 | if msg.messageType() == SERVICE_OPENED: 62 | print ("Service opened...") 63 | 64 | service = session.getService(d_service) 65 | 66 | request = service.createRequest("DeleteOrder") 67 | 68 | #request.set("EMSX_REQUEST_SEQ", 1) 69 | 70 | request.getElement("EMSX_SEQUENCE").appendValue(4115597) 71 | #request.getElement("EMSX_SEQUENCE").appendValue(1234567) 72 | 73 | 74 | print ("Request: %s" % request.toString()) 75 | 76 | self.requestID = blpapi.CorrelationId() 77 | 78 | session.sendRequest(request, correlationId=self.requestID ) 79 | 80 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 81 | print >> sys.stderr, ("Error: Service failed to open") 82 | 83 | def processResponseEvent(self, event): 84 | print ("Processing RESPONSE event") 85 | 86 | for msg in event: 87 | 88 | print ("MESSAGE: %s" % msg.toString()) 89 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 90 | 91 | 92 | if msg.correlationIds()[0].value() == self.requestID.value(): 93 | print ("MESSAGE TYPE: %s" % msg.messageType()) 94 | 95 | if msg.messageType() == ERROR_INFO: 96 | errorCode = msg.getElementAsInteger("ERROR_CODE") 97 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 98 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 99 | elif msg.messageType() == DELETE_ORDER: 100 | status = msg.getElementAsInteger("STATUS") 101 | message = msg.getElementAsString("MESSAGE") 102 | print ("STATUS: %d\tMESSAGE: %s" % (status,message)) 103 | 104 | global bEnd 105 | bEnd = True 106 | 107 | def processMiscEvents(self, event): 108 | 109 | print ("Processing " + event.eventType() + " event") 110 | 111 | for msg in event: 112 | 113 | print ("MESSAGE: %s" % (msg.tostring())) 114 | 115 | 116 | def main(): 117 | 118 | sessionOptions = blpapi.SessionOptions() 119 | sessionOptions.setServerHost(d_host) 120 | sessionOptions.setServerPort(d_port) 121 | 122 | print ("Connecting to %s:%d" % (d_host,d_port)) 123 | 124 | eventHandler = SessionEventHandler() 125 | 126 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 127 | 128 | if not session.startAsync(): 129 | print ("Failed to start session.") 130 | return 131 | 132 | global bEnd 133 | while bEnd==False: 134 | pass 135 | 136 | session.stop() 137 | 138 | if __name__ == "__main__": 139 | print ("Bloomberg - EMSX API Example - DeleteOrder") 140 | try: 141 | main() 142 | except KeyboardInterrupt: 143 | print ("Ctrl+C pressed. Stopping...") 144 | 145 | 146 | __copyright__ = """ 147 | Copyright 2017. Bloomberg Finance L.P. 148 | 149 | Permission is hereby granted, free of charge, to any person obtaining a copy 150 | of this software and associated documentation files (the "Software"), to 151 | deal in the Software without restriction, including without limitation the 152 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 153 | sell copies of the Software, and to permit persons to whom the Software is 154 | furnished to do so, subject to the following conditions: The above 155 | copyright notice and this permission notice shall be included in all copies 156 | or substantial portions of the Software. 157 | 158 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 159 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 160 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 161 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 162 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 163 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 164 | IN THE SOFTWARE. 165 | """ 166 | -------------------------------------------------------------------------------- /EMSXFullSet_Python/SellSideAck.py: -------------------------------------------------------------------------------- 1 | # SellSideAck.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | SELL_SIDE_ACK = blpapi.Name("SellSideAck") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | 20 | class SessionEventHandler(): 21 | 22 | def processEvent(self, event, session): 23 | try: 24 | if event.eventType() == blpapi.Event.SESSION_STATUS: 25 | self.processSessionStatusEvent(event,session) 26 | 27 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 28 | self.processServiceStatusEvent(event,session) 29 | 30 | elif event.eventType() == blpapi.Event.RESPONSE: 31 | self.processResponseEvent(event) 32 | 33 | else: 34 | self.processMiscEvents(event) 35 | 36 | except: 37 | print ("Exception: %s" % sys.exc_info()[0]) 38 | 39 | return False 40 | 41 | 42 | def processSessionStatusEvent(self,event,session): 43 | print ("Processing SESSION_STATUS event") 44 | 45 | for msg in event: 46 | if msg.messageType() == SESSION_STARTED: 47 | print ("Session started...") 48 | session.openServiceAsync(d_service) 49 | 50 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 51 | print >> sys.stderr, ("Error: Session startup failed") 52 | 53 | else: 54 | print (msg) 55 | 56 | 57 | def processServiceStatusEvent(self,event,session): 58 | print ("Processing SERVICE_STATUS event") 59 | 60 | for msg in event: 61 | 62 | if msg.messageType() == SERVICE_OPENED: 63 | print ("Service opened...") 64 | 65 | service = session.getService(d_service) 66 | 67 | request = service.createRequest("SellSideAck"); 68 | 69 | #request.set("EMSX_REQUEST_SEQ", 1) 70 | 71 | request.append("EMSX_SEQUENCE", 1234567) 72 | 73 | # The following Element is currently not being used in this request. 74 | #request.set("EMSX_TRADER_UUID", 7654321) 75 | 76 | print ("Request: %s" % request.toString()) 77 | 78 | self.requestID = blpapi.CorrelationId() 79 | 80 | session.sendRequest(request, correlationId=self.requestID ) 81 | 82 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 83 | print >> sys.stderr, ("Error: Service failed to open") 84 | 85 | def processResponseEvent(self, event): 86 | print ("Processing RESPONSE event") 87 | 88 | for msg in event: 89 | 90 | print ("MESSAGE: %s" % msg.toString()) 91 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 92 | 93 | 94 | if msg.correlationIds()[0].value() == self.requestID.value(): 95 | print ("MESSAGE TYPE: %s" % msg.messageType()) 96 | 97 | if msg.messageType() == ERROR_INFO: 98 | errorCode = msg.getElementAsInteger("ERROR_CODE") 99 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 100 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 101 | elif msg.messageType() == SELL_SIDE_ACK: 102 | status = msg.getElementAsInteger("STATUS") 103 | message = msg.getElementAsString("MESSAGE") 104 | print ("STATUS: %d\tMESSAGE: %s" % (status,message)) 105 | 106 | global bEnd 107 | bEnd = True 108 | 109 | def processMiscEvents(self, event): 110 | 111 | print ("Processing " + event.eventType() + " event") 112 | 113 | for msg in event: 114 | 115 | print ("MESSAGE: %s" % (msg.tostring())) 116 | 117 | 118 | def main(): 119 | 120 | sessionOptions = blpapi.SessionOptions() 121 | sessionOptions.setServerHost(d_host) 122 | sessionOptions.setServerPort(d_port) 123 | 124 | print ("Connecting to %s:%d" % (d_host,d_port)) 125 | 126 | eventHandler = SessionEventHandler() 127 | 128 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 129 | 130 | if not session.startAsync(): 131 | print ("Failed to start session.") 132 | return 133 | 134 | global bEnd 135 | while bEnd==False: 136 | pass 137 | 138 | session.stop() 139 | 140 | if __name__ == "__main__": 141 | print ("Bloomberg - EMSX API Sell-Side Example - SellSideAck") 142 | try: 143 | main() 144 | except KeyboardInterrupt: 145 | print ("Ctrl+C pressed. Stopping...") 146 | 147 | 148 | __copyright__ = """ 149 | Copyright 2017. Bloomberg Finance L.P. 150 | 151 | Permission is hereby granted, free of charge, to any person obtaining a copy 152 | of this software and associated documentation files (the "Software"), to 153 | deal in the Software without restriction, including without limitation the 154 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 155 | sell copies of the Software, and to permit persons to whom the Software is 156 | furnished to do so, subject to the following conditions: The above 157 | copyright notice and this permission notice shall be included in all copies 158 | or substantial portions of the Software. 159 | 160 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 161 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 162 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 163 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 164 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 165 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 166 | IN THE SOFTWARE. 167 | """ 168 | -------------------------------------------------------------------------------- /EMSXFullSet_Python/GetBrokersWithAssetClass.py: -------------------------------------------------------------------------------- 1 | # GetBrokersWithAssetClass.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | GET_BROKERS_WITH_ASSET_CLASS = blpapi.Name("GetBrokersWithAssetClass") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | class SessionEventHandler(): 20 | 21 | def processEvent(self, event, session): 22 | try: 23 | if event.eventType() == blpapi.Event.SESSION_STATUS: 24 | self.processSessionStatusEvent(event,session) 25 | 26 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 27 | self.processServiceStatusEvent(event,session) 28 | 29 | elif event.eventType() == blpapi.Event.RESPONSE: 30 | self.processResponseEvent(event) 31 | 32 | else: 33 | self.processMiscEvents(event) 34 | 35 | except: 36 | print ("Exception: %s" % sys.exc_info()[0]) 37 | 38 | return False 39 | 40 | 41 | def processSessionStatusEvent(self,event,session): 42 | print ("Processing SESSION_STATUS event") 43 | 44 | for msg in event: 45 | if msg.messageType() == SESSION_STARTED: 46 | print ("Session started...") 47 | session.openServiceAsync(d_service) 48 | 49 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 50 | print >> sys.stderr, ("Error: Session startup failed") 51 | 52 | else: 53 | print (msg) 54 | 55 | 56 | def processServiceStatusEvent(self,event,session): 57 | print ("Processing SERVICE_STATUS event") 58 | 59 | for msg in event: 60 | 61 | if msg.messageType() == SERVICE_OPENED: 62 | print ("Service opened...") 63 | 64 | service = session.getService(d_service) 65 | 66 | request = service.createRequest("GetBrokersWithAssetClass") 67 | 68 | #request.set("EMSX_REQUEST_SEQ", 1) 69 | 70 | request.set("EMSX_ASSET_CLASS","EQTY") # one of EQTY, OPT, FUT or MULTILEG_OPT 71 | 72 | print ("Request: %s" % request.toString()) 73 | 74 | self.requestID = blpapi.CorrelationId() 75 | 76 | session.sendRequest(request, correlationId=self.requestID ) 77 | 78 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 79 | print >> sys.stderr, ("Error: Service failed to open") 80 | 81 | def processResponseEvent(self, event): 82 | print ("Processing RESPONSE event") 83 | 84 | for msg in event: 85 | 86 | print ("MESSAGE: %s" % msg.toString()) 87 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 88 | 89 | 90 | if msg.correlationIds()[0].value() == self.requestID.value(): 91 | print ("MESSAGE TYPE: %s" % msg.messageType()) 92 | 93 | if msg.messageType() == ERROR_INFO: 94 | errorCode = msg.getElementAsInteger("ERROR_CODE") 95 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 96 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 97 | elif msg.messageType() == GET_BROKERS_WITH_ASSET_CLASS: 98 | 99 | brokers = msg.getElement("EMSX_BROKERS") 100 | 101 | for b in brokers.values(): 102 | print ("EMSX_BROKER: %s" % (b)) 103 | 104 | global bEnd 105 | bEnd = True 106 | 107 | def processMiscEvents(self, event): 108 | 109 | print ("Processing " + event.eventType() + " event") 110 | 111 | for msg in event: 112 | 113 | print ("MESSAGE: %s" % (msg.tostring())) 114 | 115 | 116 | def main(): 117 | 118 | sessionOptions = blpapi.SessionOptions() 119 | sessionOptions.setServerHost(d_host) 120 | sessionOptions.setServerPort(d_port) 121 | 122 | print ("Connecting to %s:%d" % (d_host,d_port)) 123 | 124 | eventHandler = SessionEventHandler() 125 | 126 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 127 | 128 | if not session.startAsync(): 129 | print ("Failed to start session.") 130 | return 131 | 132 | global bEnd 133 | while bEnd==False: 134 | pass 135 | 136 | session.stop() 137 | 138 | if __name__ == "__main__": 139 | print ("Bloomberg - EMSX API Example - GetBrokersWithAssetClass") 140 | try: 141 | main() 142 | except KeyboardInterrupt: 143 | print ("Ctrl+C pressed. Stopping...") 144 | 145 | 146 | __copyright__ = """ 147 | Copyright 2017. Bloomberg Finance L.P. 148 | 149 | Permission is hereby granted, free of charge, to any person obtaining a copy 150 | of this software and associated documentation files (the "Software"), to 151 | deal in the Software without restriction, including without limitation the 152 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 153 | sell copies of the Software, and to permit persons to whom the Software is 154 | furnished to do so, subject to the following conditions: The above 155 | copyright notice and this permission notice shall be included in all copies 156 | or substantial portions of the Software. 157 | 158 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 159 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 160 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 161 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 162 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 163 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 164 | IN THE SOFTWARE. 165 | """ 166 | -------------------------------------------------------------------------------- /EMSXFullSet_Python/SellSideReject.py: -------------------------------------------------------------------------------- 1 | # SellSideReject.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | SELL_SIDE_REJECT = blpapi.Name("SellSideReject") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | 20 | class SessionEventHandler(): 21 | 22 | def processEvent(self, event, session): 23 | try: 24 | if event.eventType() == blpapi.Event.SESSION_STATUS: 25 | self.processSessionStatusEvent(event,session) 26 | 27 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 28 | self.processServiceStatusEvent(event,session) 29 | 30 | elif event.eventType() == blpapi.Event.RESPONSE: 31 | self.processResponseEvent(event) 32 | 33 | else: 34 | self.processMiscEvents(event) 35 | 36 | except: 37 | print ("Exception: %s" % sys.exc_info()[0]) 38 | 39 | return False 40 | 41 | 42 | def processSessionStatusEvent(self,event,session): 43 | print ("Processing SESSION_STATUS event") 44 | 45 | for msg in event: 46 | if msg.messageType() == SESSION_STARTED: 47 | print ("Session started...") 48 | session.openServiceAsync(d_service) 49 | 50 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 51 | print >> sys.stderr, ("Error: Session startup failed") 52 | 53 | else: 54 | print (msg) 55 | 56 | 57 | def processServiceStatusEvent(self,event,session): 58 | print ("Processing SERVICE_STATUS event") 59 | 60 | for msg in event: 61 | 62 | if msg.messageType() == SERVICE_OPENED: 63 | print ("Service opened...") 64 | 65 | service = session.getService(d_service) 66 | 67 | request = service.createRequest("SellSideReject"); 68 | 69 | #request.set("EMSX_REQUEST_SEQ", 1) 70 | 71 | request.append("EMSX_SEQUENCE", 1234567) 72 | 73 | # The following Element is currently not being used in this request. 74 | #request.set("EMSX_TRADER_UUID", 7654321) 75 | 76 | print ("Request: %s" % request.toString()) 77 | 78 | self.requestID = blpapi.CorrelationId() 79 | 80 | session.sendRequest(request, correlationId=self.requestID ) 81 | 82 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 83 | print >> sys.stderr, ("Error: Service failed to open") 84 | 85 | def processResponseEvent(self, event): 86 | print ("Processing RESPONSE event") 87 | 88 | for msg in event: 89 | 90 | print ("MESSAGE: %s" % msg.toString()) 91 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 92 | 93 | 94 | if msg.correlationIds()[0].value() == self.requestID.value(): 95 | print ("MESSAGE TYPE: %s" % msg.messageType()) 96 | 97 | if msg.messageType() == ERROR_INFO: 98 | errorCode = msg.getElementAsInteger("ERROR_CODE") 99 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 100 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 101 | elif msg.messageType() == SELL_SIDE_REJECT: 102 | status = msg.getElementAsInteger("STATUS") 103 | message = msg.getElementAsString("MESSAGE") 104 | print ("STATUS: %d\tMESSAGE: %s" % (status,message)) 105 | 106 | global bEnd 107 | bEnd = True 108 | 109 | def processMiscEvents(self, event): 110 | 111 | print ("Processing " + event.eventType() + " event") 112 | 113 | for msg in event: 114 | 115 | print ("MESSAGE: %s" % (msg.tostring())) 116 | 117 | 118 | def main(): 119 | 120 | sessionOptions = blpapi.SessionOptions() 121 | sessionOptions.setServerHost(d_host) 122 | sessionOptions.setServerPort(d_port) 123 | 124 | print ("Connecting to %s:%d" % (d_host,d_port)) 125 | 126 | eventHandler = SessionEventHandler() 127 | 128 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 129 | 130 | if not session.startAsync(): 131 | print ("Failed to start session.") 132 | return 133 | 134 | global bEnd 135 | while bEnd==False: 136 | pass 137 | 138 | session.stop() 139 | 140 | if __name__ == "__main__": 141 | print ("Bloomberg - EMSX API Sell-Side Example - SellSideReject") 142 | try: 143 | main() 144 | except KeyboardInterrupt: 145 | print ("Ctrl+C pressed. Stopping...") 146 | 147 | 148 | __copyright__ = """ 149 | Copyright 2017. Bloomberg Finance L.P. 150 | 151 | Permission is hereby granted, free of charge, to any person obtaining a copy 152 | of this software and associated documentation files (the "Software"), to 153 | deal in the Software without restriction, including without limitation the 154 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 155 | sell copies of the Software, and to permit persons to whom the Software is 156 | furnished to do so, subject to the following conditions: The above 157 | copyright notice and this permission notice shall be included in all copies 158 | or substantial portions of the Software. 159 | 160 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 161 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 162 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 163 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 164 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 165 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 166 | IN THE SOFTWARE. 167 | """ 168 | -------------------------------------------------------------------------------- /EMSXFullSet_Python/CreateBasket.py: -------------------------------------------------------------------------------- 1 | # CreateBasket.py 2 | 3 | import sys 4 | import blpapi 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | CREATE_BASKET = blpapi.Name("CreateBasket") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | class SessionEventHandler(): 20 | 21 | def processEvent(self, event, session): 22 | try: 23 | if event.eventType() == blpapi.Event.SESSION_STATUS: 24 | self.processSessionStatusEvent(event,session) 25 | 26 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 27 | self.processServiceStatusEvent(event,session) 28 | 29 | elif event.eventType() == blpapi.Event.RESPONSE: 30 | self.processResponseEvent(event) 31 | 32 | else: 33 | self.processMiscEvents(event) 34 | 35 | except: 36 | print("Exception: %s" % sys.exc_info()[0]) 37 | 38 | return False 39 | 40 | 41 | def processSessionStatusEvent(self,event,session): 42 | print("Processing SESSION_STATUS event") 43 | 44 | for msg in event: 45 | if msg.messageType() == SESSION_STARTED: 46 | print("Session started...") 47 | session.openServiceAsync(d_service) 48 | 49 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 50 | print("Error: Session startup failed") 51 | 52 | else: 53 | print(msg) 54 | 55 | 56 | def processServiceStatusEvent(self,event,session): 57 | print("Processing SERVICE_STATUS event") 58 | 59 | for msg in event: 60 | 61 | if msg.messageType() == SERVICE_OPENED: 62 | print("Service opened...") 63 | 64 | service = session.getService(d_service) 65 | 66 | request = service.createRequest("CreateBasket") 67 | 68 | # define the basket name 69 | request.set("EMSX_BASKET_NAME", "TestBasket") 70 | 71 | # add any number of orders 72 | request.append("EMSX_SEQUENCE", 4313227) 73 | request.append("EMSX_SEQUENCE", 4313228) 74 | #request.append("EMSX_SEQUENCE", 4313184) 75 | 76 | print("Request: %s" % request.toString()) 77 | 78 | self.requestID = blpapi.CorrelationId() 79 | 80 | session.sendRequest(request, correlationId=self.requestID ) 81 | 82 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 83 | print("Error: Service failed to open") 84 | 85 | 86 | def processResponseEvent(self, event): 87 | print("Processing RESPONSE event") 88 | 89 | for msg in event: 90 | 91 | print("MESSAGE: %s" % msg.toString()) 92 | print("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 93 | 94 | 95 | if msg.correlationIds()[0].value() == self.requestID.value(): 96 | print("MESSAGE TYPE: %s" % msg.messageType()) 97 | 98 | if msg.messageType() == ERROR_INFO: 99 | errorCode = msg.getElementAsInteger("ERROR_CODE") 100 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 101 | print("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 102 | elif msg.messageType() == CREATE_BASKET: 103 | emsx_sequence = msg.getElementAsInteger("EMSX_SEQUENCE") 104 | message = msg.getElementAsString("MESSAGE") 105 | print("EMSX_SEQUENCE: %d\tMESSAGE: %s" % (emsx_sequence,message)) 106 | 107 | global bEnd 108 | bEnd = True 109 | 110 | def processMiscEvents(self, event): 111 | 112 | print("Processing " + event.eventType() + " event") 113 | 114 | for msg in event: 115 | 116 | print("MESSAGE: %s" % (msg.tostring())) 117 | 118 | 119 | def main(): 120 | 121 | sessionOptions = blpapi.SessionOptions() 122 | sessionOptions.setServerHost(d_host) 123 | sessionOptions.setServerPort(d_port) 124 | 125 | print("Connecting to %s:%d" % (d_host,d_port)) 126 | 127 | eventHandler = SessionEventHandler() 128 | 129 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 130 | 131 | if not session.startAsync(): 132 | print("Failed to start session.") 133 | return 134 | 135 | global bEnd 136 | while bEnd==False: 137 | pass 138 | 139 | session.stop() 140 | 141 | if __name__ == "__main__": 142 | print("Bloomberg - EMSX API Example - CreateBasket") 143 | try: 144 | main() 145 | except KeyboardInterrupt: 146 | print("Ctrl+C pressed. Stopping...") 147 | 148 | 149 | __copyright__ = """ 150 | Copyright 2018. Bloomberg Finance L.P. 151 | 152 | Permission is hereby granted, free of charge, to any person obtaining a copy 153 | of this software and associated documentation files (the "Software"), to 154 | deal in the Software without restriction, including without limitation the 155 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 156 | sell copies of the Software, and to permit persons to whom the Software is 157 | furnished to do so, subject to the following conditions: The above 158 | copyright notice and this permission notice shall be included in all copies 159 | or substantial portions of the Software. 160 | 161 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 162 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 163 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 164 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 165 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 166 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 167 | IN THE SOFTWARE. 168 | """ 169 | -------------------------------------------------------------------------------- /EMSXFullSet_Python/GetBrokerStrategiesWithAssetClass.py: -------------------------------------------------------------------------------- 1 | # GetBrokerStrategiesWithAssetClass.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | GET_BROKER_STRATEGIES_WITH_ASSET_CLASS = blpapi.Name("GetBrokerStrategiesWithAssetClass") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | class SessionEventHandler(): 20 | 21 | def processEvent(self, event, session): 22 | try: 23 | if event.eventType() == blpapi.Event.SESSION_STATUS: 24 | self.processSessionStatusEvent(event,session) 25 | 26 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 27 | self.processServiceStatusEvent(event,session) 28 | 29 | elif event.eventType() == blpapi.Event.RESPONSE: 30 | self.processResponseEvent(event) 31 | 32 | else: 33 | self.processMiscEvents(event) 34 | 35 | except: 36 | print ("Exception: %s" % sys.exc_info()[0]) 37 | 38 | return False 39 | 40 | 41 | def processSessionStatusEvent(self,event,session): 42 | print ("Processing SESSION_STATUS event") 43 | 44 | for msg in event: 45 | if msg.messageType() == SESSION_STARTED: 46 | print ("Session started...") 47 | session.openServiceAsync(d_service) 48 | 49 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 50 | print >> sys.stderr, ("Error: Session startup failed") 51 | 52 | else: 53 | print (msg) 54 | 55 | 56 | def processServiceStatusEvent(self,event,session): 57 | print ("Processing SERVICE_STATUS event") 58 | 59 | for msg in event: 60 | 61 | if msg.messageType() == SERVICE_OPENED: 62 | print ("Service opened...") 63 | 64 | service = session.getService(d_service) 65 | 66 | request = service.createRequest("GetBrokerStrategiesWithAssetClass") 67 | 68 | #request.set("EMSX_REQUEST_SEQ", 1) 69 | 70 | request.set("EMSX_ASSET_CLASS","EQTY") # one of EQTY, OPT, FUT or MULTILEG_OPT 71 | request.set("EMSX_BROKER","BMTB") 72 | 73 | print ("Request: %s" % request.toString()) 74 | 75 | self.requestID = blpapi.CorrelationId() 76 | 77 | session.sendRequest(request, correlationId=self.requestID ) 78 | 79 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 80 | print >> sys.stderr, ("Error: Service failed to open") 81 | 82 | def processResponseEvent(self, event): 83 | print ("Processing RESPONSE event") 84 | 85 | for msg in event: 86 | 87 | print ("MESSAGE: %s" % msg.toString()) 88 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 89 | 90 | 91 | if msg.correlationIds()[0].value() == self.requestID.value(): 92 | print ("MESSAGE TYPE: %s" % msg.messageType()) 93 | 94 | if msg.messageType() == ERROR_INFO: 95 | errorCode = msg.getElementAsInteger("ERROR_CODE") 96 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 97 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 98 | elif msg.messageType() == GET_BROKER_STRATEGIES_WITH_ASSET_CLASS: 99 | 100 | strategies = msg.getElement("EMSX_STRATEGIES") 101 | 102 | for s in strategies.values(): 103 | print ("EMSX_STRATEGY: %s" % (s)) 104 | 105 | global bEnd 106 | bEnd = True 107 | 108 | def processMiscEvents(self, event): 109 | 110 | print ("Processing " + event.eventType() + " event") 111 | 112 | for msg in event: 113 | 114 | print ("MESSAGE: %s" % (msg.tostring())) 115 | 116 | 117 | def main(): 118 | 119 | sessionOptions = blpapi.SessionOptions() 120 | sessionOptions.setServerHost(d_host) 121 | sessionOptions.setServerPort(d_port) 122 | 123 | print ("Connecting to %s:%d" % (d_host,d_port)) 124 | 125 | eventHandler = SessionEventHandler() 126 | 127 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 128 | 129 | if not session.startAsync(): 130 | print ("Failed to start session.") 131 | return 132 | 133 | global bEnd 134 | while bEnd==False: 135 | pass 136 | 137 | session.stop() 138 | 139 | if __name__ == "__main__": 140 | print ("Bloomberg - EMSX API Example - GetBrokerStrategiesWithAssetClass") 141 | try: 142 | main() 143 | except KeyboardInterrupt: 144 | print ("Ctrl+C pressed. Stopping...") 145 | 146 | 147 | __copyright__ = """ 148 | Copyright 2017. Bloomberg Finance L.P. 149 | 150 | Permission is hereby granted, free of charge, to any person obtaining a copy 151 | of this software and associated documentation files (the "Software"), to 152 | deal in the Software without restriction, including without limitation the 153 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 154 | sell copies of the Software, and to permit persons to whom the Software is 155 | furnished to do so, subject to the following conditions: The above 156 | copyright notice and this permission notice shall be included in all copies 157 | or substantial portions of the Software. 158 | 159 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 160 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 161 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 162 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 163 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 164 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 165 | IN THE SOFTWARE. 166 | """ 167 | -------------------------------------------------------------------------------- /EMSXFullSet_Python/CancelRoute.py: -------------------------------------------------------------------------------- 1 | # CancelRoute.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | CANCEL_ROUTE = blpapi.Name("CancelRoute") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | class SessionEventHandler(): 20 | 21 | def processEvent(self, event, session): 22 | try: 23 | if event.eventType() == blpapi.Event.SESSION_STATUS: 24 | self.processSessionStatusEvent(event,session) 25 | 26 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 27 | self.processServiceStatusEvent(event,session) 28 | 29 | elif event.eventType() == blpapi.Event.RESPONSE: 30 | self.processResponseEvent(event) 31 | 32 | else: 33 | self.processMiscEvents(event) 34 | 35 | except: 36 | print ("Exception: %s" % sys.exc_info()[0]) 37 | 38 | return False 39 | 40 | 41 | def processSessionStatusEvent(self,event,session): 42 | print ("Processing SESSION_STATUS event") 43 | 44 | for msg in event: 45 | if msg.messageType() == SESSION_STARTED: 46 | print ("Session started...") 47 | session.openServiceAsync(d_service) 48 | 49 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 50 | print >> sys.stderr, ("Error: Session startup failed") 51 | 52 | else: 53 | print (msg) 54 | 55 | 56 | def processServiceStatusEvent(self,event,session): 57 | print ("Processing SERVICE_STATUS event") 58 | 59 | for msg in event: 60 | 61 | if msg.messageType() == SERVICE_OPENED: 62 | print ("Service opened...") 63 | 64 | service = session.getService(d_service) 65 | 66 | request = service.createRequest("CancelRoute") 67 | 68 | #request.set("EMSX_REQUEST_SEQ", 1) 69 | #request.set("EMSX_TRADER_UUID", 1234567) # UUID of trader who owns the order 70 | 71 | routes = request.getElement("ROUTES") 72 | 73 | route = routes.appendElement() 74 | route.getElement("EMSX_SEQUENCE").setValue(4113567) 75 | route.getElement("EMSX_ROUTE_ID").setValue(1) 76 | 77 | print ("Request: %s" % request.toString()) 78 | 79 | self.requestID = blpapi.CorrelationId() 80 | 81 | session.sendRequest(request, correlationId=self.requestID ) 82 | 83 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 84 | print >> sys.stderr, ("Error: Service failed to open") 85 | 86 | def processResponseEvent(self, event): 87 | print ("Processing RESPONSE event") 88 | 89 | for msg in event: 90 | 91 | print ("MESSAGE: %s" % msg.toString()) 92 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 93 | 94 | 95 | if msg.correlationIds()[0].value() == self.requestID.value(): 96 | print ("MESSAGE TYPE: %s" % msg.messageType()) 97 | 98 | if msg.messageType() == ERROR_INFO: 99 | errorCode = msg.getElementAsInteger("ERROR_CODE") 100 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 101 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 102 | elif msg.messageType() == CANCEL_ROUTE: 103 | status = msg.getElementAsInteger("STATUS") 104 | message = msg.getElementAsString("MESSAGE") 105 | print ("STATUS: %d\tMESSAGE: %s" % (status,message)) 106 | 107 | global bEnd 108 | bEnd = True 109 | 110 | def processMiscEvents(self, event): 111 | 112 | print ("Processing " + event.eventType() + " event") 113 | 114 | for msg in event: 115 | 116 | print ("MESSAGE: %s" % (msg.tostring())) 117 | 118 | 119 | def main(): 120 | 121 | sessionOptions = blpapi.SessionOptions() 122 | sessionOptions.setServerHost(d_host) 123 | sessionOptions.setServerPort(d_port) 124 | 125 | print ("Connecting to %s:%d" % (d_host,d_port)) 126 | 127 | eventHandler = SessionEventHandler() 128 | 129 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 130 | 131 | if not session.startAsync(): 132 | print ("Failed to start session.") 133 | return 134 | 135 | global bEnd 136 | while bEnd==False: 137 | pass 138 | 139 | session.stop() 140 | 141 | if __name__ == "__main__": 142 | print ("Bloomberg - EMSX API Example - CancelRoute") 143 | try: 144 | main() 145 | except KeyboardInterrupt: 146 | print ("Ctrl+C pressed. Stopping...") 147 | 148 | 149 | __copyright__ = """ 150 | Copyright 2017. Bloomberg Finance L.P. 151 | 152 | Permission is hereby granted, free of charge, to any person obtaining a copy 153 | of this software and associated documentation files (the "Software"), to 154 | deal in the Software without restriction, including without limitation the 155 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 156 | sell copies of the Software, and to permit persons to whom the Software is 157 | furnished to do so, subject to the following conditions: The above 158 | copyright notice and this permission notice shall be included in all copies 159 | or substantial portions of the Software. 160 | 161 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 162 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 163 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 164 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 165 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 166 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 167 | IN THE SOFTWARE. 168 | """ 169 | -------------------------------------------------------------------------------- /EMSXFullSet_Python/GetAllFieldMetaData.py: -------------------------------------------------------------------------------- 1 | # GetAllFieldMetaData.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | GET_ALL_FIELD_METADATA = blpapi.Name("GetAllFieldMetaData") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | class SessionEventHandler(): 20 | 21 | def processEvent(self, event, session): 22 | try: 23 | if event.eventType() == blpapi.Event.SESSION_STATUS: 24 | self.processSessionStatusEvent(event,session) 25 | 26 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 27 | self.processServiceStatusEvent(event,session) 28 | 29 | elif event.eventType() == blpapi.Event.RESPONSE: 30 | self.processResponseEvent(event) 31 | 32 | else: 33 | self.processMiscEvents(event) 34 | 35 | except: 36 | print ("Exception: %s" % sys.exc_info()[0]) 37 | 38 | return False 39 | 40 | 41 | def processSessionStatusEvent(self,event,session): 42 | print ("Processing SESSION_STATUS event") 43 | 44 | for msg in event: 45 | if msg.messageType() == SESSION_STARTED: 46 | print ("Session started...") 47 | session.openServiceAsync(d_service) 48 | 49 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 50 | print >> sys.stderr, ("Error: Session startup failed") 51 | 52 | else: 53 | print (msg) 54 | 55 | 56 | def processServiceStatusEvent(self,event,session): 57 | print ("Processing SERVICE_STATUS event") 58 | 59 | for msg in event: 60 | 61 | if msg.messageType() == SERVICE_OPENED: 62 | print ("Service opened...") 63 | 64 | service = session.getService(d_service) 65 | 66 | request = service.createRequest("GetAllFieldMetaData") 67 | 68 | #request.set("EMSX_REQUEST_SEQ", 1) 69 | 70 | print ("Request: %s" % request.toString()) 71 | 72 | self.requestID = blpapi.CorrelationId() 73 | 74 | session.sendRequest(request, correlationId=self.requestID ) 75 | 76 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 77 | print >> sys.stderr, ("Error: Service failed to open") 78 | 79 | def processResponseEvent(self, event): 80 | print ("Processing RESPONSE event") 81 | 82 | for msg in event: 83 | 84 | print ("MESSAGE: %s" % msg.toString()) 85 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 86 | 87 | 88 | if msg.correlationIds()[0].value() == self.requestID.value(): 89 | print ("MESSAGE TYPE: %s" % msg.messageType()) 90 | 91 | if msg.messageType() == ERROR_INFO: 92 | errorCode = msg.getElementAsInteger("ERROR_CODE") 93 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 94 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 95 | elif msg.messageType() == GET_ALL_FIELD_METADATA: 96 | 97 | md = msg.getElement("MetaData") 98 | 99 | for e in md.values(): 100 | 101 | emsx_field_name = e.getElementAsString("EMSX_FIELD_NAME") 102 | emsx_disp_name = e.getElementAsString("EMSX_DISP_NAME") 103 | emsx_type = e.getElementAsString("EMSX_TYPE") 104 | emsx_level = e.getElementAsInteger("EMSX_LEVEL") 105 | emsx_len = e.getElementAsInteger("EMSX_LEN") 106 | 107 | print ("MetaData: %s,%s,%s,%d,%d" % (emsx_field_name, emsx_disp_name, emsx_type, emsx_level, emsx_len)) 108 | 109 | global bEnd 110 | bEnd = True 111 | 112 | def processMiscEvents(self, event): 113 | 114 | print ("Processing " + event.eventType() + " event") 115 | 116 | for msg in event: 117 | 118 | print ("MESSAGE: %s" % (msg.tostring())) 119 | 120 | 121 | def main(): 122 | 123 | sessionOptions = blpapi.SessionOptions() 124 | sessionOptions.setServerHost(d_host) 125 | sessionOptions.setServerPort(d_port) 126 | 127 | print ("Connecting to %s:%d" % (d_host,d_port)) 128 | 129 | eventHandler = SessionEventHandler() 130 | 131 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 132 | 133 | if not session.startAsync(): 134 | print ("Failed to start session.") 135 | return 136 | 137 | global bEnd 138 | while bEnd==False: 139 | pass 140 | 141 | session.stop() 142 | 143 | if __name__ == "__main__": 144 | print ("Bloomberg - EMSX API Example - GetAllFieldMetaData") 145 | try: 146 | main() 147 | except KeyboardInterrupt: 148 | print ("Ctrl+C pressed. Stopping...") 149 | 150 | 151 | __copyright__ = """ 152 | Copyright 2017. Bloomberg Finance L.P. 153 | 154 | Permission is hereby granted, free of charge, to any person obtaining a copy 155 | of this software and associated documentation files (the "Software"), to 156 | deal in the Software without restriction, including without limitation the 157 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 158 | sell copies of the Software, and to permit persons to whom the Software is 159 | furnished to do so, subject to the following conditions: The above 160 | copyright notice and this permission notice shall be included in all copies 161 | or substantial portions of the Software. 162 | 163 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 164 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 165 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 166 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 167 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 168 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 169 | IN THE SOFTWARE. 170 | """ 171 | -------------------------------------------------------------------------------- /EMSXFullSet_Python/GetBrokerStrategyInfoWithAssetClass.py: -------------------------------------------------------------------------------- 1 | # GetBrokerStrategyInfoWithAssetClass.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | GET_BROKER_STRATEGY_INFO_WITH_ASSET_CLASS = blpapi.Name("GetBrokerStrategyInfoWithAssetClass") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | class SessionEventHandler(): 20 | 21 | def processEvent(self, event, session): 22 | try: 23 | if event.eventType() == blpapi.Event.SESSION_STATUS: 24 | self.processSessionStatusEvent(event,session) 25 | 26 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 27 | self.processServiceStatusEvent(event,session) 28 | 29 | elif event.eventType() == blpapi.Event.RESPONSE: 30 | self.processResponseEvent(event) 31 | 32 | else: 33 | self.processMiscEvents(event) 34 | 35 | except: 36 | print ("Exception: %s" % sys.exc_info()[0]) 37 | 38 | return False 39 | 40 | 41 | def processSessionStatusEvent(self,event,session): 42 | print ("Processing SESSION_STATUS event") 43 | 44 | for msg in event: 45 | if msg.messageType() == SESSION_STARTED: 46 | print ("Session started...") 47 | session.openServiceAsync(d_service) 48 | 49 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 50 | print >> sys.stderr, ("Error: Session startup failed") 51 | 52 | else: 53 | print (msg) 54 | 55 | 56 | def processServiceStatusEvent(self,event,session): 57 | print ("Processing SERVICE_STATUS event") 58 | 59 | for msg in event: 60 | 61 | if msg.messageType() == SERVICE_OPENED: 62 | print ("Service opened...") 63 | 64 | service = session.getService(d_service) 65 | 66 | request = service.createRequest("GetBrokerStrategyInfoWithAssetClass") 67 | 68 | request.set("EMSX_REQUEST_SEQ", 1) 69 | 70 | request.set("EMSX_ASSET_CLASS","EQTY") # one of EQTY, OPT, FUT or MULTILEG_OPT 71 | request.set("EMSX_BROKER","BMTB") 72 | request.set("EMSX_STRATEGY","VWAP") 73 | 74 | print ("Request: %s" % request.toString()) 75 | 76 | self.requestID = blpapi.CorrelationId() 77 | 78 | session.sendRequest(request, correlationId=self.requestID ) 79 | 80 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 81 | print >> sys.stderr, ("Error: Service failed to open") 82 | 83 | def processResponseEvent(self, event): 84 | print ("Processing RESPONSE event") 85 | 86 | for msg in event: 87 | 88 | print ("MESSAGE: %s" % msg.toString()) 89 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 90 | 91 | 92 | if msg.correlationIds()[0].value() == self.requestID.value(): 93 | print ("MESSAGE TYPE: %s" % msg.messageType()) 94 | 95 | if msg.messageType() == ERROR_INFO: 96 | errorCode = msg.getElementAsInteger("ERROR_CODE") 97 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 98 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 99 | elif msg.messageType() == GET_BROKER_STRATEGY_INFO_WITH_ASSET_CLASS: 100 | 101 | strategies = msg.getElement("EMSX_STRATEGY_INFO") 102 | 103 | for s in strategies.values(): 104 | fieldname = s.getElementAsString("FieldName") 105 | disable = s.getElementAsString("Disable") 106 | stringvalue = s.getElementAsString("StringValue") 107 | 108 | print ("EMSX_STRATEGY_INFO: %s, %s, %s" % (fieldname,disable,stringvalue)) 109 | 110 | global bEnd 111 | bEnd = True 112 | 113 | def processMiscEvents(self, event): 114 | 115 | print ("Processing " + event.eventType() + " event") 116 | 117 | for msg in event: 118 | 119 | print ("MESSAGE: %s" % (msg.tostring())) 120 | 121 | 122 | def main(): 123 | 124 | sessionOptions = blpapi.SessionOptions() 125 | sessionOptions.setServerHost(d_host) 126 | sessionOptions.setServerPort(d_port) 127 | 128 | print ("Connecting to %s:%d" % (d_host,d_port)) 129 | 130 | eventHandler = SessionEventHandler() 131 | 132 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 133 | 134 | if not session.startAsync(): 135 | print ("Failed to start session.") 136 | return 137 | 138 | global bEnd 139 | while bEnd==False: 140 | pass 141 | 142 | session.stop() 143 | 144 | if __name__ == "__main__": 145 | print ("Bloomberg - EMSX API Example - GetBrokerStrategyInfoWithAssetClass") 146 | try: 147 | main() 148 | except KeyboardInterrupt: 149 | print ("Ctrl+C pressed. Stopping...") 150 | 151 | 152 | __copyright__ = """ 153 | Copyright 2017. Bloomberg Finance L.P. 154 | 155 | Permission is hereby granted, free of charge, to any person obtaining a copy 156 | of this software and associated documentation files (the "Software"), to 157 | deal in the Software without restriction, including without limitation the 158 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 159 | sell copies of the Software, and to permit persons to whom the Software is 160 | furnished to do so, subject to the following conditions: The above 161 | copyright notice and this permission notice shall be included in all copies 162 | or substantial portions of the Software. 163 | 164 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 165 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 166 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 167 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 168 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 169 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 170 | IN THE SOFTWARE. 171 | """ 172 | -------------------------------------------------------------------------------- /EMSXFullSet_Python/GetFieldMetaData.py: -------------------------------------------------------------------------------- 1 | # GetFieldMetaData.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | GET_FIELD_METADATA = blpapi.Name("GetFieldMetaData") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | class SessionEventHandler(): 20 | 21 | def processEvent(self, event, session): 22 | try: 23 | if event.eventType() == blpapi.Event.SESSION_STATUS: 24 | self.processSessionStatusEvent(event,session) 25 | 26 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 27 | self.processServiceStatusEvent(event,session) 28 | 29 | elif event.eventType() == blpapi.Event.RESPONSE: 30 | self.processResponseEvent(event) 31 | 32 | else: 33 | self.processMiscEvents(event) 34 | 35 | except: 36 | print ("Exception: %s" % sys.exc_info()[0]) 37 | 38 | return False 39 | 40 | 41 | def processSessionStatusEvent(self,event,session): 42 | print ("Processing SESSION_STATUS event") 43 | 44 | for msg in event: 45 | if msg.messageType() == SESSION_STARTED: 46 | print ("Session started...") 47 | session.openServiceAsync(d_service) 48 | 49 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 50 | print >> sys.stderr, ("Error: Session startup failed") 51 | 52 | else: 53 | print (msg) 54 | 55 | 56 | def processServiceStatusEvent(self,event,session): 57 | print ("Processing SERVICE_STATUS event") 58 | 59 | for msg in event: 60 | 61 | if msg.messageType() == SERVICE_OPENED: 62 | print ("Service opened...") 63 | 64 | service = session.getService(d_service) 65 | 66 | request = service.createRequest("GetFieldMetaData") 67 | 68 | #request.set("EMSX_REQUEST_SEQ", 1) 69 | 70 | request.getElement("EMSX_FIELD_NAMES").appendValue("EMSX_TICKER") 71 | request.getElement("EMSX_FIELD_NAMES").appendValue("EMSX_P_A") 72 | request.getElement("EMSX_FIELD_NAMES").appendValue("EMSX_CLEARING_ACCOUNT") 73 | 74 | print ("Request: %s" % request.toString()) 75 | 76 | self.requestID = blpapi.CorrelationId() 77 | 78 | session.sendRequest(request, correlationId=self.requestID ) 79 | 80 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 81 | print >> sys.stderr, ("Error: Service failed to open") 82 | 83 | def processResponseEvent(self, event): 84 | print ("Processing RESPONSE event") 85 | 86 | for msg in event: 87 | 88 | print ("MESSAGE: %s" % msg.toString()) 89 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 90 | 91 | 92 | if msg.correlationIds()[0].value() == self.requestID.value(): 93 | print ("MESSAGE TYPE: %s" % msg.messageType()) 94 | 95 | if msg.messageType() == ERROR_INFO: 96 | errorCode = msg.getElementAsInteger("ERROR_CODE") 97 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 98 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 99 | elif msg.messageType() == GET_FIELD_METADATA: 100 | 101 | md = msg.getElement("MetaData") 102 | 103 | for e in md.values(): 104 | 105 | emsx_field_name = e.getElementAsString("EMSX_FIELD_NAME") 106 | emsx_disp_name = e.getElementAsString("EMSX_DISP_NAME") 107 | emsx_type = e.getElementAsString("EMSX_TYPE") 108 | emsx_level = e.getElementAsInteger("EMSX_LEVEL") 109 | emsx_len = e.getElementAsInteger("EMSX_LEN") 110 | 111 | print ("MetaData: %s,%s,%s,%d,%d" % (emsx_field_name, emsx_disp_name, emsx_type, emsx_level, emsx_len)) 112 | 113 | global bEnd 114 | bEnd = True 115 | 116 | def processMiscEvents(self, event): 117 | 118 | print ("Processing " + event.eventType() + " event") 119 | 120 | for msg in event: 121 | 122 | print ("MESSAGE: %s" % (msg.tostring())) 123 | 124 | 125 | def main(): 126 | 127 | sessionOptions = blpapi.SessionOptions() 128 | sessionOptions.setServerHost(d_host) 129 | sessionOptions.setServerPort(d_port) 130 | 131 | print ("Connecting to %s:%d" % (d_host,d_port)) 132 | 133 | eventHandler = SessionEventHandler() 134 | 135 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 136 | 137 | if not session.startAsync(): 138 | print ("Failed to start session.") 139 | return 140 | 141 | global bEnd 142 | while bEnd==False: 143 | pass 144 | 145 | session.stop() 146 | 147 | if __name__ == "__main__": 148 | print ("Bloomberg - EMSX API Example - GetFieldMetaData") 149 | try: 150 | main() 151 | except KeyboardInterrupt: 152 | print ("Ctrl+C pressed. Stopping...") 153 | 154 | 155 | __copyright__ = """ 156 | Copyright 2017. Bloomberg Finance L.P. 157 | 158 | Permission is hereby granted, free of charge, to any person obtaining a copy 159 | of this software and associated documentation files (the "Software"), to 160 | deal in the Software without restriction, including without limitation the 161 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 162 | sell copies of the Software, and to permit persons to whom the Software is 163 | furnished to do so, subject to the following conditions: The above 164 | copyright notice and this permission notice shall be included in all copies 165 | or substantial portions of the Software. 166 | 167 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 168 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 169 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 170 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 171 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 172 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 173 | IN THE SOFTWARE. 174 | """ 175 | -------------------------------------------------------------------------------- /EMSXFullSet_Python/ManualFill.py: -------------------------------------------------------------------------------- 1 | # ManualFill.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | MANUAL_FILL = blpapi.Name("ManualFill") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | class SessionEventHandler(): 20 | 21 | def processEvent(self, event, session): 22 | try: 23 | if event.eventType() == blpapi.Event.SESSION_STATUS: 24 | self.processSessionStatusEvent(event,session) 25 | 26 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 27 | self.processServiceStatusEvent(event,session) 28 | 29 | elif event.eventType() == blpapi.Event.RESPONSE: 30 | self.processResponseEvent(event) 31 | 32 | else: 33 | self.processMiscEvents(event) 34 | 35 | except: 36 | print ("Exception: %s" % sys.exc_info()[0]) 37 | 38 | return False 39 | 40 | 41 | def processSessionStatusEvent(self,event,session): 42 | print ("Processing SESSION_STATUS event") 43 | 44 | for msg in event: 45 | if msg.messageType() == SESSION_STARTED: 46 | print ("Session started...") 47 | session.openServiceAsync(d_service) 48 | 49 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 50 | print >> sys.stderr, ("Error: Session startup failed") 51 | 52 | else: 53 | print (msg) 54 | 55 | 56 | def processServiceStatusEvent(self,event,session): 57 | print ("Processing SERVICE_STATUS event") 58 | 59 | for msg in event: 60 | 61 | if msg.messageType() == SERVICE_OPENED: 62 | print ("Service opened...") 63 | 64 | service = session.getService(d_service) 65 | 66 | request = service.createRequest("ManualFill"); 67 | #request.set("EMSX_REQUEST_SEQ", 1) 68 | #request.set("EMSX_TRADER_UUID", 1234567) # Trader UUID 69 | 70 | routeToFill = request.getElement("ROUTE_TO_FILL") 71 | routeToFill.setElement("EMSX_SEQUENCE", 12345) # EMSX_SEQUENCE or Order# from EMSX blotter 72 | routeToFill.setElement("EMSX_ROUTE_ID", 1) 73 | 74 | fills = request.getElement("FILLS") 75 | 76 | fill = fills.appendElement() 77 | 78 | fill.setElement("EMSX_FILL_AMOUNT", 100) 79 | fill.setElement("EMSX_FILL_PRICE", 168.11) 80 | #fill.setElement("EMSX_LAST_MARKET", "XLON") 81 | #fills.setElement("EMSX_INDIA_EXCHANGE","BGL") 82 | fillDateTime = fill.getElement("EMSX_FILL_DATE_TIME") 83 | 84 | legacy = fillDateTime.setChoice("Legacy"); 85 | legacy.setElement("EMSX_FILL_DATE",20171103) 86 | legacy.setElement("EMSX_FILL_TIME",26070) 87 | legacy.setElement("EMSX_FILL_TIME_FORMAT","SecondsFromMidnight") 88 | 89 | print ("Request: %s" % request.toString()) 90 | 91 | self.requestID = blpapi.CorrelationId() 92 | 93 | session.sendRequest(request, correlationId=self.requestID ) 94 | 95 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 96 | print >> sys.stderr, ("Error: Service failed to open") 97 | 98 | def processResponseEvent(self, event): 99 | print ("Processing RESPONSE event") 100 | 101 | for msg in event: 102 | 103 | print ("MESSAGE: %s" % msg.toString()) 104 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 105 | 106 | 107 | if msg.correlationIds()[0].value() == self.requestID.value(): 108 | print ("MESSAGE TYPE: %s" % msg.messageType()) 109 | 110 | if msg.messageType() == ERROR_INFO: 111 | errorCode = msg.getElementAsInteger("ERROR_CODE") 112 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 113 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 114 | elif msg.messageType() == MANUAL_FILL: 115 | fillID = msg.getElementAsInteger("EMSX_FILL_ID") 116 | message = msg.getElementAsString("MESSAGE") 117 | print ("EMSX_FILL_ID: %d\tMESSAGE: %s" % (fillID,message)) 118 | 119 | global bEnd 120 | bEnd = True 121 | 122 | def processMiscEvents(self, event): 123 | 124 | print ("Processing " + event.eventType() + " event") 125 | 126 | for msg in event: 127 | 128 | print ("MESSAGE: %s" % (msg.tostring())) 129 | 130 | 131 | def main(): 132 | 133 | sessionOptions = blpapi.SessionOptions() 134 | sessionOptions.setServerHost(d_host) 135 | sessionOptions.setServerPort(d_port) 136 | 137 | print ("Connecting to %s:%d" % (d_host,d_port)) 138 | 139 | eventHandler = SessionEventHandler() 140 | 141 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 142 | 143 | if not session.startAsync(): 144 | print ("Failed to start session.") 145 | return 146 | 147 | global bEnd 148 | while bEnd==False: 149 | pass 150 | 151 | session.stop() 152 | 153 | if __name__ == "__main__": 154 | print ("Bloomberg - EMSX API Sell-Side Example - ManualFill") 155 | try: 156 | main() 157 | except KeyboardInterrupt: 158 | print ("Ctrl+C pressed. Stopping...") 159 | 160 | 161 | __copyright__ = """ 162 | Copyright 2017. Bloomberg Finance L.P. 163 | 164 | Permission is hereby granted, free of charge, to any person obtaining a copy 165 | of this software and associated documentation files (the "Software"), to 166 | deal in the Software without restriction, including without limitation the 167 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 168 | sell copies of the Software, and to permit persons to whom the Software is 169 | furnished to do so, subject to the following conditions: The above 170 | copyright notice and this permission notice shall be included in all copies 171 | or substantial portions of the Software. 172 | 173 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 174 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 175 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 176 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 177 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 178 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 179 | IN THE SOFTWARE. 180 | """ 181 | -------------------------------------------------------------------------------- /EMSXFullSet_VBA/DeleteOrder.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | END 5 | Attribute VB_Name = "DeleteOrder" 6 | Attribute VB_GlobalNameSpace = False 7 | Attribute VB_Creatable = False 8 | Attribute VB_PredeclaredId = False 9 | Attribute VB_Exposed = False 10 | ' Copyright 2017. Bloomberg Finance L.P. 11 | ' 12 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 13 | ' of this software and associated documentation files (the "Software"), to 14 | ' deal in the Software without restriction, including without limitation the 15 | ' rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16 | ' sell copies of the Software, and to permit persons to whom the Software is 17 | ' furnished to do so, subject to the following conditions: The above 18 | ' copyright notice and this permission notice shall be included in all copies 19 | ' or substantial portions of the Software. 20 | ' 21 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | ' FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | ' IN THE SOFTWARE. 28 | 29 | Option Explicit 30 | 31 | Private WithEvents m_BBG_EMSX As blpapicomLib2.Session 32 | Attribute m_BBG_EMSX.VB_VarHelpID = -1 33 | Public running As Boolean 34 | Private svc As blpapicomLib2.service 35 | Private emsxService As String 36 | Private requestID As blpapicomLib2.CorrelationId 37 | 38 | Private Sub Class_Initialize() 39 | 40 | log "Bloomberg - EMSX API Example - DeleteOrder" 41 | 42 | emsxService = "//blp/emapisvc_beta" 43 | 44 | Set m_BBG_EMSX = New blpapicomLib2.Session 45 | 46 | running = True 47 | 48 | m_BBG_EMSX.QueueEvents = True 49 | m_BBG_EMSX.Start 50 | 51 | 52 | End Sub 53 | 54 | Private Sub Class_Terminate() 55 | Set m_BBG_EMSX = Nothing 56 | End Sub 57 | 58 | Private Sub m_BBG_EMSX_ProcessEvent(ByVal obj As Object) 59 | 60 | On Error GoTo errHandler 61 | 62 | Dim eventObj As blpapicomLib2.Event 63 | 64 | ' Assign the returned data to a Bloomberg type event 65 | Set eventObj = obj 66 | 67 | If Application.Ready Then 68 | 69 | Select Case eventObj.EventType 70 | 71 | Case SESSION_STATUS 72 | processSessionEvent eventObj 73 | 74 | Case BLPSERVICE_STATUS 75 | processServiceEvent eventObj 76 | 77 | Case RESPONSE 78 | processResponseEvent eventObj 79 | 80 | End Select 81 | 82 | End If 83 | 84 | Exit Sub 85 | 86 | errHandler: 87 | Dim errmsg As Variant 88 | errmsg = Err.Description 89 | log (errmsg) 90 | running = False 91 | 92 | End Sub 93 | 94 | 95 | Private Sub processSessionEvent(evt As blpapicomLib2.Event) 96 | 97 | log "Processing SESSION_STATUS event" 98 | 99 | Dim it As blpapicomLib2.MessageIterator 100 | 101 | Set it = evt.CreateMessageIterator() 102 | 103 | ' Loop while we have messages remaining 104 | Do While it.Next() 105 | 106 | Dim msg As Message 107 | 108 | ' Pick up message 109 | Set msg = it.Message 110 | 111 | log "MessageType: " + msg.MessageTypeAsString 112 | 113 | If msg.MessageTypeAsString = "SessionStarted" Then 114 | log "Session started..." 115 | m_BBG_EMSX.OpenService emsxService 116 | ElseIf msg.MessageTypeAsString = "SessionStartupFailure" Then 117 | log "Error: Session startup failed" 118 | running = False 119 | End If 120 | 121 | Loop 122 | 123 | End Sub 124 | 125 | Private Sub processServiceEvent(evt As blpapicomLib2.Event) 126 | 127 | Dim req As REQUEST 128 | Dim service As service 129 | 130 | Dim it As blpapicomLib2.MessageIterator 131 | 132 | On Error GoTo failed 133 | 134 | log "Processing SERVICE_STATUS event" 135 | 136 | Set it = evt.CreateMessageIterator() 137 | 138 | ' Loop while we have messages remaining 139 | Do While it.Next() 140 | 141 | Dim msg As Message 142 | 143 | ' Pick up message 144 | Set msg = it.Message 145 | 146 | log "MessageType: " + msg.MessageTypeAsString 147 | 148 | If msg.MessageTypeAsString = "ServiceOpened" Then 149 | 150 | ' Get the service 151 | Set service = m_BBG_EMSX.GetService(emsxService) 152 | 153 | 'First, create our request object 154 | Set req = service.CreateRequest("DeleteOrder") 155 | 156 | 'req.Set "EMSX_REQUEST_SEQ", 1001 157 | 158 | req.GetElement("EMSX_SEQUENCE").AppendValue 3770185 159 | req.GetElement("EMSX_SEQUENCE").AppendValue 3770187 160 | 161 | log "Request: " & req.Print 162 | 163 | ' Send the request 164 | Set requestID = m_BBG_EMSX.SendRequest(req) 165 | 166 | ElseIf msg.MessageTypeAsString = "ServiceOpenFailure" Then 167 | 168 | log "Error: Service failed to open" 169 | running = False 170 | 171 | End If 172 | 173 | Loop 174 | 175 | Exit Sub 176 | 177 | failed: 178 | 179 | log "Failed to send the request: " + Err.Description 180 | 181 | running = False 182 | Exit Sub 183 | 184 | End Sub 185 | 186 | Private Sub processResponseEvent(evt As blpapicomLib2.Event) 187 | 188 | log "Processing RESPONSE event" 189 | 190 | Dim it As blpapicomLib2.MessageIterator 191 | Dim i As Integer 192 | Dim errorCode As Long 193 | Dim errorMessage As String 194 | 195 | Set it = evt.CreateMessageIterator() 196 | 197 | ' Loop while we have messages remaining 198 | Do While it.Next() 199 | 200 | Dim msg As Message 201 | 202 | ' Pick up message 203 | Set msg = it.Message 204 | 205 | log "MessageType: " + msg.MessageTypeAsString 206 | 207 | If evt.EventType = RESPONSE And msg.CorrelationId.Value = requestID.Value Then 208 | 209 | If msg.MessageTypeAsString = "ErrorInfo" Then 210 | 211 | errorCode = msg.GetElement("ERROR_CODE") 212 | errorMessage = msg.GetElement("ERROR_MESSAGE") 213 | 214 | log "ERROR CODE: " & errorCode & " ERROR DESCRIPTION: " & errorMessage 215 | 216 | running = False 217 | 218 | ElseIf msg.MessageTypeAsString = "DeleteOrder" Then 219 | 220 | Dim stat As Long 221 | Dim msgdesc As String 222 | 223 | stat = msg.GetElement("STATUS") 224 | msgdesc = msg.GetElement("MESSAGE") 225 | 226 | log "STATUS: " & stat & " MESSAGE: " & msgdesc 227 | 228 | m_BBG_EMSX.Stop 229 | running = False 230 | 231 | End If 232 | End If 233 | Loop 234 | 235 | End Sub 236 | 237 | 238 | 239 | -------------------------------------------------------------------------------- /EMSXFullSet_VBA/GetTeams.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | END 5 | Attribute VB_Name = "GetTeams" 6 | Attribute VB_GlobalNameSpace = False 7 | Attribute VB_Creatable = False 8 | Attribute VB_PredeclaredId = False 9 | Attribute VB_Exposed = False 10 | ' Copyright 2017. Bloomberg Finance L.P. 11 | ' 12 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 13 | ' of this software and associated documentation files (the "Software"), to 14 | ' deal in the Software without restriction, including without limitation the 15 | ' rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16 | ' sell copies of the Software, and to permit persons to whom the Software is 17 | ' furnished to do so, subject to the following conditions: The above 18 | ' copyright notice and this permission notice shall be included in all copies 19 | ' or substantial portions of the Software. 20 | ' 21 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | ' FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | ' IN THE SOFTWARE. 28 | 29 | Option Explicit 30 | 31 | Private WithEvents m_BBG_EMSX As blpapicomLib2.Session 32 | Attribute m_BBG_EMSX.VB_VarHelpID = -1 33 | Public running As Boolean 34 | Private svc As blpapicomLib2.service 35 | Private emsxService As String 36 | Private requestID As blpapicomLib2.CorrelationId 37 | 38 | Private Sub Class_Initialize() 39 | 40 | log "Bloomberg - EMSX API Example - GetTeams" 41 | 42 | emsxService = "//blp/emapisvc_beta" 43 | 44 | Set m_BBG_EMSX = New blpapicomLib2.Session 45 | 46 | running = True 47 | 48 | m_BBG_EMSX.QueueEvents = True 49 | m_BBG_EMSX.Start 50 | 51 | 52 | End Sub 53 | 54 | Private Sub Class_Terminate() 55 | Set m_BBG_EMSX = Nothing 56 | End Sub 57 | 58 | Private Sub m_BBG_EMSX_ProcessEvent(ByVal obj As Object) 59 | 60 | On Error GoTo errHandler 61 | 62 | Dim eventObj As blpapicomLib2.Event 63 | 64 | ' Assign the returned data to a Bloomberg type event 65 | Set eventObj = obj 66 | 67 | If Application.Ready Then 68 | 69 | Select Case eventObj.EventType 70 | 71 | Case SESSION_STATUS 72 | processSessionEvent eventObj 73 | 74 | Case BLPSERVICE_STATUS 75 | processServiceEvent eventObj 76 | 77 | Case RESPONSE 78 | processResponseEvent eventObj 79 | 80 | End Select 81 | 82 | End If 83 | 84 | Exit Sub 85 | 86 | errHandler: 87 | Dim errmsg As Variant 88 | errmsg = Err.Description 89 | log (errmsg) 90 | running = False 91 | 92 | End Sub 93 | 94 | 95 | Private Sub processSessionEvent(evt As blpapicomLib2.Event) 96 | 97 | log "Processing SESSION_STATUS event" 98 | 99 | Dim it As blpapicomLib2.MessageIterator 100 | 101 | Set it = evt.CreateMessageIterator() 102 | 103 | ' Loop while we have messages remaining 104 | Do While it.Next() 105 | 106 | Dim msg As Message 107 | 108 | ' Pick up message 109 | Set msg = it.Message 110 | 111 | log "MessageType: " + msg.MessageTypeAsString 112 | 113 | If msg.MessageTypeAsString = "SessionStarted" Then 114 | log "Session started..." 115 | m_BBG_EMSX.OpenService emsxService 116 | ElseIf msg.MessageTypeAsString = "SessionStartupFailure" Then 117 | log "Error: Session startup failed" 118 | running = False 119 | End If 120 | 121 | Loop 122 | 123 | End Sub 124 | 125 | Private Sub processServiceEvent(evt As blpapicomLib2.Event) 126 | 127 | Dim req As REQUEST 128 | Dim service As service 129 | 130 | Dim it As blpapicomLib2.MessageIterator 131 | 132 | On Error GoTo failed 133 | 134 | log "Processing SERVICE_STATUS event" 135 | 136 | Set it = evt.CreateMessageIterator() 137 | 138 | ' Loop while we have messages remaining 139 | Do While it.Next() 140 | 141 | Dim msg As Message 142 | 143 | ' Pick up message 144 | Set msg = it.Message 145 | 146 | log "MessageType: " + msg.MessageTypeAsString 147 | 148 | If msg.MessageTypeAsString = "ServiceOpened" Then 149 | 150 | ' Get the service 151 | Set service = m_BBG_EMSX.GetService(emsxService) 152 | 153 | 'First, create our request object 154 | Set req = service.CreateRequest("GetTeams") 155 | 156 | 'req.Set "EMSX_REQUEST_SEQ", 1001 157 | 158 | log "Request: " & req.Print 159 | 160 | ' Send the request 161 | Set requestID = m_BBG_EMSX.SendRequest(req) 162 | 163 | ElseIf msg.MessageTypeAsString = "ServiceOpenFailure" Then 164 | 165 | log "Error: Service failed to open" 166 | running = False 167 | 168 | End If 169 | 170 | Loop 171 | 172 | Exit Sub 173 | 174 | failed: 175 | 176 | log "Failed to send the request: " + Err.Description 177 | 178 | running = False 179 | Exit Sub 180 | 181 | End Sub 182 | 183 | Private Sub processResponseEvent(evt As blpapicomLib2.Event) 184 | 185 | log "Processing RESPONSE event" 186 | 187 | Dim it As blpapicomLib2.MessageIterator 188 | Dim i As Integer 189 | Dim errorCode As Long 190 | Dim errorMessage As String 191 | 192 | Set it = evt.CreateMessageIterator() 193 | 194 | ' Loop while we have messages remaining 195 | Do While it.Next() 196 | 197 | Dim msg As Message 198 | 199 | ' Pick up message 200 | Set msg = it.Message 201 | 202 | log "MessageType: " + msg.MessageTypeAsString 203 | 204 | If evt.EventType = RESPONSE And msg.CorrelationId.Value = requestID.Value Then 205 | 206 | If msg.MessageTypeAsString = "ErrorInfo" Then 207 | 208 | errorCode = msg.GetElement("ERROR_CODE") 209 | errorMessage = msg.GetElement("ERROR_MESSAGE") 210 | 211 | log "ERROR CODE: " & errorCode & " ERROR DESCRIPTION: " & errorMessage 212 | 213 | running = False 214 | 215 | ElseIf msg.MessageTypeAsString = "GetTeams" Then 216 | 217 | Dim teams As Element 218 | Dim team As String 219 | Dim numValues As Integer 220 | 221 | Set teams = msg.GetElement("TEAMS") 222 | 223 | numValues = teams.numValues 224 | 225 | For i = 0 To numValues - 1 226 | 227 | team = teams.GetValue(i) 228 | 229 | log "Team: " & team 230 | 231 | Next i 232 | 233 | m_BBG_EMSX.Stop 234 | running = False 235 | 236 | End If 237 | End If 238 | Loop 239 | 240 | End Sub 241 | 242 | 243 | 244 | 245 | 246 | -------------------------------------------------------------------------------- /EMSXFullSet_VBA/CreateBasket.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | END 5 | Attribute VB_Name = "CreateBasket" 6 | Attribute VB_GlobalNameSpace = False 7 | Attribute VB_Creatable = False 8 | Attribute VB_PredeclaredId = False 9 | Attribute VB_Exposed = False 10 | ' Copyright 2017. Bloomberg Finance L.P. 11 | ' 12 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 13 | ' of this software and associated documentation files (the "Software"), to 14 | ' deal in the Software without restriction, including without limitation the 15 | ' rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16 | ' sell copies of the Software, and to permit persons to whom the Software is 17 | ' furnished to do so, subject to the following conditions: The above 18 | ' copyright notice and this permission notice shall be included in all copies 19 | ' or substantial portions of the Software. 20 | ' 21 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | ' FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | ' IN THE SOFTWARE. 28 | 29 | Option Explicit 30 | 31 | Private WithEvents m_BBG_EMSX As blpapicomLib2.Session 32 | Attribute m_BBG_EMSX.VB_VarHelpID = -1 33 | Public running As Boolean 34 | Private svc As blpapicomLib2.service 35 | Private emsxService As String 36 | Private requestID As blpapicomLib2.CorrelationId 37 | 38 | Private Sub Class_Initialize() 39 | 40 | log "Bloomberg - EMSX API Example - CreateBasket" 41 | 42 | emsxService = "//blp/emapisvc_beta" 43 | 44 | Set m_BBG_EMSX = New blpapicomLib2.Session 45 | 46 | running = True 47 | 48 | m_BBG_EMSX.QueueEvents = True 49 | m_BBG_EMSX.Start 50 | 51 | 52 | End Sub 53 | 54 | Private Sub Class_Terminate() 55 | Set m_BBG_EMSX = Nothing 56 | End Sub 57 | 58 | Private Sub m_BBG_EMSX_ProcessEvent(ByVal obj As Object) 59 | 60 | On Error GoTo errHandler 61 | 62 | Dim eventObj As blpapicomLib2.Event 63 | 64 | ' Assign the returned data to a Bloomberg type event 65 | Set eventObj = obj 66 | 67 | If Application.Ready Then 68 | 69 | Select Case eventObj.EventType 70 | 71 | Case SESSION_STATUS 72 | processSessionEvent eventObj 73 | 74 | Case BLPSERVICE_STATUS 75 | processServiceEvent eventObj 76 | 77 | Case RESPONSE 78 | processResponseEvent eventObj 79 | 80 | End Select 81 | 82 | End If 83 | 84 | Exit Sub 85 | 86 | errHandler: 87 | Dim errmsg As Variant 88 | errmsg = Err.Description 89 | log (errmsg) 90 | running = False 91 | 92 | End Sub 93 | 94 | 95 | Private Sub processSessionEvent(evt As blpapicomLib2.Event) 96 | 97 | log "Processing SESSION_STATUS event" 98 | 99 | Dim it As blpapicomLib2.MessageIterator 100 | 101 | Set it = evt.CreateMessageIterator() 102 | 103 | ' Loop while we have messages remaining 104 | Do While it.Next() 105 | 106 | Dim msg As Message 107 | 108 | ' Pick up message 109 | Set msg = it.Message 110 | 111 | log "MessageType: " + msg.MessageTypeAsString 112 | 113 | If msg.MessageTypeAsString = "SessionStarted" Then 114 | log "Session started..." 115 | m_BBG_EMSX.OpenService emsxService 116 | ElseIf msg.MessageTypeAsString = "SessionStartupFailure" Then 117 | log "Error: Session startup failed" 118 | running = False 119 | End If 120 | 121 | Loop 122 | 123 | End Sub 124 | 125 | Private Sub processServiceEvent(evt As blpapicomLib2.Event) 126 | 127 | Dim req As REQUEST 128 | Dim service As service 129 | 130 | Dim it As blpapicomLib2.MessageIterator 131 | 132 | On Error GoTo failed 133 | 134 | log "Processing SERVICE_STATUS event" 135 | 136 | Set it = evt.CreateMessageIterator() 137 | 138 | ' Loop while we have messages remaining 139 | Do While it.Next() 140 | 141 | Dim msg As Message 142 | 143 | ' Pick up message 144 | Set msg = it.Message 145 | 146 | log "MessageType: " + msg.MessageTypeAsString 147 | 148 | If msg.MessageTypeAsString = "ServiceOpened" Then 149 | 150 | ' Get the service 151 | Set service = m_BBG_EMSX.GetService(emsxService) 152 | 153 | 'First, create our request object 154 | Set req = service.CreateRequest("CreateBasket") 155 | 156 | 'The fields below are mandatory 157 | req.Set "EMSX_BASKET_NAME", "TestBasket" 158 | 159 | 'Add any number of orders 160 | req.Append "EMSX_SEQUENCE", 4313227 161 | req.Append "EMSX_SEQUENCE", 4313228 162 | 'req.Append "EMSX_SEQUENCE", 3741542 163 | 164 | 165 | log "Request: " & req.Print 166 | 167 | ' Send the request 168 | Set requestID = m_BBG_EMSX.SendRequest(req) 169 | 170 | ElseIf msg.MessageTypeAsString = "ServiceOpenFailure" Then 171 | 172 | log "Error: Service failed to open" 173 | running = False 174 | 175 | End If 176 | 177 | Loop 178 | 179 | Exit Sub 180 | 181 | failed: 182 | 183 | log "Failed to send the request: " + Err.Description 184 | 185 | running = False 186 | Exit Sub 187 | 188 | End Sub 189 | 190 | Private Sub processResponseEvent(evt As blpapicomLib2.Event) 191 | 192 | log "Processing RESPONSE event" 193 | 194 | Dim it As blpapicomLib2.MessageIterator 195 | Dim i As Integer 196 | Dim errorCode As Long 197 | Dim errorMessage As String 198 | 199 | Set it = evt.CreateMessageIterator() 200 | 201 | ' Loop while we have messages remaining 202 | Do While it.Next() 203 | 204 | Dim msg As Message 205 | 206 | ' Pick up message 207 | Set msg = it.Message 208 | 209 | log "MessageType: " + msg.MessageTypeAsString 210 | 211 | If evt.EventType = RESPONSE And msg.CorrelationId.Value = requestID.Value Then 212 | 213 | If msg.MessageTypeAsString = "ErrorInfo" Then 214 | 215 | errorCode = msg.GetElement("ERROR_CODE") 216 | errorMessage = msg.GetElement("ERROR_MESSAGE") 217 | 218 | log "ERROR CODE: " & errorCode & " ERROR DESCRIPTION: " & errorMessage 219 | 220 | running = False 221 | 222 | ElseIf msg.MessageTypeAsString = "CreateOrder" Then 223 | 224 | Dim emsxSequence As Long 225 | Dim msgdesc As String 226 | 227 | emsxSequence = msg.GetElement("EMSX_SEQUENCE") 228 | msgdesc = msg.GetElement("MESSAGE") 229 | 230 | log "EMSX_SEQUENCE: " & emsxSequence & " MESSAGE: " & msgdesc 231 | 232 | m_BBG_EMSX.Stop 233 | running = False 234 | 235 | End If 236 | End If 237 | Loop 238 | 239 | End Sub 240 | 241 | 242 | 243 | 244 | -------------------------------------------------------------------------------- /EMSXFullSet_VBA/CancelRoute.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | END 5 | Attribute VB_Name = "CancelRoute" 6 | Attribute VB_GlobalNameSpace = False 7 | Attribute VB_Creatable = False 8 | Attribute VB_PredeclaredId = False 9 | Attribute VB_Exposed = False 10 | ' Copyright 2017. Bloomberg Finance L.P. 11 | ' 12 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 13 | ' of this software and associated documentation files (the "Software"), to 14 | ' deal in the Software without restriction, including without limitation the 15 | ' rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16 | ' sell copies of the Software, and to permit persons to whom the Software is 17 | ' furnished to do so, subject to the following conditions: The above 18 | ' copyright notice and this permission notice shall be included in all copies 19 | ' or substantial portions of the Software. 20 | ' 21 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | ' FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | ' IN THE SOFTWARE. 28 | 29 | Option Explicit 30 | 31 | Private WithEvents m_BBG_EMSX As blpapicomLib2.Session 32 | Attribute m_BBG_EMSX.VB_VarHelpID = -1 33 | Public running As Boolean 34 | Private svc As blpapicomLib2.service 35 | Private emsxService As String 36 | Private requestID As blpapicomLib2.CorrelationId 37 | 38 | Private Sub Class_Initialize() 39 | 40 | log "Bloomberg - EMSX API Example - CancelRoute" 41 | 42 | emsxService = "//blp/emapisvc_beta" 43 | 44 | Set m_BBG_EMSX = New blpapicomLib2.Session 45 | 46 | running = True 47 | 48 | m_BBG_EMSX.QueueEvents = True 49 | m_BBG_EMSX.Start 50 | 51 | 52 | End Sub 53 | 54 | Private Sub Class_Terminate() 55 | Set m_BBG_EMSX = Nothing 56 | End Sub 57 | 58 | Private Sub m_BBG_EMSX_ProcessEvent(ByVal obj As Object) 59 | 60 | On Error GoTo errHandler 61 | 62 | Dim eventObj As blpapicomLib2.Event 63 | 64 | ' Assign the returned data to a Bloomberg type event 65 | Set eventObj = obj 66 | 67 | If Application.Ready Then 68 | 69 | Select Case eventObj.EventType 70 | 71 | Case SESSION_STATUS 72 | processSessionEvent eventObj 73 | 74 | Case BLPSERVICE_STATUS 75 | processServiceEvent eventObj 76 | 77 | Case RESPONSE 78 | processResponseEvent eventObj 79 | 80 | End Select 81 | 82 | End If 83 | 84 | Exit Sub 85 | 86 | errHandler: 87 | Dim errmsg As Variant 88 | errmsg = Err.Description 89 | log (errmsg) 90 | running = False 91 | 92 | End Sub 93 | 94 | 95 | Private Sub processSessionEvent(evt As blpapicomLib2.Event) 96 | 97 | log "Processing SESSION_STATUS event" 98 | 99 | Dim it As blpapicomLib2.MessageIterator 100 | 101 | Set it = evt.CreateMessageIterator() 102 | 103 | ' Loop while we have messages remaining 104 | Do While it.Next() 105 | 106 | Dim msg As Message 107 | 108 | ' Pick up message 109 | Set msg = it.Message 110 | 111 | log "MessageType: " + msg.MessageTypeAsString 112 | 113 | If msg.MessageTypeAsString = "SessionStarted" Then 114 | log "Session started..." 115 | m_BBG_EMSX.OpenService emsxService 116 | ElseIf msg.MessageTypeAsString = "SessionStartupFailure" Then 117 | log "Error: Session startup failed" 118 | running = False 119 | End If 120 | 121 | Loop 122 | 123 | End Sub 124 | 125 | Private Sub processServiceEvent(evt As blpapicomLib2.Event) 126 | 127 | Dim req As REQUEST 128 | Dim service As service 129 | Dim routes As Element 130 | Dim Route As Element 131 | 132 | Dim it As blpapicomLib2.MessageIterator 133 | 134 | On Error GoTo failed 135 | 136 | log "Processing SERVICE_STATUS event" 137 | 138 | Set it = evt.CreateMessageIterator() 139 | 140 | ' Loop while we have messages remaining 141 | Do While it.Next() 142 | 143 | Dim msg As Message 144 | 145 | ' Pick up message 146 | Set msg = it.Message 147 | 148 | log "MessageType: " + msg.MessageTypeAsString 149 | 150 | If msg.MessageTypeAsString = "ServiceOpened" Then 151 | 152 | ' Get the service 153 | Set service = m_BBG_EMSX.GetService(emsxService) 154 | 155 | 'First, create our request object 156 | Set req = service.CreateRequest("CancelRoute") 157 | 158 | 'req.Set "EMSX_REQUEST_SEQ", 1 159 | 'req.Set "EMSX_TRADER_UUID", 1234567 160 | 161 | Set routes = req.GetElement("ROUTES") 'Note, the case is important 162 | Set Route = routes.AppendElment() 163 | 164 | Route.SetElement "EMSX_SEQUENCE", 3770188 165 | Route.SetElement "EMSX_ROUTE_ID", 1 166 | 167 | log "Request: " & req.Print 168 | 169 | ' Send the request 170 | Set requestID = m_BBG_EMSX.SendRequest(req) 171 | 172 | ElseIf msg.MessageTypeAsString = "ServiceOpenFailure" Then 173 | 174 | log "Error: Service failed to open" 175 | running = False 176 | 177 | End If 178 | 179 | Loop 180 | 181 | Exit Sub 182 | 183 | failed: 184 | 185 | log "Failed to send the request: " + Err.Description 186 | 187 | running = False 188 | Exit Sub 189 | 190 | End Sub 191 | 192 | Private Sub processResponseEvent(evt As blpapicomLib2.Event) 193 | 194 | log "Processing RESPONSE event" 195 | 196 | Dim it As blpapicomLib2.MessageIterator 197 | Dim i As Integer 198 | Dim errorCode As Long 199 | Dim errorMessage As String 200 | 201 | Set it = evt.CreateMessageIterator() 202 | 203 | ' Loop while we have messages remaining 204 | Do While it.Next() 205 | 206 | Dim msg As Message 207 | 208 | ' Pick up message 209 | Set msg = it.Message 210 | 211 | log "MessageType: " + msg.MessageTypeAsString 212 | 213 | If evt.EventType = RESPONSE And msg.CorrelationId.Value = requestID.Value Then 214 | 215 | If msg.MessageTypeAsString = "ErrorInfo" Then 216 | 217 | errorCode = msg.GetElement("ERROR_CODE") 218 | errorMessage = msg.GetElement("ERROR_MESSAGE") 219 | 220 | log "ERROR CODE: " & errorCode & " ERROR DESCRIPTION: " & errorMessage 221 | 222 | running = False 223 | 224 | ElseIf msg.MessageTypeAsString = "CancelRoute" Then 225 | 226 | Dim stat As String 227 | Dim msgdesc As String 228 | 229 | stat = msg.GetElement("STATUS") 230 | msgdesc = msg.GetElement("MESSAGE") 231 | 232 | log "STATUS: " & stat & " MESSAGE: " & msgdesc 233 | 234 | m_BBG_EMSX.Stop 235 | running = False 236 | 237 | End If 238 | End If 239 | Loop 240 | 241 | End Sub 242 | 243 | 244 | 245 | -------------------------------------------------------------------------------- /EMSXFullSet_VBA/SellSideAck.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | END 5 | Attribute VB_Name = "SellSideAck" 6 | Attribute VB_GlobalNameSpace = False 7 | Attribute VB_Creatable = False 8 | Attribute VB_PredeclaredId = False 9 | Attribute VB_Exposed = False 10 | ' Copyright 2017. Bloomberg Finance L.P. 11 | ' 12 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 13 | ' of this software and associated documentation files (the "Software"), to 14 | ' deal in the Software without restriction, including without limitation the 15 | ' rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16 | ' sell copies of the Software, and to permit persons to whom the Software is 17 | ' furnished to do so, subject to the following conditions: The above 18 | ' copyright notice and this permission notice shall be included in all copies 19 | ' or substantial portions of the Software. 20 | ' 21 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | ' FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | ' IN THE SOFTWARE. 28 | 29 | Option Explicit 30 | 31 | Private WithEvents m_BBG_EMSX As blpapicomLib2.Session 32 | Attribute m_BBG_EMSX.VB_VarHelpID = -1 33 | Public running As Boolean 34 | Private svc As blpapicomLib2.service 35 | Private emsxService As String 36 | Private requestID As blpapicomLib2.CorrelationId 37 | 38 | Private Sub Class_Initialize() 39 | 40 | log "Bloomberg - EMSX API Sell-Side Example - SellSideAck" 41 | 42 | emsxService = "//blp/emapisvc_beta" 43 | 44 | Set m_BBG_EMSX = New blpapicomLib2.Session 45 | 46 | running = True 47 | 48 | m_BBG_EMSX.QueueEvents = True 49 | m_BBG_EMSX.Start 50 | 51 | 52 | End Sub 53 | 54 | Private Sub Class_Terminate() 55 | Set m_BBG_EMSX = Nothing 56 | End Sub 57 | 58 | Private Sub m_BBG_EMSX_ProcessEvent(ByVal obj As Object) 59 | 60 | On Error GoTo errHandler 61 | 62 | Dim eventObj As blpapicomLib2.Event 63 | 64 | ' Assign the returned data to a Bloomberg type event 65 | Set eventObj = obj 66 | 67 | If Application.Ready Then 68 | 69 | Select Case eventObj.EventType 70 | 71 | Case SESSION_STATUS 72 | processSessionEvent eventObj 73 | 74 | Case BLPSERVICE_STATUS 75 | processServiceEvent eventObj 76 | 77 | Case RESPONSE 78 | processResponseEvent eventObj 79 | 80 | End Select 81 | 82 | End If 83 | 84 | Exit Sub 85 | 86 | errHandler: 87 | Dim errmsg As Variant 88 | errmsg = Err.Description 89 | log (errmsg) 90 | running = False 91 | 92 | End Sub 93 | 94 | 95 | Private Sub processSessionEvent(evt As blpapicomLib2.Event) 96 | 97 | log "Processing SESSION_STATUS event" 98 | 99 | Dim it As blpapicomLib2.MessageIterator 100 | 101 | Set it = evt.CreateMessageIterator() 102 | 103 | ' Loop while we have messages remaining 104 | Do While it.Next() 105 | 106 | Dim msg As Message 107 | 108 | ' Pick up message 109 | Set msg = it.Message 110 | 111 | log "MessageType: " + msg.MessageTypeAsString 112 | 113 | If msg.MessageTypeAsString = "SessionStarted" Then 114 | log "Session started..." 115 | m_BBG_EMSX.OpenService emsxService 116 | ElseIf msg.MessageTypeAsString = "SessionStartupFailure" Then 117 | log "Error: Session startup failed" 118 | running = False 119 | End If 120 | 121 | Loop 122 | 123 | End Sub 124 | 125 | Private Sub processServiceEvent(evt As blpapicomLib2.Event) 126 | 127 | Dim req As REQUEST 128 | Dim service As service 129 | Dim routes As Element 130 | Dim Route As Element 131 | 132 | Dim it As blpapicomLib2.MessageIterator 133 | 134 | On Error GoTo failed 135 | 136 | log "Processing SERVICE_STATUS event" 137 | 138 | Set it = evt.CreateMessageIterator() 139 | 140 | ' Loop while we have messages remaining 141 | Do While it.Next() 142 | 143 | Dim msg As Message 144 | 145 | ' Pick up message 146 | Set msg = it.Message 147 | 148 | log "MessageType: " + msg.MessageTypeAsString 149 | 150 | If msg.MessageTypeAsString = "ServiceOpened" Then 151 | 152 | ' Get the service 153 | Set service = m_BBG_EMSX.GetService(emsxService) 154 | 155 | 'First, create our request object 156 | Set req = service.CreateRequest("SellSideAck") 157 | 158 | 'req.Set "EMSX_REQUEST_SEQ", 1 159 | 160 | ' Append is used as any number of orders can be ack'ed in a single request 161 | req.Append "EMSX_SEQUENCE", 3852548 162 | 163 | ' If performing the ack on an order owned by another team member, provide owner's UUID 164 | 'req.Set "EMSX_TRADER_UUID", 1234567 165 | 166 | log "Request: " & req.Print 167 | 168 | ' Send the request 169 | Set requestID = m_BBG_EMSX.SendRequest(req) 170 | 171 | ElseIf msg.MessageTypeAsString = "ServiceOpenFailure" Then 172 | 173 | log "Error: Service failed to open" 174 | running = False 175 | 176 | End If 177 | 178 | Loop 179 | 180 | Exit Sub 181 | 182 | failed: 183 | 184 | log "Failed to send the request: " + Err.Description 185 | 186 | running = False 187 | Exit Sub 188 | 189 | End Sub 190 | 191 | Private Sub processResponseEvent(evt As blpapicomLib2.Event) 192 | 193 | log "Processing RESPONSE event" 194 | 195 | Dim it As blpapicomLib2.MessageIterator 196 | Dim i As Integer 197 | Dim errorCode As Long 198 | Dim errorMessage As String 199 | 200 | Set it = evt.CreateMessageIterator() 201 | 202 | ' Loop while we have messages remaining 203 | Do While it.Next() 204 | 205 | Dim msg As Message 206 | 207 | ' Pick up message 208 | Set msg = it.Message 209 | 210 | log "MessageType: " + msg.MessageTypeAsString 211 | 212 | If evt.EventType = RESPONSE And msg.CorrelationId.Value = requestID.Value Then 213 | 214 | If msg.MessageTypeAsString = "ErrorInfo" Then 215 | 216 | errorCode = msg.GetElement("ERROR_CODE") 217 | errorMessage = msg.GetElement("ERROR_MESSAGE") 218 | 219 | log "ERROR CODE: " & errorCode & " ERROR DESCRIPTION: " & errorMessage 220 | 221 | running = False 222 | 223 | ElseIf msg.MessageTypeAsString = "CancelRoute" Then 224 | 225 | Dim stat As String 226 | Dim msgdesc As String 227 | 228 | stat = msg.GetElement("STATUS") 229 | msgdesc = msg.GetElement("MESSAGE") 230 | 231 | log "STATUS: " & stat & " MESSAGE: " & msgdesc 232 | 233 | m_BBG_EMSX.Stop 234 | running = False 235 | 236 | End If 237 | End If 238 | Loop 239 | 240 | End Sub 241 | 242 | 243 | 244 | 245 | -------------------------------------------------------------------------------- /EMSXFullSet_VBA/SellSideReject.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | END 5 | Attribute VB_Name = "SellSideReject" 6 | Attribute VB_GlobalNameSpace = False 7 | Attribute VB_Creatable = False 8 | Attribute VB_PredeclaredId = False 9 | Attribute VB_Exposed = False 10 | ' Copyright 2017. Bloomberg Finance L.P. 11 | ' 12 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 13 | ' of this software and associated documentation files (the "Software"), to 14 | ' deal in the Software without restriction, including without limitation the 15 | ' rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16 | ' sell copies of the Software, and to permit persons to whom the Software is 17 | ' furnished to do so, subject to the following conditions: The above 18 | ' copyright notice and this permission notice shall be included in all copies 19 | ' or substantial portions of the Software. 20 | ' 21 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | ' FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | ' IN THE SOFTWARE. 28 | 29 | Option Explicit 30 | 31 | Private WithEvents m_BBG_EMSX As blpapicomLib2.Session 32 | Attribute m_BBG_EMSX.VB_VarHelpID = -1 33 | Public running As Boolean 34 | Private svc As blpapicomLib2.service 35 | Private emsxService As String 36 | Private requestID As blpapicomLib2.CorrelationId 37 | 38 | Private Sub Class_Initialize() 39 | 40 | log "Bloomberg - EMSX API Sell-Side Example - SellSideReject" 41 | 42 | emsxService = "//blp/emapisvc_beta" 43 | 44 | Set m_BBG_EMSX = New blpapicomLib2.Session 45 | 46 | running = True 47 | 48 | m_BBG_EMSX.QueueEvents = True 49 | m_BBG_EMSX.Start 50 | 51 | 52 | End Sub 53 | 54 | Private Sub Class_Terminate() 55 | Set m_BBG_EMSX = Nothing 56 | End Sub 57 | 58 | Private Sub m_BBG_EMSX_ProcessEvent(ByVal obj As Object) 59 | 60 | On Error GoTo errHandler 61 | 62 | Dim eventObj As blpapicomLib2.Event 63 | 64 | ' Assign the returned data to a Bloomberg type event 65 | Set eventObj = obj 66 | 67 | If Application.Ready Then 68 | 69 | Select Case eventObj.EventType 70 | 71 | Case SESSION_STATUS 72 | processSessionEvent eventObj 73 | 74 | Case BLPSERVICE_STATUS 75 | processServiceEvent eventObj 76 | 77 | Case RESPONSE 78 | processResponseEvent eventObj 79 | 80 | End Select 81 | 82 | End If 83 | 84 | Exit Sub 85 | 86 | errHandler: 87 | Dim errmsg As Variant 88 | errmsg = Err.Description 89 | log (errmsg) 90 | running = False 91 | 92 | End Sub 93 | 94 | 95 | Private Sub processSessionEvent(evt As blpapicomLib2.Event) 96 | 97 | log "Processing SESSION_STATUS event" 98 | 99 | Dim it As blpapicomLib2.MessageIterator 100 | 101 | Set it = evt.CreateMessageIterator() 102 | 103 | ' Loop while we have messages remaining 104 | Do While it.Next() 105 | 106 | Dim msg As Message 107 | 108 | ' Pick up message 109 | Set msg = it.Message 110 | 111 | log "MessageType: " + msg.MessageTypeAsString 112 | 113 | If msg.MessageTypeAsString = "SessionStarted" Then 114 | log "Session started..." 115 | m_BBG_EMSX.OpenService emsxService 116 | ElseIf msg.MessageTypeAsString = "SessionStartupFailure" Then 117 | log "Error: Session startup failed" 118 | running = False 119 | End If 120 | 121 | Loop 122 | 123 | End Sub 124 | 125 | Private Sub processServiceEvent(evt As blpapicomLib2.Event) 126 | 127 | Dim req As REQUEST 128 | Dim service As service 129 | Dim routes As Element 130 | Dim Route As Element 131 | 132 | Dim it As blpapicomLib2.MessageIterator 133 | 134 | On Error GoTo failed 135 | 136 | log "Processing SERVICE_STATUS event" 137 | 138 | Set it = evt.CreateMessageIterator() 139 | 140 | ' Loop while we have messages remaining 141 | Do While it.Next() 142 | 143 | Dim msg As Message 144 | 145 | ' Pick up message 146 | Set msg = it.Message 147 | 148 | log "MessageType: " + msg.MessageTypeAsString 149 | 150 | If msg.MessageTypeAsString = "ServiceOpened" Then 151 | 152 | ' Get the service 153 | Set service = m_BBG_EMSX.GetService(emsxService) 154 | 155 | 'First, create our request object 156 | Set req = service.CreateRequest("SellSideReject") 157 | 158 | 'req.Set "EMSX_REQUEST_SEQ", 1 159 | 160 | ' Append is used as any number of orders can be rejected in a single request 161 | req.Append "EMSX_SEQUENCE", 3852548 162 | 163 | ' If performing the reject on an order owned by another team member, provide owner's UUID 164 | 'req.Set "EMSX_TRADER_UUID", 1234567 165 | 166 | log "Request: " & req.Print 167 | 168 | ' Send the request 169 | Set requestID = m_BBG_EMSX.SendRequest(req) 170 | 171 | ElseIf msg.MessageTypeAsString = "ServiceOpenFailure" Then 172 | 173 | log "Error: Service failed to open" 174 | running = False 175 | 176 | End If 177 | 178 | Loop 179 | 180 | Exit Sub 181 | 182 | failed: 183 | 184 | log "Failed to send the request: " + Err.Description 185 | 186 | running = False 187 | Exit Sub 188 | 189 | End Sub 190 | 191 | Private Sub processResponseEvent(evt As blpapicomLib2.Event) 192 | 193 | log "Processing RESPONSE event" 194 | 195 | Dim it As blpapicomLib2.MessageIterator 196 | Dim i As Integer 197 | Dim errorCode As Long 198 | Dim errorMessage As String 199 | 200 | Set it = evt.CreateMessageIterator() 201 | 202 | ' Loop while we have messages remaining 203 | Do While it.Next() 204 | 205 | Dim msg As Message 206 | 207 | ' Pick up message 208 | Set msg = it.Message 209 | 210 | log "MessageType: " + msg.MessageTypeAsString 211 | 212 | If evt.EventType = RESPONSE And msg.CorrelationId.Value = requestID.Value Then 213 | 214 | If msg.MessageTypeAsString = "ErrorInfo" Then 215 | 216 | errorCode = msg.GetElement("ERROR_CODE") 217 | errorMessage = msg.GetElement("ERROR_MESSAGE") 218 | 219 | log "ERROR CODE: " & errorCode & " ERROR DESCRIPTION: " & errorMessage 220 | 221 | running = False 222 | 223 | ElseIf msg.MessageTypeAsString = "CancelRoute" Then 224 | 225 | Dim stat As String 226 | Dim msgdesc As String 227 | 228 | stat = msg.GetElement("STATUS") 229 | msgdesc = msg.GetElement("MESSAGE") 230 | 231 | log "STATUS: " & stat & " MESSAGE: " & msgdesc 232 | 233 | m_BBG_EMSX.Stop 234 | running = False 235 | 236 | End If 237 | End If 238 | Loop 239 | 240 | End Sub 241 | 242 | 243 | 244 | 245 | 246 | -------------------------------------------------------------------------------- /EMSXFullSet_Python/ModifyOrderEx.py: -------------------------------------------------------------------------------- 1 | # ModifyOrder.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | MODIFY_ORDER_EX = blpapi.Name("ModifyOrderEx") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | 20 | class SessionEventHandler(): 21 | 22 | def processEvent(self, event, session): 23 | try: 24 | if event.eventType() == blpapi.Event.SESSION_STATUS: 25 | self.processSessionStatusEvent(event,session) 26 | 27 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 28 | self.processServiceStatusEvent(event,session) 29 | 30 | elif event.eventType() == blpapi.Event.RESPONSE: 31 | self.processResponseEvent(event) 32 | 33 | else: 34 | self.processMiscEvents(event) 35 | 36 | except: 37 | print ("Exception: %s" % sys.exc_info()[0]) 38 | 39 | return False 40 | 41 | 42 | def processSessionStatusEvent(self,event,session): 43 | print ("Processing SESSION_STATUS event") 44 | 45 | for msg in event: 46 | if msg.messageType() == SESSION_STARTED: 47 | print ("Session started...") 48 | session.openServiceAsync(d_service) 49 | 50 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 51 | print >> sys.stderr, ("Error: Session startup failed") 52 | 53 | else: 54 | print (msg) 55 | 56 | 57 | def processServiceStatusEvent(self,event,session): 58 | print ("Processing SERVICE_STATUS event") 59 | 60 | for msg in event: 61 | 62 | if msg.messageType() == SERVICE_OPENED: 63 | print ("Service opened...") 64 | 65 | service = session.getService(d_service) 66 | 67 | request = service.createRequest("ModifyOrderEx") 68 | 69 | # The fields below are mandatory 70 | request.set("EMSX_SEQUENCE", 4116143) 71 | request.set("EMSX_AMOUNT", 500) 72 | request.set("EMSX_ORDER_TYPE", "MKT") 73 | request.set("EMSX_TIF", "DAY") 74 | request.set("EMSX_TICKER", "CVX US Equity") 75 | 76 | # The fields below are optional 77 | #request.set("EMSX_HAND_INSTRUCTION", "ANY") 78 | #request.set("EMSX_ACCOUNT","TestAccount") 79 | #request.set("EMSX_CFD_FLAG", "1") 80 | #request.set("EMSX_EXEC_INSTRUCTION", "Drop down values from EMSX Ticket") 81 | #request.set("EMSX_GET_WARNINGS", "0") 82 | #request.set("EMSX_GTD_DATE", "20170105") 83 | #request.set("EMSX_INVESTOR_ID", "InvID") 84 | #request.set("EMSX_LIMIT_PRICE", 123.45) 85 | #request.set("EMSX_NOTES", "Some notes") 86 | #request.set("EMSX_REQUEST_SEQ", 1001) 87 | #request.set("EMSX_STOP_PRICE", 123.5) 88 | 89 | # Note: When changing order type to a LMT order, you will need to provide the EMSX_LIMIT_PRICE value. 90 | # When changing order type away from LMT order, you will need to reset the EMSX_LIMIT_PRICE value 91 | # by setting the content to -99999 92 | 93 | # Note: To clear down the stop price, set the content to -1 94 | 95 | # If modifying on behalf of another trader, set the order owner's UUID 96 | #request.set("EMSX_TRADER_UUID", 1234567) 97 | 98 | print ("Request: %s" % request.toString()) 99 | 100 | self.requestID = blpapi.CorrelationId() 101 | 102 | session.sendRequest(request, correlationId=self.requestID ) 103 | 104 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 105 | print >> sys.stderr, ("Error: Service failed to open") 106 | 107 | def processResponseEvent(self, event): 108 | print ("Processing RESPONSE event") 109 | 110 | for msg in event: 111 | 112 | print ("MESSAGE: %s" % msg.toString()) 113 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 114 | 115 | 116 | if msg.correlationIds()[0].value() == self.requestID.value(): 117 | print ("MESSAGE TYPE: %s" % msg.messageType()) 118 | 119 | if msg.messageType() == ERROR_INFO: 120 | errorCode = msg.getElementAsInteger("ERROR_CODE") 121 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 122 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 123 | elif msg.messageType() == MODIFY_ORDER_EX: 124 | emsx_sequence = msg.getElementAsInteger("EMSX_SEQUENCE") 125 | message = msg.getElementAsString("MESSAGE") 126 | print ("EMSX_SEQUENCE: %d\tMESSAGE: %s" % (emsx_sequence,message)) 127 | 128 | global bEnd 129 | bEnd = True 130 | 131 | def processMiscEvents(self, event): 132 | 133 | print ("Processing " + event.eventType() + " event") 134 | 135 | for msg in event: 136 | 137 | print ("MESSAGE: %s" % (msg.tostring())) 138 | 139 | 140 | def main(): 141 | 142 | sessionOptions = blpapi.SessionOptions() 143 | sessionOptions.setServerHost(d_host) 144 | sessionOptions.setServerPort(d_port) 145 | 146 | print ("Connecting to %s:%d" % (d_host,d_port)) 147 | 148 | eventHandler = SessionEventHandler() 149 | 150 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 151 | 152 | if not session.startAsync(): 153 | print ("Failed to start session.") 154 | return 155 | 156 | global bEnd 157 | while bEnd==False: 158 | pass 159 | 160 | session.stop() 161 | 162 | if __name__ == "__main__": 163 | print ("Bloomberg - EMSX API Example - ModifyOrderEx") 164 | try: 165 | main() 166 | except KeyboardInterrupt: 167 | print ("Ctrl+C pressed. Stopping...") 168 | 169 | 170 | __copyright__ = """ 171 | Copyright 2017. Bloomberg Finance L.P. 172 | 173 | Permission is hereby granted, free of charge, to any person obtaining a copy 174 | of this software and associated documentation files (the "Software"), to 175 | deal in the Software without restriction, including without limitation the 176 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 177 | sell copies of the Software, and to permit persons to whom the Software is 178 | furnished to do so, subject to the following conditions: The above 179 | copyright notice and this permission notice shall be included in all copies 180 | or substantial portions of the Software. 181 | 182 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 183 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 184 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 185 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 186 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 187 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 188 | IN THE SOFTWARE. 189 | """ 190 | -------------------------------------------------------------------------------- /EMSXFullSet_VBA/GetBrokersWithAssetClass.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | END 5 | Attribute VB_Name = "GetBrokersWithAssetClass" 6 | Attribute VB_GlobalNameSpace = False 7 | Attribute VB_Creatable = False 8 | Attribute VB_PredeclaredId = False 9 | Attribute VB_Exposed = False 10 | ' Copyright 2017. Bloomberg Finance L.P. 11 | ' 12 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 13 | ' of this software and associated documentation files (the "Software"), to 14 | ' deal in the Software without restriction, including without limitation the 15 | ' rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16 | ' sell copies of the Software, and to permit persons to whom the Software is 17 | ' furnished to do so, subject to the following conditions: The above 18 | ' copyright notice and this permission notice shall be included in all copies 19 | ' or substantial portions of the Software. 20 | ' 21 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | ' FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | ' IN THE SOFTWARE. 28 | 29 | Option Explicit 30 | 31 | Private WithEvents m_BBG_EMSX As blpapicomLib2.Session 32 | Attribute m_BBG_EMSX.VB_VarHelpID = -1 33 | Public running As Boolean 34 | Private svc As blpapicomLib2.service 35 | Private emsxService As String 36 | Private requestID As blpapicomLib2.CorrelationId 37 | 38 | Private Sub Class_Initialize() 39 | 40 | log "Bloomberg - EMSX API Example - GetBrokersWithAssetClass" 41 | 42 | emsxService = "//blp/emapisvc_beta" 43 | 44 | Set m_BBG_EMSX = New blpapicomLib2.Session 45 | 46 | running = True 47 | 48 | m_BBG_EMSX.QueueEvents = True 49 | m_BBG_EMSX.Start 50 | 51 | 52 | End Sub 53 | 54 | Private Sub Class_Terminate() 55 | Set m_BBG_EMSX = Nothing 56 | End Sub 57 | 58 | Private Sub m_BBG_EMSX_ProcessEvent(ByVal obj As Object) 59 | 60 | On Error GoTo errHandler 61 | 62 | Dim eventObj As blpapicomLib2.Event 63 | 64 | ' Assign the returned data to a Bloomberg type event 65 | Set eventObj = obj 66 | 67 | If Application.Ready Then 68 | 69 | Select Case eventObj.EventType 70 | 71 | Case SESSION_STATUS 72 | processSessionEvent eventObj 73 | 74 | Case BLPSERVICE_STATUS 75 | processServiceEvent eventObj 76 | 77 | Case RESPONSE 78 | processResponseEvent eventObj 79 | 80 | End Select 81 | 82 | End If 83 | 84 | Exit Sub 85 | 86 | errHandler: 87 | Dim errmsg As Variant 88 | errmsg = Err.Description 89 | log (errmsg) 90 | running = False 91 | 92 | End Sub 93 | 94 | 95 | Private Sub processSessionEvent(evt As blpapicomLib2.Event) 96 | 97 | log "Processing SESSION_STATUS event" 98 | 99 | Dim it As blpapicomLib2.MessageIterator 100 | 101 | Set it = evt.CreateMessageIterator() 102 | 103 | ' Loop while we have messages remaining 104 | Do While it.Next() 105 | 106 | Dim msg As Message 107 | 108 | ' Pick up message 109 | Set msg = it.Message 110 | 111 | log "MessageType: " + msg.MessageTypeAsString 112 | 113 | If msg.MessageTypeAsString = "SessionStarted" Then 114 | log "Session started..." 115 | m_BBG_EMSX.OpenService emsxService 116 | ElseIf msg.MessageTypeAsString = "SessionStartupFailure" Then 117 | log "Error: Session startup failed" 118 | running = False 119 | End If 120 | 121 | Loop 122 | 123 | End Sub 124 | 125 | Private Sub processServiceEvent(evt As blpapicomLib2.Event) 126 | 127 | Dim req As REQUEST 128 | Dim service As service 129 | 130 | Dim it As blpapicomLib2.MessageIterator 131 | 132 | On Error GoTo failed 133 | 134 | log "Processing SERVICE_STATUS event" 135 | 136 | Set it = evt.CreateMessageIterator() 137 | 138 | ' Loop while we have messages remaining 139 | Do While it.Next() 140 | 141 | Dim msg As Message 142 | 143 | ' Pick up message 144 | Set msg = it.Message 145 | 146 | log "MessageType: " + msg.MessageTypeAsString 147 | 148 | If msg.MessageTypeAsString = "ServiceOpened" Then 149 | 150 | ' Get the service 151 | Set service = m_BBG_EMSX.GetService(emsxService) 152 | 153 | 'First, create our request object 154 | Set req = service.CreateRequest("GetBrokersWithAssetClass") 155 | 156 | 'req.Set "EMSX_REQUEST_SEQ", 1001 157 | 158 | req.Set "EMSX_ASSET_CLASS", "EQTY" 'one of EQTY, OPT, FUT or MULTILEG_OPT 159 | 160 | log "Request: " & req.Print 161 | 162 | ' Send the request 163 | Set requestID = m_BBG_EMSX.SendRequest(req) 164 | 165 | ElseIf msg.MessageTypeAsString = "ServiceOpenFailure" Then 166 | 167 | log "Error: Service failed to open" 168 | running = False 169 | 170 | End If 171 | 172 | Loop 173 | 174 | Exit Sub 175 | 176 | failed: 177 | 178 | log "Failed to send the request: " + Err.Description 179 | 180 | running = False 181 | Exit Sub 182 | 183 | End Sub 184 | 185 | Private Sub processResponseEvent(evt As blpapicomLib2.Event) 186 | 187 | log "Processing RESPONSE event" 188 | 189 | Dim it As blpapicomLib2.MessageIterator 190 | Dim i As Integer 191 | Dim errorCode As Long 192 | Dim errorMessage As String 193 | 194 | Set it = evt.CreateMessageIterator() 195 | 196 | ' Loop while we have messages remaining 197 | Do While it.Next() 198 | 199 | Dim msg As Message 200 | 201 | ' Pick up message 202 | Set msg = it.Message 203 | 204 | log "MessageType: " + msg.MessageTypeAsString 205 | 206 | If evt.EventType = RESPONSE And msg.CorrelationId.Value = requestID.Value Then 207 | 208 | If msg.MessageTypeAsString = "ErrorInfo" Then 209 | 210 | errorCode = msg.GetElement("ERROR_CODE") 211 | errorMessage = msg.GetElement("ERROR_MESSAGE") 212 | 213 | log "ERROR CODE: " & errorCode & " ERROR DESCRIPTION: " & errorMessage 214 | 215 | running = False 216 | 217 | ElseIf msg.MessageTypeAsString = "GetBrokersWithAssetClass" Then 218 | 219 | Dim brokers As Element 220 | Dim broker As String 221 | Dim numValues As Integer 222 | 223 | Set brokers = msg.GetElement("EMSX_BROKERS") 224 | 225 | numValues = brokers.numValues 226 | 227 | For i = 0 To numValues - 1 228 | 229 | broker = brokers.GetValue(i) 230 | 231 | log "Broker: " & broker 232 | 233 | Next i 234 | 235 | m_BBG_EMSX.Stop 236 | running = False 237 | 238 | End If 239 | End If 240 | Loop 241 | 242 | End Sub 243 | 244 | 245 | 246 | 247 | 248 | 249 | -------------------------------------------------------------------------------- /EMSXFullSet_Python/AssignTrader.py: -------------------------------------------------------------------------------- 1 | # AssignTrader.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | ASSIGN_TRADER = blpapi.Name("AssignTrader") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | class SessionEventHandler(): 20 | 21 | def processEvent(self, event, session): 22 | try: 23 | if event.eventType() == blpapi.Event.SESSION_STATUS: 24 | self.processSessionStatusEvent(event,session) 25 | 26 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 27 | self.processServiceStatusEvent(event,session) 28 | 29 | elif event.eventType() == blpapi.Event.RESPONSE: 30 | self.processResponseEvent(event) 31 | 32 | else: 33 | self.processMiscEvents(event) 34 | 35 | except: 36 | print ("Exception: %s" % sys.exc_info()[0]) 37 | 38 | return False 39 | 40 | 41 | def processSessionStatusEvent(self,event,session): 42 | print ("Processing SESSION_STATUS event") 43 | 44 | for msg in event: 45 | if msg.messageType() == SESSION_STARTED: 46 | print ("Session started...") 47 | session.openServiceAsync(d_service) 48 | 49 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 50 | print >> sys.stderr, ("Error: Session startup failed") 51 | 52 | else: 53 | print (msg) 54 | 55 | 56 | def processServiceStatusEvent(self,event,session): 57 | print ("Processing SERVICE_STATUS event") 58 | 59 | for msg in event: 60 | 61 | if msg.messageType() == SERVICE_OPENED: 62 | print ("Service opened...") 63 | 64 | service = session.getService(d_service) 65 | 66 | request = service.createRequest("AssignTrader") 67 | 68 | request.append("EMSX_SEQUENCE", 5062768) #This is the EMSX_SEQUENCE or Order# from EMSX blotter 69 | #request.append("EMSX_SEQUENCE", 5062767) 70 | 71 | request.set("EMSX_ASSIGNEE_TRADER_UUID", 7569479) #This is the new UUID 72 | 73 | print ("Request: %s" % request.toString()) 74 | 75 | self.requestID = blpapi.CorrelationId() 76 | 77 | session.sendRequest(request, correlationId=self.requestID ) 78 | 79 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 80 | print >> sys.stderr, ("Error: Service failed to open") 81 | 82 | def processResponseEvent(self, event): 83 | print ("Processing RESPONSE event") 84 | 85 | for msg in event: 86 | 87 | print ("MESSAGE: %s" % msg.toString()) 88 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 89 | 90 | 91 | if msg.correlationIds()[0].value() == self.requestID.value(): 92 | print ("MESSAGE TYPE: %s" % msg.messageType()) 93 | 94 | if msg.messageType() == ERROR_INFO: 95 | errorCode = msg.getElementAsInteger("ERROR_CODE") 96 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 97 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 98 | elif msg.messageType() == ASSIGN_TRADER: 99 | success = msg.getElementAsBool("EMSX_ALL_SUCCESS") 100 | if success: 101 | print ("All orders successfully assigned") 102 | successful = msg.getElement("EMSX_ASSIGN_TRADER_SUCCESSFUL_ORDERS") 103 | 104 | if successful.numValues() > 0: print ("Successful assignments:-") 105 | 106 | for order in successful.values(): 107 | seq = order.getElement("EMSX_SEQUENCE").getValue() 108 | print (seq) 109 | 110 | else: 111 | print ("One or more failed assignments...\n") 112 | 113 | if msg.hasElement("EMSX_ASSIGN_TRADER_SUCCESSFUL_ORDERS"): 114 | successful = msg.getElement("EMSX_ASSIGN_TRADER_SUCCESSFUL_ORDERS") 115 | 116 | if successful.numValues() > 0: print ("Successful assignments:-") 117 | 118 | for order in successful.values(): 119 | seq = order.getElement("EMSX_SEQUENCE").getValue() 120 | print (seq) 121 | 122 | 123 | if msg.hasElement("EMSX_ASSIGN_TRADER_FAILED_ORDERS"): 124 | failed = msg.getElement("EMSX_ASSIGN_TRADER_FAILED_ORDERS") 125 | 126 | if failed.numValues() > 0: print ("Failed assignments:-") 127 | 128 | for order in failed.values(): 129 | seq = order.getElement("EMSX_SEQUENCE").getValue() 130 | print (seq) 131 | 132 | global bEnd 133 | bEnd = True 134 | 135 | def processMiscEvents(self, event): 136 | 137 | print ("Processing " + event.eventType() + " event") 138 | 139 | for msg in event: 140 | 141 | print ("MESSAGE: %s" % (msg.tostring())) 142 | 143 | 144 | def main(): 145 | 146 | sessionOptions = blpapi.SessionOptions() 147 | sessionOptions.setServerHost(d_host) 148 | sessionOptions.setServerPort(d_port) 149 | 150 | print ("Connecting to %s:%d" % (d_host,d_port)) 151 | 152 | eventHandler = SessionEventHandler() 153 | 154 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 155 | 156 | if not session.startAsync(): 157 | print ("Failed to start session.") 158 | return 159 | 160 | global bEnd 161 | while bEnd==False: 162 | pass 163 | 164 | session.stop() 165 | 166 | if __name__ == "__main__": 167 | print ("Bloomberg - EMSX API Example - AssignTrader") 168 | try: 169 | main() 170 | except KeyboardInterrupt: 171 | print ("Ctrl+C pressed. Stopping...") 172 | 173 | 174 | __copyright__ = """ 175 | Copyright 2017. Bloomberg Finance L.P. 176 | 177 | Permission is hereby granted, free of charge, to any person obtaining a copy 178 | of this software and associated documentation files (the "Software"), to 179 | deal in the Software without restriction, including without limitation the 180 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 181 | sell copies of the Software, and to permit persons to whom the Software is 182 | furnished to do so, subject to the following conditions: The above 183 | copyright notice and this permission notice shall be included in all copies 184 | or substantial portions of the Software. 185 | 186 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 187 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 188 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 189 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 190 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 191 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 192 | IN THE SOFTWARE. 193 | """ 194 | -------------------------------------------------------------------------------- /EMSXFullSet_VBA/GetBrokerStrategiesWithAssetClass.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | END 5 | Attribute VB_Name = "GetBrokerStrategiesWithAssetCls" 6 | Attribute VB_GlobalNameSpace = False 7 | Attribute VB_Creatable = False 8 | Attribute VB_PredeclaredId = False 9 | Attribute VB_Exposed = False 10 | ' Copyright 2017. Bloomberg Finance L.P. 11 | ' 12 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 13 | ' of this software and associated documentation files (the "Software"), to 14 | ' deal in the Software without restriction, including without limitation the 15 | ' rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16 | ' sell copies of the Software, and to permit persons to whom the Software is 17 | ' furnished to do so, subject to the following conditions: The above 18 | ' copyright notice and this permission notice shall be included in all copies 19 | ' or substantial portions of the Software. 20 | ' 21 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | ' FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | ' IN THE SOFTWARE. 28 | 29 | Option Explicit 30 | 31 | Private WithEvents m_BBG_EMSX As blpapicomLib2.Session 32 | Attribute m_BBG_EMSX.VB_VarHelpID = -1 33 | Public running As Boolean 34 | Private svc As blpapicomLib2.service 35 | Private emsxService As String 36 | Private requestID As blpapicomLib2.CorrelationId 37 | 38 | Private Sub Class_Initialize() 39 | 40 | log "Bloomberg - EMSX API Example - GetBrokerStrategiesWithAssetClass" 41 | 42 | emsxService = "//blp/emapisvc_beta" 43 | 44 | Set m_BBG_EMSX = New blpapicomLib2.Session 45 | 46 | running = True 47 | 48 | m_BBG_EMSX.QueueEvents = True 49 | m_BBG_EMSX.Start 50 | 51 | 52 | End Sub 53 | 54 | Private Sub Class_Terminate() 55 | Set m_BBG_EMSX = Nothing 56 | End Sub 57 | 58 | Private Sub m_BBG_EMSX_ProcessEvent(ByVal obj As Object) 59 | 60 | On Error GoTo errHandler 61 | 62 | Dim eventObj As blpapicomLib2.Event 63 | 64 | ' Assign the returned data to a Bloomberg type event 65 | Set eventObj = obj 66 | 67 | If Application.Ready Then 68 | 69 | Select Case eventObj.EventType 70 | 71 | Case SESSION_STATUS 72 | processSessionEvent eventObj 73 | 74 | Case BLPSERVICE_STATUS 75 | processServiceEvent eventObj 76 | 77 | Case RESPONSE 78 | processResponseEvent eventObj 79 | 80 | End Select 81 | 82 | End If 83 | 84 | Exit Sub 85 | 86 | errHandler: 87 | Dim errmsg As Variant 88 | errmsg = Err.Description 89 | log (errmsg) 90 | running = False 91 | 92 | End Sub 93 | 94 | 95 | Private Sub processSessionEvent(evt As blpapicomLib2.Event) 96 | 97 | log "Processing SESSION_STATUS event" 98 | 99 | Dim it As blpapicomLib2.MessageIterator 100 | 101 | Set it = evt.CreateMessageIterator() 102 | 103 | ' Loop while we have messages remaining 104 | Do While it.Next() 105 | 106 | Dim msg As Message 107 | 108 | ' Pick up message 109 | Set msg = it.Message 110 | 111 | log "MessageType: " + msg.MessageTypeAsString 112 | 113 | If msg.MessageTypeAsString = "SessionStarted" Then 114 | log "Session started..." 115 | m_BBG_EMSX.OpenService emsxService 116 | ElseIf msg.MessageTypeAsString = "SessionStartupFailure" Then 117 | log "Error: Session startup failed" 118 | running = False 119 | End If 120 | 121 | Loop 122 | 123 | End Sub 124 | 125 | Private Sub processServiceEvent(evt As blpapicomLib2.Event) 126 | 127 | Dim req As REQUEST 128 | Dim service As service 129 | 130 | Dim it As blpapicomLib2.MessageIterator 131 | 132 | On Error GoTo failed 133 | 134 | log "Processing SERVICE_STATUS event" 135 | 136 | Set it = evt.CreateMessageIterator() 137 | 138 | ' Loop while we have messages remaining 139 | Do While it.Next() 140 | 141 | Dim msg As Message 142 | 143 | ' Pick up message 144 | Set msg = it.Message 145 | 146 | log "MessageType: " + msg.MessageTypeAsString 147 | 148 | If msg.MessageTypeAsString = "ServiceOpened" Then 149 | 150 | ' Get the service 151 | Set service = m_BBG_EMSX.GetService(emsxService) 152 | 153 | 'First, create our request object 154 | Set req = service.CreateRequest("GetBrokerStrategiesWithAssetClass") 155 | 156 | 'req.Set "EMSX_REQUEST_SEQ", 1001 157 | 158 | req.Set "EMSX_ASSET_CLASS", "EQTY" 'one of EQTY, OPT, FUT or MULTILEG_OPT 159 | req.Set "EMSX_BROKER", "BMTB" 160 | 161 | log "Request: " & req.Print 162 | 163 | ' Send the request 164 | Set requestID = m_BBG_EMSX.SendRequest(req) 165 | 166 | ElseIf msg.MessageTypeAsString = "ServiceOpenFailure" Then 167 | 168 | log "Error: Service failed to open" 169 | running = False 170 | 171 | End If 172 | 173 | Loop 174 | 175 | Exit Sub 176 | 177 | failed: 178 | 179 | log "Failed to send the request: " + Err.Description 180 | 181 | running = False 182 | Exit Sub 183 | 184 | End Sub 185 | 186 | Private Sub processResponseEvent(evt As blpapicomLib2.Event) 187 | 188 | log "Processing RESPONSE event" 189 | 190 | Dim it As blpapicomLib2.MessageIterator 191 | Dim i As Integer 192 | Dim errorCode As Long 193 | Dim errorMessage As String 194 | 195 | Set it = evt.CreateMessageIterator() 196 | 197 | ' Loop while we have messages remaining 198 | Do While it.Next() 199 | 200 | Dim msg As Message 201 | 202 | ' Pick up message 203 | Set msg = it.Message 204 | 205 | log "MessageType: " + msg.MessageTypeAsString 206 | 207 | If evt.EventType = RESPONSE And msg.CorrelationId.Value = requestID.Value Then 208 | 209 | If msg.MessageTypeAsString = "ErrorInfo" Then 210 | 211 | errorCode = msg.GetElement("ERROR_CODE") 212 | errorMessage = msg.GetElement("ERROR_MESSAGE") 213 | 214 | log "ERROR CODE: " & errorCode & " ERROR DESCRIPTION: " & errorMessage 215 | 216 | running = False 217 | 218 | ElseIf msg.MessageTypeAsString = "GetBrokerStrategiesWithAssetClass" Then 219 | 220 | Dim strategies As Element 221 | Dim strategy As String 222 | Dim numValues As Integer 223 | 224 | Set strategies = msg.GetElement("EMSX_STRATEGIES") 225 | 226 | numValues = strategies.numValues 227 | 228 | log "Number of strategies: " & numValues 229 | 230 | For i = 0 To numValues - 1 231 | 232 | strategy = strategies.GetValue(i) 233 | log "Strategy: " & strategy 234 | 235 | Next i 236 | 237 | m_BBG_EMSX.Stop 238 | running = False 239 | 240 | End If 241 | End If 242 | Loop 243 | 244 | End Sub 245 | 246 | 247 | 248 | 249 | 250 | -------------------------------------------------------------------------------- /EMSXFullSet_Python/CreateOrderAndRouteManually.py: -------------------------------------------------------------------------------- 1 | # CreateOrderAndRouteManually.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | CREATE_ORDER_AND_ROUTE_MANUALLY = blpapi.Name("CreateOrderAndRouteManually") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | class SessionEventHandler(): 20 | 21 | def processEvent(self, event, session): 22 | try: 23 | if event.eventType() == blpapi.Event.SESSION_STATUS: 24 | self.processSessionStatusEvent(event,session) 25 | 26 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 27 | self.processServiceStatusEvent(event,session) 28 | 29 | elif event.eventType() == blpapi.Event.RESPONSE: 30 | self.processResponseEvent(event) 31 | 32 | else: 33 | self.processMiscEvents(event) 34 | 35 | except: 36 | print ("Exception: %s" % sys.exc_info()[0]) 37 | 38 | return False 39 | 40 | 41 | def processSessionStatusEvent(self,event,session): 42 | print ("Processing SESSION_STATUS event") 43 | 44 | for msg in event: 45 | if msg.messageType() == SESSION_STARTED: 46 | print ("Session started...") 47 | session.openServiceAsync(d_service) 48 | 49 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 50 | print >> sys.stderr, ("Error: Session startup failed") 51 | 52 | else: 53 | print (msg) 54 | 55 | 56 | def processServiceStatusEvent(self,event,session): 57 | print ("Processing SERVICE_STATUS event") 58 | 59 | for msg in event: 60 | 61 | if msg.messageType() == SERVICE_OPENED: 62 | print ("Service opened...") 63 | 64 | service = session.getService(d_service) 65 | 66 | request = service.createRequest("CreateOrderAndRouteManually") 67 | 68 | # The fields below are mandatory 69 | request.set("EMSX_TICKER", "TSLA US Equity") 70 | request.set("EMSX_AMOUNT", 1000) 71 | request.set("EMSX_ORDER_TYPE", "MKT") 72 | request.set("EMSX_TIF", "DAY") 73 | request.set("EMSX_HAND_INSTRUCTION", "ANY") 74 | request.set("EMSX_SIDE", "SELL") 75 | request.set("EMSX_BROKER", "BB") 76 | 77 | # The fields below are optional 78 | #request.set("EMSX_ACCOUNT","TestAccount") 79 | #request.set("EMSX_CFD_FLAG", "1") 80 | #request.set("EMSX_CLEARING_ACCOUNT", "ClrAccName") 81 | #request.set("EMSX_CLEARING_FIRM", "FirmName") 82 | #request.set("EMSX_EXCHANGE_DESTINATION", "ExchDest") 83 | #request.set("EMSX_EXEC_INSTRUCTION", "Drop down values from EMSX Ticket") 84 | #request.set("EMSX_GET_WARNINGS", "0") 85 | #request.set("EMSX_GTD_DATE", "20170105") 86 | #request.set("EMSX_INVESTOR_ID", "InvID") 87 | #request.set("EMSX_LIMIT_PRICE", 123.45) 88 | #request.set("EMSX_LOCATE_BROKER", "BMTB") 89 | #request.set("EMSX_LOCATE_ID", "SomeID") 90 | #request.set("EMSX_LOCATE_REQ", "Y") 91 | #request.set("EMSX_NOTES", "Some notes") 92 | #request.set("EMSX_ODD_LOT", "0") 93 | #request.set("EMSX_ORDER_ORIGIN", "") 94 | #request.set("EMSX_ORDER_REF_ID", "UniqueID") 95 | #request.set("EMSX_P_A", "P") 96 | #request.set("EMSX_RELEASE_TIME", 34341) 97 | #request.set("EMSX_REQUEST_SEQ", 1001) 98 | #request.set("EMSX_SETTLE_DATE", 20170106) 99 | #request.set("EMSX_STOP_PRICE", 123.5) 100 | 101 | print ("Request: %s" % request.toString()) 102 | 103 | self.requestID = blpapi.CorrelationId() 104 | 105 | session.sendRequest(request, correlationId=self.requestID ) 106 | 107 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 108 | print >> sys.stderr, ("Error: Service failed to open") 109 | 110 | def processResponseEvent(self, event): 111 | print ("Processing RESPONSE event") 112 | 113 | for msg in event: 114 | 115 | print ("MESSAGE: %s" % msg.toString()) 116 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 117 | 118 | 119 | if msg.correlationIds()[0].value() == self.requestID.value(): 120 | print ("MESSAGE TYPE: %s" % msg.messageType()) 121 | 122 | if msg.messageType() == ERROR_INFO: 123 | errorCode = msg.getElementAsInteger("ERROR_CODE") 124 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 125 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 126 | elif msg.messageType() == CREATE_ORDER_AND_ROUTE_MANUALLY: 127 | emsx_sequence = msg.getElementAsInteger("EMSX_SEQUENCE") 128 | emsx_route_id = msg.getElementAsInteger("EMSX_ROUTE_ID") 129 | message = msg.getElementAsString("MESSAGE") 130 | print ("EMSX_SEQUENCE: %d\tEMSX_ROUTE_ID: %d\tMESSAGE: %s" % (emsx_sequence,emsx_route_id,message)) 131 | 132 | global bEnd 133 | bEnd = True 134 | 135 | def processMiscEvents(self, event): 136 | 137 | print ("Processing " + event.eventType() + " event") 138 | 139 | for msg in event: 140 | 141 | print ("MESSAGE: %s" % (msg.tostring())) 142 | 143 | 144 | def main(): 145 | 146 | sessionOptions = blpapi.SessionOptions() 147 | sessionOptions.setServerHost(d_host) 148 | sessionOptions.setServerPort(d_port) 149 | 150 | print ("Connecting to %s:%d" % (d_host,d_port)) 151 | 152 | eventHandler = SessionEventHandler() 153 | 154 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 155 | 156 | if not session.startAsync(): 157 | print ("Failed to start session.") 158 | return 159 | 160 | global bEnd 161 | while bEnd==False: 162 | pass 163 | 164 | session.stop() 165 | 166 | if __name__ == "__main__": 167 | print ("Bloomberg - EMSX API Example - CreateOrderAndRouteManually") 168 | try: 169 | main() 170 | except KeyboardInterrupt: 171 | print ("Ctrl+C pressed. Stopping...") 172 | 173 | 174 | __copyright__ = """ 175 | Copyright 2017. Bloomberg Finance L.P. 176 | 177 | Permission is hereby granted, free of charge, to any person obtaining a copy 178 | of this software and associated documentation files (the "Software"), to 179 | deal in the Software without restriction, including without limitation the 180 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 181 | sell copies of the Software, and to permit persons to whom the Software is 182 | furnished to do so, subject to the following conditions: The above 183 | copyright notice and this permission notice shall be included in all copies 184 | or substantial portions of the Software. 185 | 186 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 187 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 188 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 189 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 190 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 191 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 192 | IN THE SOFTWARE. 193 | """ 194 | -------------------------------------------------------------------------------- /EMSXFullSet_VBA/GetAllFieldMetaData.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | END 5 | Attribute VB_Name = "GetAllFieldMetaData" 6 | Attribute VB_GlobalNameSpace = False 7 | Attribute VB_Creatable = False 8 | Attribute VB_PredeclaredId = False 9 | Attribute VB_Exposed = False 10 | ' Copyright 2017. Bloomberg Finance L.P. 11 | ' 12 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 13 | ' of this software and associated documentation files (the "Software"), to 14 | ' deal in the Software without restriction, including without limitation the 15 | ' rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16 | ' sell copies of the Software, and to permit persons to whom the Software is 17 | ' furnished to do so, subject to the following conditions: The above 18 | ' copyright notice and this permission notice shall be included in all copies 19 | ' or substantial portions of the Software. 20 | ' 21 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | ' FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | ' IN THE SOFTWARE. 28 | 29 | Option Explicit 30 | 31 | Private WithEvents m_BBG_EMSX As blpapicomLib2.Session 32 | Attribute m_BBG_EMSX.VB_VarHelpID = -1 33 | Public running As Boolean 34 | Private svc As blpapicomLib2.service 35 | Private emsxService As String 36 | Private requestID As blpapicomLib2.CorrelationId 37 | 38 | Private Sub Class_Initialize() 39 | 40 | log "Bloomberg - EMSX API Example - GetAllFieldMetaData" 41 | 42 | emsxService = "//blp/emapisvc_beta" 43 | 44 | Set m_BBG_EMSX = New blpapicomLib2.Session 45 | 46 | running = True 47 | 48 | m_BBG_EMSX.QueueEvents = True 49 | m_BBG_EMSX.Start 50 | 51 | 52 | End Sub 53 | 54 | Private Sub Class_Terminate() 55 | Set m_BBG_EMSX = Nothing 56 | End Sub 57 | 58 | Private Sub m_BBG_EMSX_ProcessEvent(ByVal obj As Object) 59 | 60 | On Error GoTo errHandler 61 | 62 | Dim eventObj As blpapicomLib2.Event 63 | 64 | ' Assign the returned data to a Bloomberg type event 65 | Set eventObj = obj 66 | 67 | If Application.Ready Then 68 | 69 | Select Case eventObj.EventType 70 | 71 | Case SESSION_STATUS 72 | processSessionEvent eventObj 73 | 74 | Case BLPSERVICE_STATUS 75 | processServiceEvent eventObj 76 | 77 | Case RESPONSE 78 | processResponseEvent eventObj 79 | 80 | End Select 81 | 82 | End If 83 | 84 | Exit Sub 85 | 86 | errHandler: 87 | Dim errmsg As Variant 88 | errmsg = Err.Description 89 | log (errmsg) 90 | running = False 91 | 92 | End Sub 93 | 94 | 95 | Private Sub processSessionEvent(evt As blpapicomLib2.Event) 96 | 97 | log "Processing SESSION_STATUS event" 98 | 99 | Dim it As blpapicomLib2.MessageIterator 100 | 101 | Set it = evt.CreateMessageIterator() 102 | 103 | ' Loop while we have messages remaining 104 | Do While it.Next() 105 | 106 | Dim msg As Message 107 | 108 | ' Pick up message 109 | Set msg = it.Message 110 | 111 | log "MessageType: " + msg.MessageTypeAsString 112 | 113 | If msg.MessageTypeAsString = "SessionStarted" Then 114 | log "Session started..." 115 | m_BBG_EMSX.OpenService emsxService 116 | ElseIf msg.MessageTypeAsString = "SessionStartupFailure" Then 117 | log "Error: Session startup failed" 118 | running = False 119 | End If 120 | 121 | Loop 122 | 123 | End Sub 124 | 125 | Private Sub processServiceEvent(evt As blpapicomLib2.Event) 126 | 127 | Dim req As REQUEST 128 | Dim service As service 129 | 130 | Dim it As blpapicomLib2.MessageIterator 131 | 132 | On Error GoTo failed 133 | 134 | log "Processing SERVICE_STATUS event" 135 | 136 | Set it = evt.CreateMessageIterator() 137 | 138 | ' Loop while we have messages remaining 139 | Do While it.Next() 140 | 141 | Dim msg As Message 142 | 143 | ' Pick up message 144 | Set msg = it.Message 145 | 146 | log "MessageType: " + msg.MessageTypeAsString 147 | 148 | If msg.MessageTypeAsString = "ServiceOpened" Then 149 | 150 | ' Get the service 151 | Set service = m_BBG_EMSX.GetService(emsxService) 152 | 153 | 'First, create our request object 154 | Set req = service.CreateRequest("GetAllFieldMetaData") 155 | 156 | 'req.Set "EMSX_REQUEST_SEQ", 1001 157 | 158 | log "Request: " & req.Print 159 | 160 | ' Send the request 161 | Set requestID = m_BBG_EMSX.SendRequest(req) 162 | 163 | ElseIf msg.MessageTypeAsString = "ServiceOpenFailure" Then 164 | 165 | log "Error: Service failed to open" 166 | running = False 167 | 168 | End If 169 | 170 | Loop 171 | 172 | Exit Sub 173 | 174 | failed: 175 | 176 | log "Failed to send the request: " + Err.Description 177 | 178 | running = False 179 | Exit Sub 180 | 181 | End Sub 182 | 183 | Private Sub processResponseEvent(evt As blpapicomLib2.Event) 184 | 185 | log "Processing RESPONSE event" 186 | 187 | Dim it As blpapicomLib2.MessageIterator 188 | Dim i As Integer 189 | Dim errorCode As Long 190 | Dim errorMessage As String 191 | 192 | Set it = evt.CreateMessageIterator() 193 | 194 | ' Loop while we have messages remaining 195 | Do While it.Next() 196 | 197 | Dim msg As Message 198 | 199 | ' Pick up message 200 | Set msg = it.Message 201 | 202 | log "MessageType: " + msg.MessageTypeAsString 203 | 204 | If evt.EventType = RESPONSE And msg.CorrelationId.Value = requestID.Value Then 205 | 206 | If msg.MessageTypeAsString = "ErrorInfo" Then 207 | 208 | errorCode = msg.GetElement("ERROR_CODE") 209 | errorMessage = msg.GetElement("ERROR_MESSAGE") 210 | 211 | log "ERROR CODE: " & errorCode & " ERROR DESCRIPTION: " & errorMessage 212 | 213 | running = False 214 | 215 | ElseIf msg.MessageTypeAsString = "GetAllFieldMetaData" Then 216 | 217 | Dim md As Element 218 | Dim e As Element 219 | Dim numValues As Integer 220 | Dim emsxFieldName As String 221 | Dim emsxDispName As String 222 | Dim emsxType As String 223 | Dim emsxLevel As Integer 224 | Dim emsxLen As Integer 225 | 226 | Set md = msg.GetElement("MetaData") 227 | 228 | numValues = md.numValues 229 | 230 | For i = 0 To numValues - 1 231 | 232 | Set e = md.GetValueAsElement(i) 233 | 234 | emsxFieldName = e.GetElement("EMSX_FIELD_NAME") 235 | emsxDispName = e.GetElement("EMSX_DISP_NAME") 236 | emsxType = e.GetElement("EMSX_TYPE") 237 | emsxLevel = e.GetElement("EMSX_LEVEL") 238 | emsxLen = e.GetElement("EMSX_LEN") 239 | 240 | log "MetaData: " & emsxFieldName & ", " & emsxDispName & ", " & emsxType & ", " & emsxLevel & ", " & emsxLen 241 | 242 | Next i 243 | 244 | m_BBG_EMSX.Stop 245 | running = False 246 | 247 | End If 248 | End If 249 | Loop 250 | 251 | End Sub 252 | 253 | 254 | 255 | 256 | -------------------------------------------------------------------------------- /EMSXFullSet_VBA/GetBrokerStrategyInfoWithAssetClass.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | END 5 | Attribute VB_Name = "GetBrokerStrategyInfoWithAstCls" 6 | Attribute VB_GlobalNameSpace = False 7 | Attribute VB_Creatable = False 8 | Attribute VB_PredeclaredId = False 9 | Attribute VB_Exposed = False 10 | ' Copyright 2017. Bloomberg Finance L.P. 11 | ' 12 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 13 | ' of this software and associated documentation files (the "Software"), to 14 | ' deal in the Software without restriction, including without limitation the 15 | ' rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16 | ' sell copies of the Software, and to permit persons to whom the Software is 17 | ' furnished to do so, subject to the following conditions: The above 18 | ' copyright notice and this permission notice shall be included in all copies 19 | ' or substantial portions of the Software. 20 | ' 21 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | ' FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | ' IN THE SOFTWARE. 28 | 29 | Option Explicit 30 | 31 | Private WithEvents m_BBG_EMSX As blpapicomLib2.Session 32 | Attribute m_BBG_EMSX.VB_VarHelpID = -1 33 | Public running As Boolean 34 | Private svc As blpapicomLib2.service 35 | Private emsxService As String 36 | Private requestID As blpapicomLib2.CorrelationId 37 | 38 | Private Sub Class_Initialize() 39 | 40 | log "Bloomberg - EMSX API Example - GetBrokerStrategyInfoWithAssetClass" 41 | 42 | emsxService = "//blp/emapisvc_beta" 43 | 44 | Set m_BBG_EMSX = New blpapicomLib2.Session 45 | 46 | running = True 47 | 48 | m_BBG_EMSX.QueueEvents = True 49 | m_BBG_EMSX.Start 50 | 51 | 52 | End Sub 53 | 54 | Private Sub Class_Terminate() 55 | Set m_BBG_EMSX = Nothing 56 | End Sub 57 | 58 | Private Sub m_BBG_EMSX_ProcessEvent(ByVal obj As Object) 59 | 60 | On Error GoTo errHandler 61 | 62 | Dim eventObj As blpapicomLib2.Event 63 | 64 | ' Assign the returned data to a Bloomberg type event 65 | Set eventObj = obj 66 | 67 | If Application.Ready Then 68 | 69 | Select Case eventObj.EventType 70 | 71 | Case SESSION_STATUS 72 | processSessionEvent eventObj 73 | 74 | Case BLPSERVICE_STATUS 75 | processServiceEvent eventObj 76 | 77 | Case RESPONSE 78 | processResponseEvent eventObj 79 | 80 | End Select 81 | 82 | End If 83 | 84 | Exit Sub 85 | 86 | errHandler: 87 | Dim errmsg As Variant 88 | errmsg = Err.Description 89 | log (errmsg) 90 | running = False 91 | 92 | End Sub 93 | 94 | 95 | Private Sub processSessionEvent(evt As blpapicomLib2.Event) 96 | 97 | log "Processing SESSION_STATUS event" 98 | 99 | Dim it As blpapicomLib2.MessageIterator 100 | 101 | Set it = evt.CreateMessageIterator() 102 | 103 | ' Loop while we have messages remaining 104 | Do While it.Next() 105 | 106 | Dim msg As Message 107 | 108 | ' Pick up message 109 | Set msg = it.Message 110 | 111 | log "MessageType: " + msg.MessageTypeAsString 112 | 113 | If msg.MessageTypeAsString = "SessionStarted" Then 114 | log "Session started..." 115 | m_BBG_EMSX.OpenService emsxService 116 | ElseIf msg.MessageTypeAsString = "SessionStartupFailure" Then 117 | log "Error: Session startup failed" 118 | running = False 119 | End If 120 | 121 | Loop 122 | 123 | End Sub 124 | 125 | Private Sub processServiceEvent(evt As blpapicomLib2.Event) 126 | 127 | Dim req As REQUEST 128 | Dim service As service 129 | 130 | Dim it As blpapicomLib2.MessageIterator 131 | 132 | On Error GoTo failed 133 | 134 | log "Processing SERVICE_STATUS event" 135 | 136 | Set it = evt.CreateMessageIterator() 137 | 138 | ' Loop while we have messages remaining 139 | Do While it.Next() 140 | 141 | Dim msg As Message 142 | 143 | ' Pick up message 144 | Set msg = it.Message 145 | 146 | log "MessageType: " + msg.MessageTypeAsString 147 | 148 | If msg.MessageTypeAsString = "ServiceOpened" Then 149 | 150 | ' Get the service 151 | Set service = m_BBG_EMSX.GetService(emsxService) 152 | 153 | 'First, create our request object 154 | Set req = service.CreateRequest("GetBrokerStrategyInfoWithAssetClass") 155 | 156 | 'req.Set "EMSX_REQUEST_SEQ", 1001 157 | 158 | req.Set "EMSX_ASSET_CLASS", "EQTY" 'one of EQTY, OPT, FUT or MULTILEG_OPT 159 | req.Set "EMSX_BROKER", "BMTB" 160 | req.Set "EMSX_STRATEGY", "VWAP" 161 | 162 | log "Request: " & req.Print 163 | 164 | ' Send the request 165 | Set requestID = m_BBG_EMSX.SendRequest(req) 166 | 167 | ElseIf msg.MessageTypeAsString = "ServiceOpenFailure" Then 168 | 169 | log "Error: Service failed to open" 170 | running = False 171 | 172 | End If 173 | 174 | Loop 175 | 176 | Exit Sub 177 | 178 | failed: 179 | 180 | log "Failed to send the request: " + Err.Description 181 | 182 | running = False 183 | Exit Sub 184 | 185 | End Sub 186 | 187 | Private Sub processResponseEvent(evt As blpapicomLib2.Event) 188 | 189 | log "Processing RESPONSE event" 190 | 191 | Dim it As blpapicomLib2.MessageIterator 192 | Dim i As Integer 193 | Dim errorCode As Long 194 | Dim errorMessage As String 195 | 196 | Set it = evt.CreateMessageIterator() 197 | 198 | ' Loop while we have messages remaining 199 | Do While it.Next() 200 | 201 | Dim msg As Message 202 | 203 | ' Pick up message 204 | Set msg = it.Message 205 | 206 | log "MessageType: " + msg.MessageTypeAsString 207 | 208 | If evt.EventType = RESPONSE And msg.CorrelationId.Value = requestID.Value Then 209 | 210 | If msg.MessageTypeAsString = "ErrorInfo" Then 211 | 212 | errorCode = msg.GetElement("ERROR_CODE") 213 | errorMessage = msg.GetElement("ERROR_MESSAGE") 214 | 215 | log "ERROR CODE: " & errorCode & " ERROR DESCRIPTION: " & errorMessage 216 | 217 | running = False 218 | 219 | ElseIf msg.MessageTypeAsString = "GetBrokerStrategyInfoWithAssetClass" Then 220 | 221 | Dim strategies As Element 222 | Dim e As Element 223 | Dim numValues As Integer 224 | Dim fieldName As String 225 | Dim disable As String 226 | Dim stringValue As String 227 | 228 | Set strategies = msg.GetElement("EMSX_STRATEGY_INFO") 229 | 230 | numValues = strategies.numValues 231 | 232 | log "Number of strategies: " & numValues 233 | 234 | For i = 0 To numValues - 1 235 | 236 | Set e = strategies.GetValue(i) 237 | 238 | fieldName = e.GetElement("FieldName") 239 | disable = e.GetElement("Disable") 240 | stringValue = e.GetElement("StringValue") 241 | 242 | log "Strategy Info: " & fieldName & ", " & disable & ", " & stringValue 243 | 244 | Next i 245 | 246 | m_BBG_EMSX.Stop 247 | running = False 248 | 249 | End If 250 | End If 251 | Loop 252 | 253 | End Sub 254 | 255 | 256 | 257 | 258 | 259 | 260 | -------------------------------------------------------------------------------- /EMSXFullSet_VBA/GetFieldMetaData.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | END 5 | Attribute VB_Name = "GetFieldMetaData" 6 | Attribute VB_GlobalNameSpace = False 7 | Attribute VB_Creatable = False 8 | Attribute VB_PredeclaredId = False 9 | Attribute VB_Exposed = False 10 | ' Copyright 2017. Bloomberg Finance L.P. 11 | ' 12 | ' Permission is hereby granted, free of charge, to any person obtaining a copy 13 | ' of this software and associated documentation files (the "Software"), to 14 | ' deal in the Software without restriction, including without limitation the 15 | ' rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16 | ' sell copies of the Software, and to permit persons to whom the Software is 17 | ' furnished to do so, subject to the following conditions: The above 18 | ' copyright notice and this permission notice shall be included in all copies 19 | ' or substantial portions of the Software. 20 | ' 21 | ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | ' FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 | ' IN THE SOFTWARE. 28 | 29 | Option Explicit 30 | 31 | Private WithEvents m_BBG_EMSX As blpapicomLib2.Session 32 | Attribute m_BBG_EMSX.VB_VarHelpID = -1 33 | Public running As Boolean 34 | Private svc As blpapicomLib2.service 35 | Private emsxService As String 36 | Private requestID As blpapicomLib2.CorrelationId 37 | 38 | Private Sub Class_Initialize() 39 | 40 | log "Bloomberg - EMSX API Example - GetFieldMetaData" 41 | 42 | emsxService = "//blp/emapisvc_beta" 43 | 44 | Set m_BBG_EMSX = New blpapicomLib2.Session 45 | 46 | running = True 47 | 48 | m_BBG_EMSX.QueueEvents = True 49 | m_BBG_EMSX.Start 50 | 51 | 52 | End Sub 53 | 54 | Private Sub Class_Terminate() 55 | Set m_BBG_EMSX = Nothing 56 | End Sub 57 | 58 | Private Sub m_BBG_EMSX_ProcessEvent(ByVal obj As Object) 59 | 60 | On Error GoTo errHandler 61 | 62 | Dim eventObj As blpapicomLib2.Event 63 | 64 | ' Assign the returned data to a Bloomberg type event 65 | Set eventObj = obj 66 | 67 | If Application.Ready Then 68 | 69 | Select Case eventObj.EventType 70 | 71 | Case SESSION_STATUS 72 | processSessionEvent eventObj 73 | 74 | Case BLPSERVICE_STATUS 75 | processServiceEvent eventObj 76 | 77 | Case RESPONSE 78 | processResponseEvent eventObj 79 | 80 | End Select 81 | 82 | End If 83 | 84 | Exit Sub 85 | 86 | errHandler: 87 | Dim errmsg As Variant 88 | errmsg = Err.Description 89 | log (errmsg) 90 | running = False 91 | 92 | End Sub 93 | 94 | 95 | Private Sub processSessionEvent(evt As blpapicomLib2.Event) 96 | 97 | log "Processing SESSION_STATUS event" 98 | 99 | Dim it As blpapicomLib2.MessageIterator 100 | 101 | Set it = evt.CreateMessageIterator() 102 | 103 | ' Loop while we have messages remaining 104 | Do While it.Next() 105 | 106 | Dim msg As Message 107 | 108 | ' Pick up message 109 | Set msg = it.Message 110 | 111 | log "MessageType: " + msg.MessageTypeAsString 112 | 113 | If msg.MessageTypeAsString = "SessionStarted" Then 114 | log "Session started..." 115 | m_BBG_EMSX.OpenService emsxService 116 | ElseIf msg.MessageTypeAsString = "SessionStartupFailure" Then 117 | log "Error: Session startup failed" 118 | running = False 119 | End If 120 | 121 | Loop 122 | 123 | End Sub 124 | 125 | Private Sub processServiceEvent(evt As blpapicomLib2.Event) 126 | 127 | Dim req As REQUEST 128 | Dim service As service 129 | 130 | Dim it As blpapicomLib2.MessageIterator 131 | 132 | On Error GoTo failed 133 | 134 | log "Processing SERVICE_STATUS event" 135 | 136 | Set it = evt.CreateMessageIterator() 137 | 138 | ' Loop while we have messages remaining 139 | Do While it.Next() 140 | 141 | Dim msg As Message 142 | 143 | ' Pick up message 144 | Set msg = it.Message 145 | 146 | log "MessageType: " + msg.MessageTypeAsString 147 | 148 | If msg.MessageTypeAsString = "ServiceOpened" Then 149 | 150 | ' Get the service 151 | Set service = m_BBG_EMSX.GetService(emsxService) 152 | 153 | 'First, create our request object 154 | Set req = service.CreateRequest("GetFieldMetaData") 155 | 156 | 'req.Set "EMSX_REQUEST_SEQ", 1001 157 | 158 | req.GetElement("EMSX_FIELD_NAMES").AppendValue "EMSX_TICKER" 159 | req.GetElement("EMSX_FIELD_NAMES").AppendValue "EMSX_P_A" 160 | 161 | log "Request: " & req.Print 162 | 163 | ' Send the request 164 | Set requestID = m_BBG_EMSX.SendRequest(req) 165 | 166 | ElseIf msg.MessageTypeAsString = "ServiceOpenFailure" Then 167 | 168 | log "Error: Service failed to open" 169 | running = False 170 | 171 | End If 172 | 173 | Loop 174 | 175 | Exit Sub 176 | 177 | failed: 178 | 179 | log "Failed to send the request: " + Err.Description 180 | 181 | running = False 182 | Exit Sub 183 | 184 | End Sub 185 | 186 | Private Sub processResponseEvent(evt As blpapicomLib2.Event) 187 | 188 | log "Processing RESPONSE event" 189 | 190 | Dim it As blpapicomLib2.MessageIterator 191 | Dim i As Integer 192 | Dim errorCode As Long 193 | Dim errorMessage As String 194 | 195 | Set it = evt.CreateMessageIterator() 196 | 197 | ' Loop while we have messages remaining 198 | Do While it.Next() 199 | 200 | Dim msg As Message 201 | 202 | ' Pick up message 203 | Set msg = it.Message 204 | 205 | log "MessageType: " + msg.MessageTypeAsString 206 | 207 | If evt.EventType = RESPONSE And msg.CorrelationId.Value = requestID.Value Then 208 | 209 | If msg.MessageTypeAsString = "ErrorInfo" Then 210 | 211 | errorCode = msg.GetElement("ERROR_CODE") 212 | errorMessage = msg.GetElement("ERROR_MESSAGE") 213 | 214 | log "ERROR CODE: " & errorCode & " ERROR DESCRIPTION: " & errorMessage 215 | 216 | running = False 217 | 218 | ElseIf msg.MessageTypeAsString = "GetFieldMetaData" Then 219 | 220 | Dim md As Element 221 | Dim e As Element 222 | Dim numValues As Integer 223 | Dim emsxFieldName As String 224 | Dim emsxDispName As String 225 | Dim emsxType As String 226 | Dim emsxLevel As Integer 227 | Dim emsxLen As Integer 228 | 229 | Set md = msg.GetElement("MetaData") 230 | 231 | numValues = md.numValues 232 | 233 | For i = 0 To numValues - 1 234 | 235 | Set e = md.GetValueAsElement(i) 236 | 237 | emsxFieldName = e.GetElement("EMSX_FIELD_NAME") 238 | emsxDispName = e.GetElement("EMSX_DISP_NAME") 239 | emsxType = e.GetElement("EMSX_TYPE") 240 | emsxLevel = e.GetElement("EMSX_LEVEL") 241 | emsxLen = e.GetElement("EMSX_LEN") 242 | 243 | log "MetaData: " & emsxFieldName & ", " & emsxDispName & ", " & emsxType & ", " & emsxLevel & ", " & emsxLen 244 | 245 | Next i 246 | 247 | m_BBG_EMSX.Stop 248 | running = False 249 | 250 | End If 251 | End If 252 | Loop 253 | 254 | End Sub 255 | 256 | 257 | 258 | 259 | 260 | -------------------------------------------------------------------------------- /EMSXFullSet_Python/CreateOrder.py: -------------------------------------------------------------------------------- 1 | # CreateOrder.py 2 | 3 | import blpapi 4 | import sys 5 | 6 | 7 | SESSION_STARTED = blpapi.Name("SessionStarted") 8 | SESSION_STARTUP_FAILURE = blpapi.Name("SessionStartupFailure") 9 | SERVICE_OPENED = blpapi.Name("ServiceOpened") 10 | SERVICE_OPEN_FAILURE = blpapi.Name("ServiceOpenFailure") 11 | ERROR_INFO = blpapi.Name("ErrorInfo") 12 | CREATE_ORDER = blpapi.Name("CreateOrder") 13 | 14 | d_service="//blp/emapisvc_beta" 15 | d_host="localhost" 16 | d_port=8194 17 | bEnd=False 18 | 19 | class SessionEventHandler(): 20 | 21 | def processEvent(self, event, session): 22 | try: 23 | if event.eventType() == blpapi.Event.SESSION_STATUS: 24 | self.processSessionStatusEvent(event,session) 25 | 26 | elif event.eventType() == blpapi.Event.SERVICE_STATUS: 27 | self.processServiceStatusEvent(event,session) 28 | 29 | elif event.eventType() == blpapi.Event.RESPONSE: 30 | self.processResponseEvent(event) 31 | 32 | else: 33 | self.processMiscEvents(event) 34 | 35 | except: 36 | print ("Exception: %s" % sys.exc_info()[0]) 37 | 38 | return False 39 | 40 | 41 | def processSessionStatusEvent(self,event,session): 42 | print ("Processing SESSION_STATUS event") 43 | 44 | for msg in event: 45 | if msg.messageType() == SESSION_STARTED: 46 | print ("Session started...") 47 | session.openServiceAsync(d_service) 48 | 49 | elif msg.messageType() == SESSION_STARTUP_FAILURE: 50 | print >> sys.stderr, ("Error: Session startup failed") 51 | 52 | else: 53 | print (msg) 54 | 55 | 56 | def processServiceStatusEvent(self,event,session): 57 | print ("Processing SERVICE_STATUS event") 58 | 59 | for msg in event: 60 | 61 | if msg.messageType() == SERVICE_OPENED: 62 | print ("Service opened...") 63 | 64 | service = session.getService(d_service) 65 | 66 | request = service.createRequest("CreateOrder") 67 | 68 | # The fields below are mandatory 69 | request.set("EMSX_TICKER", "IBM US Equity") 70 | request.set("EMSX_AMOUNT", 1000) 71 | request.set("EMSX_ORDER_TYPE", "MKT") 72 | request.set("EMSX_TIF", "DAY") 73 | request.set("EMSX_HAND_INSTRUCTION", "ANY") 74 | request.set("EMSX_SIDE", "BUY") 75 | 76 | 77 | # The fields below are optional 78 | #request.set("EMSX_ACCOUNT","TestAccount") 79 | #request.set("EMSX_BASKET_NAME", "HedgingBasket") 80 | #request.set("EMSX_BROKER", "BMTB") 81 | #request.set("EMSX_CFD_FLAG", "1") 82 | #request.set("EMSX_CLEARING_ACCOUNT", "ClrAccName") 83 | #request.set("EMSX_CLEARING_FIRM", "FirmName") 84 | #request.set("EMSX_CUSTOM_NOTE1", "Note1") 85 | #request.set("EMSX_CUSTOM_NOTE2", "Note2") 86 | #request.set("EMSX_CUSTOM_NOTE3", "Note3") 87 | #request.set("EMSX_CUSTOM_NOTE4", "Note4") 88 | #request.set("EMSX_CUSTOM_NOTE5", "Note5") 89 | #request.set("EMSX_EXCHANGE_DESTINATION", "ExchDest") 90 | #request.set("EMSX_EXEC_INSTRUCTION", "Drop down values from EMSX Ticket") 91 | #request.set("EMSX_GET_WARNINGS", "0") 92 | #request.set("EMSX_GTD_DATE", "20170105") 93 | #request.set("EMSX_INVESTOR_ID", "InvID") 94 | #request.set("EMSX_LIMIT_PRICE", 123.45) 95 | #request.set("EMSX_LOCATE_BROKER", "BMTB") 96 | #request.set("EMSX_LOCATE_ID", "SomeID") 97 | #request.set("EMSX_LOCATE_REQ", "Y") 98 | #request.set("EMSX_NOTES", "Some notes") 99 | #request.set("EMSX_ODD_LOT", "0") 100 | #request.set("EMSX_ORDER_ORIGIN", "") 101 | #request.set("EMSX_ORDER_REF_ID", "UniqueID") 102 | #request.set("EMSX_P_A", "P") 103 | #request.set("EMSX_RELEASE_TIME", 34341) 104 | #request.set("EMSX_REQUEST_SEQ", 1001) 105 | #request.set("EMSX_SETTLE_CURRENCY", "USD") 106 | #request.set("EMSX_SETTLE_DATE", 20170106) 107 | #request.set("EMSX_SETTLE_TYPE", "T+2") 108 | #request.set("EMSX_STOP_PRICE", 123.5) 109 | 110 | print ("Request: %s" % request.toString()) 111 | 112 | self.requestID = blpapi.CorrelationId() 113 | 114 | session.sendRequest(request, correlationId=self.requestID ) 115 | 116 | elif msg.messageType() == SERVICE_OPEN_FAILURE: 117 | print >> sys.stderr, ("Error: Service failed to open") 118 | 119 | def processResponseEvent(self, event): 120 | print ("Processing RESPONSE event") 121 | 122 | for msg in event: 123 | 124 | print ("MESSAGE: %s" % msg.toString()) 125 | print ("CORRELATION ID: %d" % msg.correlationIds()[0].value()) 126 | 127 | 128 | if msg.correlationIds()[0].value() == self.requestID.value(): 129 | print ("MESSAGE TYPE: %s" % msg.messageType()) 130 | 131 | if msg.messageType() == ERROR_INFO: 132 | errorCode = msg.getElementAsInteger("ERROR_CODE") 133 | errorMessage = msg.getElementAsString("ERROR_MESSAGE") 134 | print ("ERROR CODE: %d\tERROR MESSAGE: %s" % (errorCode,errorMessage)) 135 | elif msg.messageType() == CREATE_ORDER: 136 | emsx_sequence = msg.getElementAsInteger("EMSX_SEQUENCE") 137 | message = msg.getElementAsString("MESSAGE") 138 | print ("EMSX_SEQUENCE: %d\tMESSAGE: %s" % (emsx_sequence,message)) 139 | 140 | global bEnd 141 | bEnd = True 142 | 143 | def processMiscEvents(self, event): 144 | 145 | print ("Processing " + event.eventType() + " event") 146 | 147 | for msg in event: 148 | 149 | print ("MESSAGE: %s" % (msg.tostring())) 150 | 151 | 152 | def main(): 153 | 154 | sessionOptions = blpapi.SessionOptions() 155 | sessionOptions.setServerHost(d_host) 156 | sessionOptions.setServerPort(d_port) 157 | 158 | print ("Connecting to %s:%d" % (d_host,d_port)) 159 | 160 | eventHandler = SessionEventHandler() 161 | 162 | session = blpapi.Session(sessionOptions, eventHandler.processEvent) 163 | 164 | if not session.startAsync(): 165 | print ("Failed to start session.") 166 | return 167 | 168 | global bEnd 169 | while bEnd==False: 170 | pass 171 | 172 | session.stop() 173 | 174 | if __name__ == "__main__": 175 | print ("Bloomberg - EMSX API Example - CreateOrder") 176 | try: 177 | main() 178 | except KeyboardInterrupt: 179 | print ("Ctrl+C pressed. Stopping...") 180 | 181 | 182 | __copyright__ = """ 183 | Copyright 2017. Bloomberg Finance L.P. 184 | 185 | Permission is hereby granted, free of charge, to any person obtaining a copy 186 | of this software and associated documentation files (the "Software"), to 187 | deal in the Software without restriction, including without limitation the 188 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 189 | sell copies of the Software, and to permit persons to whom the Software is 190 | furnished to do so, subject to the following conditions: The above 191 | copyright notice and this permission notice shall be included in all copies 192 | or substantial portions of the Software. 193 | 194 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 195 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 196 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 197 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 198 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 199 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 200 | IN THE SOFTWARE. 201 | """ 202 | --------------------------------------------------------------------------------