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(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()
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)) forwarder = connect_publisher(config.get("safe_price_forwarder", "zmq_frontend_address")) safe_price_notifier = SafePriceNotifier(session, engine, acct, webserver, forwarder, contract) accountant_export = AccountantExport(engine, safe_price_notifier, webserver_notifier) router_share_async(accountant_export, "tcp://127.0.0.1:%d" % accountant_port) engine.add_listener(logger) engine.add_listener(accountant_notifier) engine.add_listener(webserver_notifier) engine.add_listener(safe_price_notifier) # Cancel all orders with some quantity_left that have been dispatched but not cancelled try: for order in session.query(models.Order).filter_by(
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()