Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
slick::sim::order_gateway::TcpOrderGateway Class Referenceabstract

The transport half of a binary order-entry gateway: a TCP server that hands a venue's protocol whole byte runs, and hands it every engine response, on one thread. More...

#include <order_gateway/tcp_order_gateway.hpp>

Inheritance diagram for slick::sim::order_gateway::TcpOrderGateway:
Collaboration diagram for slick::sim::order_gateway::TcpOrderGateway:

Public Member Functions

 TcpOrderGateway (Venue venue, slick::queue< Request > &request_queue, slick::queue< OrderResponse > &response_queue, const TCPServerConfig &tcp_config)
 ~TcpOrderGateway () override
void start () override
void stop () override
uint16_t listen_port () const noexcept
 The bound port; with a configured port of 0, the one the OS assigned.
void onClientConnected (int client_id, const std::string &client_address)
void onClientDisconnected (int client_id)
void onClientData (int client_id, const uint8_t *data, size_t length)
void onPoll ()
Public Member Functions inherited from slick::sim::order_gateway::OrderGateway
 OrderGateway (Venue venue, slick::queue< Request > &request_queue, slick::queue< OrderResponse > &response_queue)
virtual ~OrderGateway ()=default
slick::queue< Request > & get_request_queue ()
slick::queue< OrderResponse > & get_response_queue ()

Protected Member Functions

virtual void on_connect (int, const std::string &)
virtual void on_disconnect (int)
virtual size_t on_data (int connection_id, const uint8_t *data, size_t size)=0
 Consumes as many whole messages from the front of data as are there and returns how many bytes that was.
virtual void on_response (const OrderResponse &response)=0
 Every response on the venue's response queue, in order.
virtual void on_poll ()
 Once per server loop iteration, after the responses are drained.
bool send (int connection_id, const uint8_t *data, size_t size)
 Server thread only, like everything a protocol does.
void close (int connection_id)
Request & reserve_request ()
void publish_request ()

Additional Inherited Members

Protected Attributes inherited from slick::sim::order_gateway::OrderGateway
Venue venue_
slick::queue< Request > & request_queue_
slick::queue< OrderResponse > & response_queue_

Detailed Description

The transport half of a binary order-entry gateway: a TCP server that hands a venue's protocol whole byte runs, and hands it every engine response, on one thread.

What it does:

  • runs the slick-socket server thread, and nothing else runs gateway code;
  • keeps the unconsumed tail of each connection's stream, so the protocol only ever sees bytes starting at a message boundary;
  • drains response_queue_ on that same thread, from the server loop's onPoll(), so a protocol can answer from on_response with send() - the server only allows sends from its own thread;
  • gives the protocol a two-step publish onto request_queue_.

What it leaves to the venue: framing, sessions, sequencing, and the mapping between wire messages and Request/OrderResponse. A venue derives from this and implements on_data and on_response.

Response latency is the server loop's pace: back to back with TCPServerConfig::cpu_affinity set, up to ~1 ms apart otherwise.

A derived class must call stop() in its own destructor. The server thread calls into the derived class, and by the time this base destructor runs the derived members are already gone.

Definition at line 39 of file tcp_order_gateway.hpp.

Constructor & Destructor Documentation

◆ TcpOrderGateway()

slick::sim::order_gateway::TcpOrderGateway::TcpOrderGateway ( Venue venue,
slick::queue< Request > & request_queue,
slick::queue< OrderResponse > & response_queue,
const TCPServerConfig & tcp_config )

◆ ~TcpOrderGateway()

slick::sim::order_gateway::TcpOrderGateway::~TcpOrderGateway ( )
override

Definition at line 19 of file tcp_order_gateway.cpp.

References stop().

Member Function Documentation

◆ close()

void slick::sim::order_gateway::TcpOrderGateway::close ( int connection_id)
inlineprotected

Definition at line 76 of file tcp_order_gateway.hpp.

◆ listen_port()

uint16_t slick::sim::order_gateway::TcpOrderGateway::listen_port ( ) const
inlinenodiscardnoexcept

The bound port; with a configured port of 0, the one the OS assigned.

Definition at line 52 of file tcp_order_gateway.hpp.

◆ on_connect()

virtual void slick::sim::order_gateway::TcpOrderGateway::on_connect ( int ,
const std::string &  )
inlineprotectedvirtual

Definition at line 61 of file tcp_order_gateway.hpp.

Referenced by onClientConnected().

◆ on_data()

virtual size_t slick::sim::order_gateway::TcpOrderGateway::on_data ( int connection_id,
const uint8_t * data,
size_t size )
protectedpure virtual

Consumes as many whole messages from the front of data as are there and returns how many bytes that was.

The remainder is kept and presented again, at the front, once more bytes arrive.

Referenced by onClientData().

◆ on_disconnect()

virtual void slick::sim::order_gateway::TcpOrderGateway::on_disconnect ( int )
inlineprotectedvirtual

Definition at line 62 of file tcp_order_gateway.hpp.

Referenced by onClientDisconnected().

◆ on_poll()

virtual void slick::sim::order_gateway::TcpOrderGateway::on_poll ( )
inlineprotectedvirtual

Once per server loop iteration, after the responses are drained.

Definition at line 70 of file tcp_order_gateway.hpp.

Referenced by onPoll().

◆ on_response()

virtual void slick::sim::order_gateway::TcpOrderGateway::on_response ( const OrderResponse & response)
protectedpure virtual

Every response on the venue's response queue, in order.

Referenced by onPoll().

◆ onClientConnected()

void slick::sim::order_gateway::TcpOrderGateway::onClientConnected ( int client_id,
const std::string & client_address )

◆ onClientData()

void slick::sim::order_gateway::TcpOrderGateway::onClientData ( int client_id,
const uint8_t * data,
size_t length )

Definition at line 46 of file tcp_order_gateway.cpp.

References on_data().

◆ onClientDisconnected()

void slick::sim::order_gateway::TcpOrderGateway::onClientDisconnected ( int client_id)

◆ onPoll()

void slick::sim::order_gateway::TcpOrderGateway::onPoll ( )

◆ publish_request()

void slick::sim::order_gateway::TcpOrderGateway::publish_request ( )
inlineprotected

◆ reserve_request()

Request & slick::sim::order_gateway::TcpOrderGateway::reserve_request ( )
inlineprotected

◆ send()

bool slick::sim::order_gateway::TcpOrderGateway::send ( int connection_id,
const uint8_t * data,
size_t size )
inlineprotected

Server thread only, like everything a protocol does.

Definition at line 73 of file tcp_order_gateway.hpp.

◆ start()

void slick::sim::order_gateway::TcpOrderGateway::start ( )
overridevirtual

◆ stop()

void slick::sim::order_gateway::TcpOrderGateway::stop ( )
overridevirtual

Implements slick::sim::order_gateway::OrderGateway.

Definition at line 31 of file tcp_order_gateway.cpp.

Referenced by ~TcpOrderGateway().


The documentation for this class was generated from the following files: