Ver código fonte

quote handler fixes

laxaurus 6 anos atrás
pai
commit
bb9f104aa5

+ 0 - 0
src/config/tws_gateway_prd.cfg → src/comms/tws_gateway_prd.cfg


+ 33 - 4
src/ormdapi/v2/apiv2.py

@@ -213,6 +213,31 @@ class v2_helper():
         
         
         cdict ={}
         cdict ={}
         js_v2 = json.loads(contract_v2str)
         js_v2 = json.loads(contract_v2str)
+        
+        
+        
+        symbol = js_v2['symbol'] if 'symbol' in js_v2 else None
+        currency= js_v2['currency'] if 'currency' in js_v2 else None
+        sec_type = js_v2['sec_type'] if 'sec_type' in js_v2 else None
+        exchange = js_v2['exchange'] if 'exchange' in js_v2 else None
+        expiry= js_v2['expiry'] if 'expiry' in js_v2 else None
+        right= js_v2['right'] if 'right' in js_v2 else None
+        strike= js_v2['strike'] if 'strike' in js_v2 else None
+        
+        if symbol == None or currency == None or sec_type == None or exchange == None:
+            raise ('one or more of the values in symbol, currency, duration, sec_type, exchange, end_date contains null value!')
+        if sec_type.upper() in ['OPT']:
+            if expiry == None or right == None or strike == None:
+                raise('expiry or right or strike can not be null for options!')
+            try:
+                _ = float(strike)
+            except:
+                raise('parameter strike must be a number!')
+        if sec_type.upper() in ['FUT'] and expiry == None:
+            print 'expiry can not be null for futures'
+        
+        
+        
         for k,v in js_v2.iteritems():
         for k,v in js_v2.iteritems():
             if k in mmap:
             if k in mmap:
                 cdict[mmap[k]] = v
                 cdict[mmap[k]] = v
@@ -390,14 +415,15 @@ class QuoteRequest_v2(Resource, Publisher):
         
         
 
 
 
 
-        contract = v2_helper.format_v2_str_to_contract(args['contract'])
-        require_greeks = False
         try:
         try:
+            contract = v2_helper.format_v2_str_to_contract(args['contract'])
+            require_greeks = False
+            
             if contract.m_secType in ['OPT']:
             if contract.m_secType in ['OPT']:
-                if args['greeks'].upper() == 'TRUE':
+                if args['greeks'] <> None and args['greeks'].upper() == 'TRUE':
                     require_greeks = True
                     require_greeks = True
         except:
         except:
-            pass
+            return {'error': 'check the format of the contract message! %s' % traceback.format_exc()}, 409
         
         
         if args['live_update']:
         if args['live_update']:
             handle_id = args['live_update'].strip('"').strip("'")
             handle_id = args['live_update'].strip('"').strip("'")
@@ -681,6 +707,9 @@ class HistoricalData_v2(Resource):
                     return 'Not getting any contract information from the server after waited 10 seconds! Check for last errors', 404
                     return 'Not getting any contract information from the server after waited 10 seconds! Check for last errors', 404
                 hd = self.contract_info_mgr.get_historical_data(id)
                 hd = self.contract_info_mgr.get_historical_data(id)
                 if hd <> None:
                 if hd <> None:
+                    if 'error' in hd:
+                        return {'historical_data': hd}, 404
+    
                     return {'historical_data': hd}, 200
                     return {'historical_data': hd}, 200
                 
                 
         except:
         except:

+ 16 - 1
src/ormdapi/v2/quote_handler.py

@@ -37,6 +37,17 @@ class QuoteRESTHandler(Subscriber):
         logging.debug('QuoteHandler:tickPrice')
         logging.debug('QuoteHandler:tickPrice')
         try:
         try:
             s = self.symbols[contract_key]
             s = self.symbols[contract_key]
+            '''
+                a contract may have already existed in the self.symbols dictionary
+                from a previous subscription attempt that was unsuccessful,
+                resulting in no Symbol created but an error message stored
+                as a dict and assigned to self.symbols (check the code in update
+                function below)
+                the following if condition deals with such a case by recreating a
+                new symbol and getting rid of the error dict
+            '''
+            if not isinstance(s, Symbol):
+                raise KeyError            
         except KeyError:
         except KeyError:
             s = Symbol(ContractHelper.makeContractfromRedisKeyEx(contract_key))
             s = Symbol(ContractHelper.makeContractfromRedisKeyEx(contract_key))
             self.symbols[contract_key] = s
             self.symbols[contract_key] = s
@@ -46,9 +57,11 @@ class QuoteRESTHandler(Subscriber):
         
         
     
     
     def handle_ticksize(self, contract_key, field, size):
     def handle_ticksize(self, contract_key, field, size):
-        logging.debug('QuoteHandler:ticksize')
+        logging.info('QuoteHandler:ticksize %s' % contract_key)
         try:
         try:
             s = self.symbols[contract_key]
             s = self.symbols[contract_key]
+            if not isinstance(s, Symbol):
+                raise KeyError
         except KeyError:
         except KeyError:
             s = Symbol(ContractHelper.makeContractfromRedisKeyEx(contract_key))
             s = Symbol(ContractHelper.makeContractfromRedisKeyEx(contract_key))
             self.symbols[contract_key] = s
             self.symbols[contract_key] = s
@@ -59,6 +72,8 @@ class QuoteRESTHandler(Subscriber):
         try:
         try:
             contract_key = params['contract_key']
             contract_key = params['contract_key']
             s = self.symbols[contract_key]
             s = self.symbols[contract_key]
+            if not isinstance(s, Symbol):
+                raise KeyError            
         except KeyError:
         except KeyError:
             s = Symbol(ContractHelper.makeContractfromRedisKeyEx(contract_key))
             s = Symbol(ContractHelper.makeContractfromRedisKeyEx(contract_key))
             self.symbols[contract_key] = s
             self.symbols[contract_key] = s

+ 2 - 1
src/ormdapi/v2/ws/client/ws_api_test.py

@@ -19,7 +19,8 @@ def accepted(event, handle):
     test api
     test api
 '''
 '''
 def test_quote(rest_server, handle):
 def test_quote(rest_server, handle):
-    url = 'http://%s/v2/quote?contract={"currency": "USD", "symbol": "EUR", "sec_type": "CASH", "exchange": "IDEALPRO"}&live_update=%s' % (rest_server, handle)
+    #url = 'http://%s/v2/quote?contract={"currency": "USD", "symbol": "EUR", "sec_type": "CASH", "exchange": "IDEALPRO"}&live_update=%s' % (rest_server, handle)
+    url = 'http://%s/v2/quote?contract={"currency": "USD", "symbol": "GOOG", "sec_type": "OPT", "strike": 1077.5, "exchange": "SMART", "right": "C", "expiry":"20190614"}&live_update=%s' % (rest_server, handle)
     print url
     print url
     r = requests.get(url)
     r = requests.get(url)
     print r.content
     print r.content