def on_init(self): self.ticker = self.contract.ticker log.msg("Engine for contract %s (%d) started." % (self.ticker, self.contract.id)) log.msg( "Listening for connections on port %d." % (config.getint("engine", "accountant_base_port") + self.contract.id)) log.msg( "Listening for connections on port %d." % (config.getint("engine", "administrator_base_port") + self.contract.id))
def main(): fo = log.startLogging(sys.stdout) fo.formatTime = lambda x: datetime.datetime.fromtimestamp(x).strftime("%Y-%m-%d %H:%M:%S.%f") engine = database.make_engine() timeout = config.getint("ledger", "timeout") ledger = Ledger(engine, timeout) accountant_export = AccountantExport(ledger) watchdog(config.get("watchdog", "ledger")) router_share_async(accountant_export, config.get("ledger", "accountant_export")) reactor.run()
def main(): fo = log.startLogging(sys.stdout) fo.formatTime = lambda x: datetime.datetime.fromtimestamp(x).strftime( "%Y-%m-%d %H:%M:%S.%f") engine = database.make_engine() timeout = config.getint("ledger", "timeout") ledger = Ledger(engine, timeout) accountant_export = AccountantExport(ledger) watchdog(config.get("watchdog", "ledger")) router_share_async(accountant_export, config.get("ledger", "accountant_export")) reactor.run()
def main(): log.startLogging(sys.stdout) session = database.make_session() safe_price_subscriber = connect_subscriber(config.get("safe_price_forwarder", "zmq_backend_address")) safe_price_subscriber.subscribe('') sendmail = Sendmail(config.get("riskmanager", "from_email")) accountant = AccountantProxy("dealer", config.get("accountant", "riskmanager_export"), config.getint("accountant", "riskmanager_export_base_port")) riskmanager = RiskManager(session, sendmail, safe_price_subscriber, accountant) reactor.run()
def main(): log.startLogging(sys.stdout) monitors = ["administrator", "cashier", "ledger", "webserver"] session = database.make_session() proxy = AlertsProxy(config.get("alerts", "export")) watchdogs = {} for name in monitors: watchdogs[name] = Watchdog(name, config.get("watchdog", name), proxy) watchdogs[name].run() num_accountants = config.getint("accountant", "num_procs") for i in range(num_accountants): name = "accountant_%d" % i watchdogs[name] = Watchdog(name, config.get("watchdog", "accountant") % (config.getint("watchdog", "accountant_base_port") + i), proxy) watchdogs[name].run() engine_base_port = config.getint("watchdog", "engine_base_port") for contract in session.query(models.Contract).filter_by(active=True).all(): if contract.contract_type != "cash": watchdogs[contract.ticker] = Watchdog(contract.ticker, config.get("watchdog", "engine") % (engine_base_port + int(contract.id)), proxy) watchdogs[contract.ticker].run() reactor.run()
def main(): log.startLogging(sys.stdout) session = database.make_session() safe_price_subscriber = connect_subscriber( config.get("safe_price_forwarder", "zmq_backend_address")) safe_price_subscriber.subscribe('') sendmail = Sendmail(config.get("riskmanager", "from_email")) accountant = AccountantProxy( "dealer", config.get("accountant", "riskmanager_export"), config.getint("accountant", "riskmanager_export_base_port")) riskmanager = RiskManager(session, sendmail, safe_price_subscriber, accountant) reactor.run()
def main(pm): from sputnik.webserver.router.twisted.wamp import RouterFactory router_factory = RouterFactory() router_factory.router = SputnikRouter router_factory.authz_plugins = \ pm.services.get("sputnik.webserver.plugins.authz", []) router_factory.schema_plugins = \ pm.services.get("sputnik.webserver.plugins.schema", []) from sputnik.webserver.router.twisted.wamp import RouterSessionFactory session_factory = RouterSessionFactory(router_factory) session_factory.session = SputnikRouterSession authn_stack = [("ip.IPFilter", "requisite"), ("anonymous.AnonymousLogin", "sufficient"), ("cookie.CookieLogin", "sufficient"), ("wampcra.WAMPCRALogin", "requisite"), ("totp.TOTPVerification", "requisite")] session_factory.plugins = [] for plugin_name, flag in authn_stack: path = "sputnik.webserver.plugins.authn." + plugin_name session_factory.plugins.append((pm.plugins[path], flag)) rpc_plugins = pm.services.get("sputnik.webserver.plugins.rpc", []) feeds_plugins = pm.services.get("sputnik.webserver.plugins.feeds", []) svc_plugins = rpc_plugins + feeds_plugins for plugin in svc_plugins: component_session = plugin component_session.config.realm = u"sputnik" session_factory.add(component_session, plugin.plugin_path.decode("ascii"), u"trusted") uri = "ws://" if config.getboolean("webserver", "ssl"): uri = "wss://" address = config.get("webserver", "ws_address") port = config.getint("webserver", "ws_port") uri += "%s:%s/" % (address, port) from autobahn.twisted.websocket import WampWebSocketServerFactory transport_factory = WampWebSocketServerFactory(session_factory, uri, debug = False, debug_wamp = False) transport_factory.setProtocolOptions(failByDrop = False) watchdog(config.get("watchdog", "webserver")) from twisted.web.server import Site from autobahn.twisted.resource import WebSocketResource root = Root() ws_resource = WebSocketResource(transport_factory) rest_resource = pm.plugins['sputnik.webserver.rest.RESTProxy'] root.putChild("ws", ws_resource) root.putChild("api", rest_resource) site = Site(root) site.noisy = False site.log = lambda _: None from twisted.internet.endpoints import serverFromString, quoteStringArgument if config.getboolean("webserver", "ssl"): key = config.get("webserver", "ssl_key") cert = config.get("webserver", "ssl_cert") cert_chain = config.get("webserver", "ssl_cert_chain") # TODO: Add dhparameters # See https://twistedmatrix.com/documents/14.0.0/core/howto/endpoints.html server = serverFromString(reactor, b"ssl:%d:privateKey=%s:certKey=%s:extraCertChain=%s:sslmethod=TLSv1_METHOD" % (port, quoteStringArgument(key), quoteStringArgument(cert), quoteStringArgument(cert_chain))) else: server = serverFromString(reactor, b"tcp:%d" % port) server.listen(site)
def run(pm, reactor): from sputnik.webserver.router.twisted.wamp import RouterFactory router_factory = RouterFactory() router_factory.router = SputnikRouter router_factory.authz_plugins = \ pm.services.get("sputnik.webserver.plugins.authz", []) router_factory.schema_plugins = \ pm.services.get("sputnik.webserver.plugins.schema", []) from sputnik.webserver.router.twisted.wamp import RouterSessionFactory session_factory = RouterSessionFactory(router_factory) session_factory.session = SputnikRouterSession authn_stack = [("ip.IPFilter", "requisite"), ("anonymous.AnonymousLogin", "sufficient"), ("cookie.CookieLogin", "sufficient"), ("wampcra.WAMPCRALogin", "requisite"), ("totp.TOTPVerification", "requisite")] session_factory.plugins = [] for plugin_name, flag in authn_stack: path = "sputnik.webserver.plugins.authn." + plugin_name session_factory.plugins.append((pm.plugins[path], flag)) rpc_plugins = pm.services.get("sputnik.webserver.plugins.rpc", []) feeds_plugins = pm.services.get("sputnik.webserver.plugins.feeds", []) svc_plugins = rpc_plugins + feeds_plugins for plugin in svc_plugins: component_session = plugin component_session.config.realm = u"sputnik" session_factory.add(component_session, plugin.plugin_path.decode("ascii"), u"trusted") uri = "ws://" if config.getboolean("webserver", "ssl"): uri = "wss://" address = config.get("webserver", "ws_address") port = config.getint("webserver", "ws_port") uri += "%s:%s/" % (address, port) from autobahn.twisted.websocket import WampWebSocketServerFactory transport_factory = WampWebSocketServerFactory(session_factory, uri, debug=False, debug_wamp=False) transport_factory.setProtocolOptions(failByDrop=False) watchdog(config.get("watchdog", "webserver")) from twisted.web.server import Site from autobahn.twisted.resource import WebSocketResource root = Root() ws_resource = WebSocketResource(transport_factory) rest_resource = pm.plugins['sputnik.webserver.rest.RESTProxy'] root.putChild("ws", ws_resource) root.putChild("api", rest_resource) site = Site(root) site.noisy = False site.log = lambda _: None from twisted.internet.endpoints import serverFromString, quoteStringArgument if config.getboolean("webserver", "ssl"): key = config.get("webserver", "ssl_key") cert = config.get("webserver", "ssl_cert") cert_chain = config.get("webserver", "ssl_cert_chain") # TODO: Add dhparameters # See https://twistedmatrix.com/documents/14.0.0/core/howto/endpoints.html server = serverFromString( reactor, b"ssl:%d:privateKey=%s:certKey=%s:extraCertChain=%s:sslmethod=TLSv1_METHOD" % (port, quoteStringArgument(key), quoteStringArgument(cert), quoteStringArgument(cert_chain))) else: server = serverFromString(reactor, b"tcp:%d" % port) server.listen(site)
def main(): log.startLogging(sys.stdout) accountant = AccountantProxy("dealer", config.get("accountant", "cashier_export"), config.getint("accountant", "cashier_export_base_port")) session = db.make_session() bitcoin_conf = config.get("cashier", "bitcoin_conf") log.msg('connecting to bitcoin client') bitcoinrpc = {'BTC': BitcoinRpc(bitcoin_conf, 1)} compropago = Compropago(config.get("cashier", "compropago_key")) cold_wallet_period = config.getint("cashier", "cold_wallet_period") sendmail=Sendmail(config.get("administrator", "email")) minimum_confirmations = config.getint("cashier", "minimum_confirmations") alerts_proxy = AlertsProxy(config.get("alerts", "export")) bitgo_config = {'use_production': not config.getboolean("cashier", "testnet"), 'client_id': config.get("bitgo", "client_id"), 'client_secret': config.get("bitgo", "client_secret")} bitgo = BitGo(**bitgo_config) bitgo_private_key_file = config.get("cashier", "bitgo_private_key_file") cashier = Cashier(session, accountant, bitcoinrpc, compropago, cold_wallet_period=cold_wallet_period, sendmail=sendmail, minimum_confirmations=minimum_confirmations, alerts=alerts_proxy, bitgo=bitgo, bitgo_private_key_file=bitgo_private_key_file, testnet=config.getboolean("cashier", "testnet"), ) administrator_export = AdministratorExport(cashier) accountant_export = AccountantExport(cashier) webserver_export = WebserverExport(cashier) watchdog(config.get("watchdog", "cashier")) router_share_async(administrator_export, config.get("cashier", "administrator_export")) pull_share_async(accountant_export, config.get("cashier", "accountant_export")) router_share_async(webserver_export, config.get("cashier", "webserver_export")) public_server = Resource() public_server.putChild('compropago', CompropagoHook(cashier)) private_server = Resource() private_server.putChild('bitcoin', BitcoinNotify(cashier)) if config.getboolean("webserver", "ssl"): key = config.get("webserver", "ssl_key") cert = config.get("webserver", "ssl_cert") cert_chain = config.get("webserver", "ssl_cert_chain") contextFactory = ssl.ChainedOpenSSLContextFactory(key, cert_chain) reactor.listenSSL(config.getint("cashier", "public_port"), Site(public_server), contextFactory, interface=config.get("cashier", "public_interface")) else: reactor.listenTCP(config.getint("cashier", "public_port"), Site(public_server), interface=config.get("cashier", "public_interface")) reactor.listenTCP(config.getint("cashier", "private_port"), Site(private_server), interface=config.get("cashier", "private_interface")) reactor.run()
def main(): log.startLogging(sys.stdout) session = database.make_session() ticker = args[0] try: contract = session.query(models.Contract).filter_by(ticker=ticker).one() except Exception, e: session.rollback() log.err("Cannot determine ticker id. %s" % e) log.err() raise e engine = Engine() administrator_export = AdministratorExport(engine) accountant_port = config.getint("engine", "accountant_base_port") + contract.id administrator_port = config.getint("engine", "administrator_base_port") + contract.id router_share_async(administrator_export, "tcp://127.0.0.1:%d" % administrator_port) logger = LoggingListener(engine, contract) acct = accountant.AccountantProxy("push", config.get("accountant", "engine_export"), config.getint("accountant", "engine_export_base_port")) accountant_notifier = AccountantNotifier(engine, acct, contract) webserver = push_proxy_async(config.get("webserver", "engine_export")) webserver_notifier = WebserverNotifier(engine, webserver, contract) watchdog(config.get("watchdog", "engine") % (config.getint("watchdog", "engine_base_port") + contract.id))
def __init__(self): BackendPlugin.__init__(self) self.proxy = accountant.AccountantProxy( "dealer", config.get("accountant", "webserver_export"), config.getint("accountant", "webserver_export_base_port"))
def __init__(self): BackendPlugin.__init__(self) self.proxy = accountant.AccountantProxy("dealer", config.get("accountant", "webserver_export"), config.getint("accountant", "webserver_export_base_port"))
def main(): log.startLogging(sys.stdout) accountant = AccountantProxy( "dealer", config.get("accountant", "cashier_export"), config.getint("accountant", "cashier_export_base_port")) session = db.make_session() bitcoin_conf = config.get("cashier", "bitcoin_conf") log.msg('connecting to bitcoin client') bitcoinrpc = {'BTC': BitcoinRpc(bitcoin_conf, 1)} compropago = Compropago(config.get("cashier", "compropago_key")) cold_wallet_period = config.getint("cashier", "cold_wallet_period") sendmail = Sendmail(config.get("administrator", "email")) minimum_confirmations = config.getint("cashier", "minimum_confirmations") alerts_proxy = AlertsProxy(config.get("alerts", "export")) bitgo_config = { 'use_production': not config.getboolean("cashier", "testnet"), 'client_id': config.get("bitgo", "client_id"), 'client_secret': config.get("bitgo", "client_secret") } bitgo = BitGo(**bitgo_config) bitgo_private_key_file = config.get("cashier", "bitgo_private_key_file") cashier = Cashier( session, accountant, bitcoinrpc, compropago, cold_wallet_period=cold_wallet_period, sendmail=sendmail, minimum_confirmations=minimum_confirmations, alerts=alerts_proxy, bitgo=bitgo, bitgo_private_key_file=bitgo_private_key_file, testnet=config.getboolean("cashier", "testnet"), ) administrator_export = AdministratorExport(cashier) accountant_export = AccountantExport(cashier) webserver_export = WebserverExport(cashier) watchdog(config.get("watchdog", "cashier")) router_share_async(administrator_export, config.get("cashier", "administrator_export")) pull_share_async(accountant_export, config.get("cashier", "accountant_export")) router_share_async(webserver_export, config.get("cashier", "webserver_export")) public_server = Resource() public_server.putChild('compropago', CompropagoHook(cashier)) private_server = Resource() private_server.putChild('bitcoin', BitcoinNotify(cashier)) if config.getboolean("webserver", "ssl"): key = config.get("webserver", "ssl_key") cert = config.get("webserver", "ssl_cert") cert_chain = config.get("webserver", "ssl_cert_chain") contextFactory = ssl.ChainedOpenSSLContextFactory(key, cert_chain) reactor.listenSSL(config.getint("cashier", "public_port"), Site(public_server), contextFactory, interface=config.get("cashier", "public_interface")) else: reactor.listenTCP(config.getint("cashier", "public_port"), Site(public_server), interface=config.get("cashier", "public_interface")) reactor.listenTCP(config.getint("cashier", "private_port"), Site(private_server), interface=config.get("cashier", "private_interface")) reactor.run()