Drop contracts cache; that wasn't the bottleneck
This also fixes a bug where option subscriptions weren't actually being changed when a new call was made..kivy_mainline_and_py3.8
							parent
							
								
									3fd01c42f2
								
							
						
					
					
						commit
						5af90c044f
					
				| 
						 | 
					@ -5,7 +5,6 @@ import time
 | 
				
			||||||
from datetime import datetime
 | 
					from datetime import datetime
 | 
				
			||||||
from functools import partial
 | 
					from functools import partial
 | 
				
			||||||
import configparser
 | 
					import configparser
 | 
				
			||||||
from operator import itemgetter
 | 
					 | 
				
			||||||
from typing import List, Tuple, Dict, Any, Iterator, NamedTuple
 | 
					from typing import List, Tuple, Dict, Any, Iterator, NamedTuple
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import trio
 | 
					import trio
 | 
				
			||||||
| 
						 | 
					@ -418,9 +417,8 @@ async def get_client() -> Client:
 | 
				
			||||||
        log.debug("Check time to ensure access token is valid")
 | 
					        log.debug("Check time to ensure access token is valid")
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            # await client.api.time()
 | 
					            # await client.api.time()
 | 
				
			||||||
            quote = await client.quote(['RY.TO'])
 | 
					            await client.quote(['RY.TO'])
 | 
				
			||||||
        except Exception as err:
 | 
					        except Exception:
 | 
				
			||||||
            # import pdb; pdb.set_trace()
 | 
					 | 
				
			||||||
            # access token is likely no good
 | 
					            # access token is likely no good
 | 
				
			||||||
            log.warn(f"Access token {client.access_data['access_token']} seems"
 | 
					            log.warn(f"Access token {client.access_data['access_token']} seems"
 | 
				
			||||||
                     f" expired, forcing refresh")
 | 
					                     f" expired, forcing refresh")
 | 
				
			||||||
| 
						 | 
					@ -501,18 +499,15 @@ async def option_quoter(client: Client, tickers: List[str]):
 | 
				
			||||||
    @async_lifo_cache(maxsize=128)
 | 
					    @async_lifo_cache(maxsize=128)
 | 
				
			||||||
    async def get_contract_by_date(
 | 
					    async def get_contract_by_date(
 | 
				
			||||||
        sym_date_pairs: Tuple[Tuple[str, str]],
 | 
					        sym_date_pairs: Tuple[Tuple[str, str]],
 | 
				
			||||||
        _contract_cache: dict = {}
 | 
					 | 
				
			||||||
    ):
 | 
					    ):
 | 
				
			||||||
        """For each tuple,
 | 
					        """For each tuple,
 | 
				
			||||||
        ``(symbol_date_1, symbol_date_2, ... , symbol_date_n)``
 | 
					        ``(symbol_date_1, symbol_date_2, ... , symbol_date_n)``
 | 
				
			||||||
        return a contract dict.
 | 
					        return a contract dict.
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        symbols, dates = zip(*sym_date_pairs)
 | 
					        symbols, dates = zip(*sym_date_pairs)
 | 
				
			||||||
        if not _contract_cache:
 | 
					 | 
				
			||||||
        contracts = await client.get_all_contracts(symbols)
 | 
					        contracts = await client.get_all_contracts(symbols)
 | 
				
			||||||
            _contract_cache.update(contracts)
 | 
					 | 
				
			||||||
        selected = {}
 | 
					        selected = {}
 | 
				
			||||||
        for key, val in _contract_cache.items():
 | 
					        for key, val in contracts.items():
 | 
				
			||||||
            if key.expiry in dates:
 | 
					            if key.expiry in dates:
 | 
				
			||||||
                selected[key] = val
 | 
					                selected[key] = val
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue