class ApiProduct: """ApiAdapterFactory Product interface""" def __init__(self): self.api_class = None self.name = None self.exchange = None self.market = None self.calls = None self.channels = None self.api = None self.api_context = None self.conf = Conf() self.rstypes = RESULT_TYPES.copy() def interface(self, api_class, exchange=None, market=None): """Implement the interface for the adapter object""" self.api_class = api_class self.name = api_class.name self.exchange = exchange self.market = market self.calls = self.conf.get_api_calls() self.channels = self.conf.get_ws_subscriptions(self.name) self.api = None self.api_context = AllApiContexts().get(self.name) self.api_context.creds = self.conf.get_api_credentials(self.name) try: self.rstypes.update(self.api.result_types) except AttributeError: pass def shutdown(self): """Executed on shutdown of application""" self.api.shutdown()
def __init__(self, api_classes): self.apis = [] # type: list self.wsocks = [] # type: list # Extract configuration necessary to generate api adapters self.conf = Conf() api_conf = self.conf.get_api() exchanges = getattr(api_conf, "exchanges", []) currencies = getattr(api_conf, "currencies", []) # Setup exchange/currency/call adapters exch_curr = [] for exch in exchanges: for curr in currencies: exch_curr.append((exch, curr)) if exch_curr: for val_pair in exch_curr: for api_class in api_classes: self.create_api_adapter(api_class, *val_pair) else: for api_class in api_classes: self.create_api_adapter(api_class) for api_class in api_classes: self.create_ws_adapter(api_class)
def __init__(self): self.host = Conf().get_base_url('mysql','host') self.port = Conf().get_base_url('mysql','port') self.root = Conf().get_base_url('mysql','root') self.pwd = Conf().get_base_url('mysql','pwd') self.db = pymysql.connect(host=self.host, user=self.root, password=self.pwd, port=int(self.port), ) #建立连接 self.cursor = self.db.cursor() #建立游标
def __init__(self): self.api_class = None self.name = None self.exchange = None self.market = None self.calls = None self.channels = None self.api = None self.api_context = None self.conf = Conf() self.rstypes = RESULT_TYPES.copy()
class ApiMetaAdapter: """Adapter of adapters for all API instantiations""" def __init__(self, api_classes): self.apis = [] # type: list self.wsocks = [] # type: list # Extract configuration necessary to generate api adapters self.conf = Conf() api_conf = self.conf.get_api() exchanges = getattr(api_conf, "exchanges", []) currencies = getattr(api_conf, "currencies", []) # Setup exchange/currency/call adapters exch_curr = [] for exch in exchanges: for curr in currencies: exch_curr.append((exch, curr)) if exch_curr: for val_pair in exch_curr: for api_class in api_classes: self.create_api_adapter(api_class, *val_pair) else: for api_class in api_classes: self.create_api_adapter(api_class) for api_class in api_classes: self.create_ws_adapter(api_class) def create_ws_adapter(self, api_class): """Create and return an api adapter""" api = WsAdapterFactory() api.product.interface(api_class) self.wsocks.append(api.product) def create_api_adapter(self, api_class, exchange=None, market=None): """Create and return an api adapter""" api = ApiAdapterFactory() api.product.interface(api_class, exchange, market) self.apis.append(api.product) def run(self, callback): """Executed on startup of application""" for wsock in self.wsocks: wsock.run(callback) for api in self.apis: api.run(callback) def shutdown(self): """Executed on shutdown of application""" for wsock in self.wsocks: wsock.run() for api in self.apis: api.shutdown()
def main(strategies=[Print(), Echo()], apiclasses=[Coinigy], configfile=None): """Main routine""" # Grab configuration conf = Conf(filename=configfile) # Roll out pipeline strat = Strategy(*strategies) impl = AppBuilder(apiclasses, strat) # Run impl.run()
class AllApiContexts(metaclass=Singleton): """ Shared context between API instances. """ def __init__(self): self.contexts = {} # type: dict self.conf = Conf() def get(self, apiname): """Creates a context if one doesn't exist for given API""" try: return self.contexts[apiname] except KeyError: return self.create(apiname) def create(self, apiname): """Creates a context for given API""" self.contexts[apiname] = ApiContext() conf = self.conf.get_api(apiname) conf["currencies"] = self.conf.get_currencies() self.contexts[apiname].populate(conf) return self.contexts[apiname]
def __init__(self): self.contexts = {} # type: dict self.conf = Conf()
def join_url(self,sheet_url): #获取基础路径中url conf = Conf() base_url = conf.get_base_url('api','url') # print(type(base_url)) return os.path.join(base_url,sheet_url)