from flask.views import MethodView from decorators import throttle from flask.ext.pymongo import PyMongo from flask import json from utils import redis_connect import utils import redis import time from blueprints.trials import trials_blueprint from coiapi import create_app app = create_app() # blueprints app.register_blueprint(trials_blueprint, url_prefix='/trials') mongo = PyMongo(app) rds = redis_connect() # -- error handlers @app.errorhandler(405) def handle_405(error): return utils.generate_response(request, {'error': 'Method not allowed'}) @app.errorhandler(406) def handle_406(error): return 'Invalid or unspecified content type' # -- end error handlers @app.before_request def before(): addr = request.remote_addr count = rds.incr('visitors:{0}'.format(addr))
'uid': bot.uid, "type": "stop_bot" })) bot.update_blueprint() utils.flash("bot '{}' is stopping. Status: {}".format( bot.name, bot.status), "info", sync=False) sys.exit(exitcode) # ----------------------------------------------- # -- init -- signal.signal(signal.SIGTERM, on_sigterm) signal.signal(signal.SIGUSR1, on_sigterm) rds = utils.redis_connect() uid = sys.argv[1] logging.info("%s Spawning Orderbot" % uid) try: botdata = json.loads(rds.get("trader:startbot:" + uid)) except Exception as e: logging.error("Error '{}': no data in redis's 'trader:startbot:{}'".format( e, uid)) sys.exit(9) mybot = bot.OrderBot(botdata, rds) rds.delete("trader:startbot:" + uid) mybot.update_blueprint() utils.flash("bot '{}' initialized".format(mybot.name), "success", sync=False)