Example #1
0
def main(port=9000, debug=None):
    """FIX gateway

    Accepts orders over a FIX session.

    """
    if debug:
        logger.setLevel(logging.DEBUG)
        logger.info(f"Logging set to debug.")
    else:
        logger.setLevel(logging.INFO)
        logger.info(f"Logging set to info.")

    settings = fix.SessionSettings("configs/exchange.cfg")
    log = fix.FileLogFactory(settings)
    store = fix.FileStoreFactory(settings)
    app = MessageBroker()
    address = ("localhost", port)

    app.set_logging(logger)

    acceptor = fix.SocketAcceptor(app, store, settings, log)

    try:
        acceptor.start()
        logger.info("FIX.4.2 server started.")

        conn = Client(address, authkey=b"Dj$0.Jkx1@")

        logger.info(f"Started market data publisher at port {port}.")

        while True:
            sleep(1)
            if MARKETS:
                for market in MARKETS:
                    # remove the comment below to print debug orderbook
                    # logger.debug(f"\n{MARKETS[market]._show_orderbook()}")
                    if market in FLUSH_BOOK:
                        bids, asks = MARKETS[market].book()
                        trades = []
                        if FLUSH_BOOK[market]:
                            # trades
                            trades = list(set(FLUSH_BOOK[market]))
                        book = Book(market, bids, asks, trades)
                        conn.send(book)
                        FLUSH_BOOK.pop(market)

    except (fix.ConfigError, fix.RuntimeError) as error:
        raise fix.RuntimeError(error)
    except KeyboardInterrupt:
        logger.info(f"Got signal interrupt, exiting...")
        acceptor.stop()
Example #2
0
def main(port=9000, debug=None):
    """FIX price gateway

    Sends market data snapshot over FIX.

    """
    if debug:
        logger.setLevel(logging.DEBUG)
        logger.info("Logging set to debug.")
    else:
        logger.setLevel(logging.INFO)
        logger.info("Logging set to info.")

    settings = fix.SessionSettings("configs/price.cfg")
    log = fix.FileLogFactory(settings)
    store = fix.FileStoreFactory(settings)
    app = MarketDataAdapter()
    address = ("localhost", port)

    book = Book("Market", [(1, 1)], [(1, 1)], [])

    app.set_logging(logger)

    acceptor = fix.SocketAcceptor(app, store, settings, log)

    try:
        acceptor.start()

        logger.info("FIX.4.2 maarket data server started.")
        logger.debug(f"Starting listener on port {port}.")

        conn = Listener(address, authkey=b"Dj$0.Jkx1@").accept()

        logger.debug(f"Accepted orderbook connection on port {port}.")

        while True:
            book = conn.recv()
            app.dispatch(book)

    except (fix.ConfigError, fix.RuntimeError) as error:
        raise fix.RuntimeError(error)
    except KeyboardInterrupt:
        logger.info(f"Got signal interrupt, exiting...")
        acceptor.stop()
Example #3
0
def main(debug=None):
    """FIX gateway

    Accepts orders over a FIX session.

    """
    if debug:
        logger.setLevel(logging.DEBUG)
        logger.info(f"Logging set to debug.")
    else:
        logger.setLevel(logging.INFO)
        logger.info(f"Logging set to info.")

    settings = fix.SessionSettings("configs/exchange.cfg")
    log = fix.FileLogFactory(settings)
    store = fix.FileStoreFactory(settings)
    app = MessageBroker()

    app.set_logging(logger)

    acceptor = fix.SocketAcceptor(app, store, settings, log)

    try:
        acceptor.start()
        logger.info("FIX4.2 server started.")

        while True:
            sleep(1)
            if MARKETS:
                for market in MARKETS:
                    logger.debug(f"\n{MARKETS[market]._show_orderbook()}")

    except (fix.ConfigError, fix.RuntimeError) as error:
        raise fix.RuntimeError(error)
    except KeyboardInterrupt:
        logger.info(f"Got signal interrupt, exiting...")
        acceptor.stop()