Add basic server setup
Add a command line tool to start a simple one node server setup of the exchange
This commit is contained in:
parent
84b0cb9540
commit
ede4916284
22
exe/rex-server
Executable file
22
exe/rex-server
Executable file
@ -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
|
||||
}
|
@ -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"
|
||||
|
54
lib/rex/server/simple_server_setup.rb
Normal file
54
lib/rex/server/simple_server_setup.rb
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user