diff --git a/exe/rex-server b/exe/rex-server new file mode 100755 index 0000000..7a20618 --- /dev/null +++ b/exe/rex-server @@ -0,0 +1,22 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "bundler/setup" +require "rex" + +puts <<~STR + __ + / _) + _.----._/ / + / / + __/ ( | ( | + /__.-'|_|--|_| + + Ruby Exchange (Rex) + Author: Tim Kächele + License: AGPLv3 +STR + +EM.run { + Rex::Server::SimpleServerSetup.new(ARGV[0], ARGV[1].to_i).start +} diff --git a/lib/rex/server.rb b/lib/rex/server.rb index c24891f..fffd5ef 100644 --- a/lib/rex/server.rb +++ b/lib/rex/server.rb @@ -13,6 +13,8 @@ require_relative "server/message_processor" require_relative "server/websocket_server" require_relative "server/json_message_serializer" +require_relative "server/simple_server_setup" + module Rex module Server VERSION = "0.1.0" diff --git a/lib/rex/server/simple_server_setup.rb b/lib/rex/server/simple_server_setup.rb new file mode 100644 index 0000000..c63b855 --- /dev/null +++ b/lib/rex/server/simple_server_setup.rb @@ -0,0 +1,54 @@ +module Rex + module Server + # Implementation of a simple one node server setup + # + # Setups/Starts + # + # - a message processor to parse and forward + # messages to the matching engine + # - a matching engine instance to process any order book related + # messages + # - a websocket server to accept websocket base connections and + # process incoming messages + class SimpleServerSetup + def initialize(host, port) + matching_engine_inbox_pipe = EventMachine::Channel.new + matching_engine_outbox_pipe = EventMachine::Channel.new + + @matching_engine = MatchingEngine.new( + matching_engine_inbox_pipe, + matching_engine_outbox_pipe + ) + + message_processor_inflow_pipe = EventMachine::Channel.new + message_broker = MessageBroker.new(JsonMessageSerializer.new) + + @message_processor = Rex::Server::MessageProcessor.new( + matching_engine_inbox_pipe, + matching_engine_outbox_pipe, + message_broker, + message_processor_inflow_pipe + ) + + @websocket_server = Rex::Server::WebsocketServer.new( + message_broker, + message_processor_inflow_pipe, + host: host, + port: port + ) + end + + def start + @message_processor.start + @matching_engine.start + @websocket_server.start + end + + def stop + @matching_engine.stop + @message_processor.stop + @websocket_server.stop + end + end + end +end