Example #1
0
    def __init__(self, setAuto=True, setMongo=True):

        setup_logger(logger_name="broker", log_file='broker.log')
        self.logger = logging.getLogger("broker")

        self.afacade = facade.Facade()
        #in memory data
        self.balances = None
        self.openorders = list()
        self.submitted_orders = list()
        self.active_exchanges = list()
        self.selected_exchange = None

        if setAuto:
            self.set_keys_exchange_file()

        if setMongo:
            try:
                wdir = self.get_workingdir()
                path_file_config = wdir + "/" + "config.toml"
                config_dict = parse_toml(path_file_config)
            except:
                self.logger.error("no file. path expected: %s" %
                                  str(path_file_config))
            try:
                mongo_conf = config_dict["MONGO"]
                uri = mongo_conf["uri"]
                self.set_mongo(uri)
                self.using_mongo = True
            except:
                self.using_mongo = False
                self.logger.error("could not set mongo")

        self.starttime = datetime.datetime.utcnow()
Example #2
0
 def set_apikeys_fromfile(self, user_id=""):
     #store_apikey
     try:
         wdir = self.get_workingdir()
         api_file = wdir + "/" + "apikeys.toml"
         api_keys = parse_toml(api_file)
         #print (api_keys)
         self.db.apikeys.drop()
         for k, v in api_keys.items():
             self.store_apikey(k, v["public_key"], v["secret"], user_id)
             #pass
     except:
         self.logger.error("no file. path expected: %s" % str(api_file))
Example #3
0
    def __init__(self, setMongo=True):

        setup_logger(logger_name="broker", log_file='broker.log')
        self.logger = logging.getLogger("broker")

        setMongo = True
        setRedis = True

        try:
            wdir = self.get_workingdir()
            path_file_config = wdir + "/" + "config.toml"
            config_dict = parse_toml(path_file_config)
        except:
            self.logger.error("no file. path expected: %s" %
                              str(path_file_config))

        if setMongo:
            try:
                mongo_conf = config_dict["MONGO"]
                uri = mongo_conf["uri"]
                self.set_mongo(uri)
                self.using_mongo = True
            except:
                self.using_mongo = False
                self.logger.error("could not set mongo")

        self.clients = {}

        self.starttime = datetime.datetime.utcnow()

        self.session_user_id = None
        self.session_active = False

        if setRedis:
            self.logger.info(config_dict)
            try:
                redis_conf = config_dict["REDIS"]
                host = redis_conf["host"]
                port = redis_conf["port"]
                self.redis_client = redis.Redis(host=host, port=port)
            except Exception as e:
                self.logger.error("could not set redis %s %s" %
                                  (str(host), str(port)))
                self.logger.error(str(e))
Example #4
0
    def set_keys_exchange_file(self, path_file_apikeys=None, exchanges=None):
        self.logger.info("set_keys_exchange_file")
        if path_file_apikeys is None:
            wdir = self.get_workingdir()
            #standard_apikeys_file
            path_file_apikeys = wdir + "/" + standard_apikeys_file
        self.logger.info("use path %s" % path_file_apikeys)
        apikeys = parse_toml(path_file_apikeys)
        self.logger.info("set keys %s" % apikeys.keys())

        if exchanges:
            for e in exchanges:
                try:
                    self.logger.info("set %s %s" %
                                     (e, str(apikeys[e]["public_key"])))
                    self.set_keys_exchange(e, apikeys[e])
                except Exception as err:
                    self.logger.error("could not set %s" % str(err))
        else:
            try:
                if not self.active_exchanges:
                    for k, v in apikeys.items():
                        self.logger.info("set %s" % k)
                        if exc.exchange_exists(k):
                            try:

                                self.set_keys_exchange(k, apikeys[k])
                                self.active_exchanges.append(k)
                            except Exception as err:
                                self.logger.error(
                                    "could not set api keys: %s" % err)
                        else:
                            self.logger.error(
                                "exchange not supported or not set")
                    self.logger.info("active exchanges %s" %
                                     self.active_exchanges)

            except Exception as err:
                self.logger.error("error parsing apikeys file: %s" % (err))
Example #5
0
        if not os.path.exists(wdir):
            os.makedirs(wdir)

        return wdir

    elif os.name == 'nt':
        home = str(Path.home())
        wdir = home + os.sep + ".archon"

        if not os.path.exists(wdir):
            os.makedirs(wdir)

        return wdir

    else:
        print("unknown os ", os.name)


wdir = get_workingdir()
print(wdir)
key_file = wdir + os.sep + "apikeys.toml"
print(key_file)

print(os.path.exists(key_file))

keys = config.parse_toml(key_file)
print(keys)

brk = b.Brokerservice()
brk.store_apikey(exc.BINANCE, "pub", "sec")
#store_apikey(self, exchange, pubkey, secret, user_id=""):