Compare commits
10
Commits
2.17.0_rc8
..
0.6.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e974edfc6e | ||
|
|
3b7740cee0 | ||
|
|
258d4a3fc1 | ||
|
|
c53f6425cd | ||
|
|
e5d77593d1 | ||
|
|
6580f3883b | ||
|
|
a66eae66bb | ||
|
|
090a9dfb17 | ||
|
|
27aa43f44d | ||
|
|
19e087aa69 |
No files matched your search
@@ -37,3 +37,4 @@ trace_data/
|
||||
*.rej
|
||||
/build
|
||||
.clangd/
|
||||
*CMakeDeps.cmake
|
||||
@@ -1 +1 @@
|
||||
set(sources /home/ppinto/Dropbox/bts/spark/doc/user/build.sh;content/_index.md;content/bts_spark/Glossary/_index.md;content/bts_spark/Help/_index.md;content/bts_spark/Help/about_spark.png;content/bts_spark/Help/image39.png;content/bts_spark/Help/image58.png;content/bts_spark/Launcher/_index.md;content/bts_spark/Launcher/image38.png;content/bts_spark/Launcher/image68.png;content/bts_spark/Logging-In-to-the-System/_index.md;content/bts_spark/Logging-In-to-the-System/image3.png;content/bts_spark/Logging-In-to-the-System/image64.png;content/bts_spark/Market/_index.md;content/bts_spark/Market/change_securities.png;content/bts_spark/Market/image11.png;content/bts_spark/Market/image14.png;content/bts_spark/Market/image20.png;content/bts_spark/Market/image21.png;content/bts_spark/Market/image23.png;content/bts_spark/Market/image24.png;content/bts_spark/Market/image34.png;content/bts_spark/Market/image49.png;content/bts_spark/Market/image53.png;content/bts_spark/Market/image66.png;content/bts_spark/Market/image69.png;content/bts_spark/Market/market_view.png;content/bts_spark/Market/settings_icon.png;content/bts_spark/Market/time_and_sales.png;content/bts_spark/My-Windows/_index.md;content/bts_spark/My-Windows/image15.png;content/bts_spark/My-Windows/image16.png;content/bts_spark/My-Windows/image37.png;content/bts_spark/Settings/_index.md;content/bts_spark/Settings/image51.png;content/bts_spark/Settings/image9.png;content/bts_spark/Spreader/_index.md;content/bts_spark/Spreader/image10.png;content/bts_spark/Spreader/image13.png;content/bts_spark/Spreader/image18.png;content/bts_spark/Spreader/image19.png;content/bts_spark/Spreader/image28.png;content/bts_spark/Spreader/image29.png;content/bts_spark/Spreader/image31.png;content/bts_spark/Spreader/image35.png;content/bts_spark/Spreader/image40.png;content/bts_spark/Spreader/image43.png;content/bts_spark/Spreader/image54.png;content/bts_spark/Spreader/image55.png;content/bts_spark/Spreader/image56.png;content/bts_spark/Spreader/image6.png;content/bts_spark/Spreader/image7.png;content/bts_spark/Spreader/image70.png;content/bts_spark/Spreader/image72.png;content/bts_spark/Spreader/image8.png;content/bts_spark/Trading/OrderTypes/index.md;content/bts_spark/Trading/_index.md;content/bts_spark/Trading/algo_studio.png;content/bts_spark/Trading/collapse_all_icon.png;content/bts_spark/Trading/cover_algo_control.png;content/bts_spark/Trading/expand_all_icon.png;content/bts_spark/Trading/image1.png;content/bts_spark/Trading/image17.png;content/bts_spark/Trading/image2.png;content/bts_spark/Trading/image25.png;content/bts_spark/Trading/image27.png;content/bts_spark/Trading/image33.png;content/bts_spark/Trading/image42.png;content/bts_spark/Trading/image44.png;content/bts_spark/Trading/image47.png;content/bts_spark/Trading/image48.png;content/bts_spark/Trading/image5.png;content/bts_spark/Trading/image50.png;content/bts_spark/Trading/image52.png;content/bts_spark/Trading/image57.png;content/bts_spark/Trading/image59.png;content/bts_spark/Trading/image60.png;content/bts_spark/Trading/image61.png;content/bts_spark/Trading/image62.png;content/bts_spark/Trading/image73.png;content/bts_spark/Trading/image74.png;content/bts_spark/Trading/join_algo_control.png;content/bts_spark/Trading/ladder.png;content/bts_spark/Trading/ladder_badges.png;content/bts_spark/Trading/ladder_main_part.png;content/bts_spark/Trading/lean_algo_control.png;content/bts_spark/Trading/mini_orderbook.png;content/bts_spark/Trading/oco_algo_control.png;content/bts_spark/Trading/offset_algo_control.png;content/bts_spark/Trading/pnl_calculation.png;content/bts_spark/Trading/pnl_window.png;content/bts_spark/Trading/recreate_icon.png;content/bts_spark/Trading/settings_icon.png;content/bts_spark/Trading/spark_menu_order_book.png;content/bts_spark/Trading/top_algo_control.png;content/bts_spark/Trading/trigger_algo_control.png;content/bts_spark/_index.md;content/release_notes/_index.md;content/system_requirements/_index.md;static/book.js;static/favicon.ico;static/image.js;templates/index.html;templates/page.html;templates/section.html;templates/shortcodes/back_button.html)
|
||||
set(sources /home/pfisher/bts/spark/doc/user/build.sh;content/_index.md;content/bts_spark/Glossary/_index.md;content/bts_spark/Help/_index.md;content/bts_spark/Help/about_spark.png;content/bts_spark/Help/image39.png;content/bts_spark/Help/image58.png;content/bts_spark/Launcher/_index.md;content/bts_spark/Launcher/image38.png;content/bts_spark/Launcher/image68.png;content/bts_spark/Logging-In-to-the-System/_index.md;content/bts_spark/Logging-In-to-the-System/image3.png;content/bts_spark/Logging-In-to-the-System/image64.png;content/bts_spark/Market/_index.md;content/bts_spark/Market/change_securities.png;content/bts_spark/Market/image11.png;content/bts_spark/Market/image14.png;content/bts_spark/Market/image20.png;content/bts_spark/Market/image21.png;content/bts_spark/Market/image23.png;content/bts_spark/Market/image24.png;content/bts_spark/Market/image34.png;content/bts_spark/Market/image49.png;content/bts_spark/Market/image53.png;content/bts_spark/Market/image66.png;content/bts_spark/Market/image69.png;content/bts_spark/Market/market_view.png;content/bts_spark/Market/settings_icon.png;content/bts_spark/Market/time_and_sales.png;content/bts_spark/My-Windows/_index.md;content/bts_spark/My-Windows/image15.png;content/bts_spark/My-Windows/image16.png;content/bts_spark/My-Windows/image37.png;content/bts_spark/Settings/_index.md;content/bts_spark/Settings/image51.png;content/bts_spark/Settings/image9.png;content/bts_spark/Spreader/_index.md;content/bts_spark/Spreader/image10.png;content/bts_spark/Spreader/image13.png;content/bts_spark/Spreader/image18.png;content/bts_spark/Spreader/image19.png;content/bts_spark/Spreader/image28.png;content/bts_spark/Spreader/image29.png;content/bts_spark/Spreader/image31.png;content/bts_spark/Spreader/image35.png;content/bts_spark/Spreader/image40.png;content/bts_spark/Spreader/image43.png;content/bts_spark/Spreader/image54.png;content/bts_spark/Spreader/image55.png;content/bts_spark/Spreader/image56.png;content/bts_spark/Spreader/image6.png;content/bts_spark/Spreader/image7.png;content/bts_spark/Spreader/image70.png;content/bts_spark/Spreader/image72.png;content/bts_spark/Spreader/image8.png;content/bts_spark/Trading/OrderTypes/index.md;content/bts_spark/Trading/_index.md;content/bts_spark/Trading/algo_studio.png;content/bts_spark/Trading/collapse_all_icon.png;content/bts_spark/Trading/cover_algo_control.png;content/bts_spark/Trading/expand_all_icon.png;content/bts_spark/Trading/image1.png;content/bts_spark/Trading/image17.png;content/bts_spark/Trading/image2.png;content/bts_spark/Trading/image25.png;content/bts_spark/Trading/image27.png;content/bts_spark/Trading/image33.png;content/bts_spark/Trading/image42.png;content/bts_spark/Trading/image44.png;content/bts_spark/Trading/image47.png;content/bts_spark/Trading/image48.png;content/bts_spark/Trading/image5.png;content/bts_spark/Trading/image50.png;content/bts_spark/Trading/image52.png;content/bts_spark/Trading/image57.png;content/bts_spark/Trading/image59.png;content/bts_spark/Trading/image60.png;content/bts_spark/Trading/image61.png;content/bts_spark/Trading/image62.png;content/bts_spark/Trading/image73.png;content/bts_spark/Trading/image74.png;content/bts_spark/Trading/join_algo_control.png;content/bts_spark/Trading/ladder.png;content/bts_spark/Trading/ladder_badges.png;content/bts_spark/Trading/ladder_main_part.png;content/bts_spark/Trading/lean_algo_control.png;content/bts_spark/Trading/mini_orderbook.png;content/bts_spark/Trading/oco_algo_control.png;content/bts_spark/Trading/offset_algo_control.png;content/bts_spark/Trading/pnl_calculation.png;content/bts_spark/Trading/pnl_window.png;content/bts_spark/Trading/recreate_icon.png;content/bts_spark/Trading/settings_icon.png;content/bts_spark/Trading/spark_menu_order_book.png;content/bts_spark/Trading/top_algo_control.png;content/bts_spark/Trading/trigger_algo_control.png;content/bts_spark/_index.md;content/release_notes/_index.md;content/system_requirements/_index.md;static/book.js;static/favicon.ico;static/image.js;templates/index.html;templates/page.html;templates/section.html;templates/shortcodes/back_button.html)
|
||||
+1
-1
Submodule docker/linux updated: 6f0dd9324b...7258a028d7.
@@ -48,7 +48,7 @@ def get_value(json_key):
|
||||
# Column 1 - Sending Timestamps
|
||||
def SendingTimeEpoch(epochtime): #1
|
||||
#TIME = time.strftime('%Y%m%d-%H:%M:%S.{}'.format(epochtime/1000000000), time.gmtime(epochtime/1000000000))
|
||||
TIME = datetime.datetime.fromtimestamp(epochtime/1000000000).strftime('%Y%m%d-%H:%M:%S.%f')
|
||||
TIME = datetime.datetime.fromtimestamp(int(epochtime) / 1e9).strftime('%Y%m%d-%H:%M:%S.%f')
|
||||
return TIME
|
||||
|
||||
# Column 2 - Message Direction
|
||||
@@ -402,4 +402,4 @@ with file_opener(args.json_log) as json_file:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -319,7 +319,7 @@ if __name__ == "__main__":
|
||||
|
||||
if DEBUG:
|
||||
for f in response.file:
|
||||
print f.content
|
||||
print (f.content)
|
||||
else:
|
||||
output = response.SerializeToString()
|
||||
sys.stdout.write(output)
|
||||
|
||||
+28
-3
@@ -60,10 +60,13 @@ class IntPrice {
|
||||
return delta.mantissa() < 0;
|
||||
}
|
||||
}
|
||||
bool operator <=(const IntPrice& other) {
|
||||
bool operator <=(const IntPrice& other) const {
|
||||
return *this == other || *this < other;
|
||||
}
|
||||
bool operator >=(const IntPrice& other) {
|
||||
bool operator >(const IntPrice& other) const {
|
||||
return other < *this;
|
||||
}
|
||||
bool operator >=(const IntPrice& other) const {
|
||||
return !(*this < other);
|
||||
}
|
||||
IntPrice operator - (const IntPrice& o) const {
|
||||
@@ -72,9 +75,31 @@ class IntPrice {
|
||||
IntPrice operator + (const IntPrice& o) const {
|
||||
return op(o, [](int64_t m1, int64_t m2) { return m1 + m2; });
|
||||
}
|
||||
IntPrice& operator +=(const IntPrice& o) {
|
||||
auto temp = *this + o;
|
||||
_mantissa = temp._mantissa;
|
||||
_exponent = temp._exponent;
|
||||
return *this;
|
||||
}
|
||||
IntPrice& operator -=(const IntPrice& o) {
|
||||
auto temp = *this - o;
|
||||
_mantissa = temp._mantissa;
|
||||
_exponent = temp._exponent;
|
||||
return *this;
|
||||
}
|
||||
IntPrice operator -() {
|
||||
return IntPrice(-_mantissa, _exponent);
|
||||
}
|
||||
IntPrice operator * (const IntPrice& other) const {
|
||||
return op(other, [](int64_t m1, int64_t m2) { return m1 * m2; });
|
||||
}
|
||||
IntPrice operator * (const int& other) const {
|
||||
return IntPrice(_mantissa * other, _exponent);
|
||||
}
|
||||
IntPrice& operator *=(const int& other) {
|
||||
_mantissa *= other;
|
||||
return *this;
|
||||
}
|
||||
IntPrice operator / (double v) const {
|
||||
return { (int64_t)(_mantissa / v), exponent() };
|
||||
}
|
||||
@@ -183,4 +208,4 @@ inline std::ostream& operator<<(std::ostream& os, const IntPrice& p) {
|
||||
return os;
|
||||
}
|
||||
|
||||
}}
|
||||
}}
|
||||
@@ -235,7 +235,7 @@ void GLBXiLink3ExecutionGateway::on_admin_data(
|
||||
const mercury::Update<NewAdminDataEvent> &) {}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::send_msgs(std::vector<OrderMsg> const &msgs,
|
||||
trace::CorID) {
|
||||
trace::CorID corid) {
|
||||
|
||||
if (me->state == State::READY) {
|
||||
for (auto &m : msgs) {
|
||||
@@ -248,6 +248,11 @@ void GLBXiLink3ExecutionGateway::send_msgs(std::vector<OrderMsg> const &msgs,
|
||||
// CancelReplace
|
||||
auto cancel_replace_ptr = std::get_if<CancelReplaceOrderMsg>(&m);
|
||||
if (cancel_replace_ptr) {
|
||||
LOG(iLink3,Info,"Cancel Replace. CorID:{}.{} Order:{}",
|
||||
log::CharPtrWrapper{corid.channel},
|
||||
corid.sn,
|
||||
cancel_replace_ptr->exchange_order_id);
|
||||
|
||||
me->gw->send_cancel_replace(*cancel_replace_ptr);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ struct TimeKeeper {
|
||||
uint64_t now() const {
|
||||
auto now = utils::TimeStamp::now();
|
||||
auto delta = now - start;
|
||||
return unix_time + delta.microseconds();
|
||||
return unix_time + delta.nanoseconds();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
* iLink3 Reference Documentation
|
||||
** Overview
|
||||
The iLink3 work leverages and extends the iLink2 functionality. Most of the order management logic is unchanged from iLink2 with the substantial changes being confined to session management and encoding/decoding. In an effort to facilitate future addition of new execution protocols a set of protocol independent data structures and methods was added.
|
||||
** Main classes
|
||||
*** GLBXNativeorder
|
||||
GLBXNativeOrder implements the common iLink2 and iLink3 order management logic, including status updates, buffering of cancel/updates, recovery from disk, handling of execution reports, special order handling and routing. This is essentially unchanged from iLink2. From the point of view of this class the differences between iLink2 and iLink2 are delegated to the IGLBXOrderEncoder interface. At run time depending on the type of connection used an implementation of this interface for iLink2 or iLink3 is selected.
|
||||
*** IGLBXOrderEncoder
|
||||
Implementations of the IGLBXOrderEncoder interface below realize wire protocol specific implementations of encoding allowing GLBXNativeOrder to manage both iLink2 and iLink3 orders. The interface provides methods for creating,updating, canceling and dispatching orders. Currently there are two concrete implementations of this interface: iLink2OrderEncoder and iLink3OrderEncoder.
|
||||
|
||||
#+BEGIN_SRC c++
|
||||
class IGLBXOrderEncoder {
|
||||
public:
|
||||
virtual ~IGLBXOrderEncoder() {}
|
||||
virtual void init(OrderKey key, api::orderman::RoutingRecord const &,
|
||||
api::Security const &security,
|
||||
api::orderman::OrderDefinition const &def,
|
||||
int price_encoding_precision,
|
||||
bool stop_order_has_been_triggered) = 0;
|
||||
|
||||
virtual void update_exchange_order_id(ExchangeOrderIDVar const&) = 0;
|
||||
|
||||
virtual void update_create_order_encoding(Price p, int price_precision,
|
||||
Quantity q, OrderServices &) = 0;
|
||||
|
||||
virtual void update_cancel_replace_stop_px(Price stop_px,
|
||||
int price_precision) = 0;
|
||||
virtual void update_cancel_replace_max_show(Quantity max_show) = 0;
|
||||
virtual void update_cancel_replace_encoding(Price p, int price_precision,
|
||||
Quantity q, OrderServices &) = 0;
|
||||
virtual void update_cancel_replace_encoding(Quantity q, OrderServices &) = 0;
|
||||
virtual void update_cancel_replace_encoding(Price p,
|
||||
int price_precision,
|
||||
OrderServices &) = 0;
|
||||
virtual void update_cancel_encoding(OrderServices&) = 0;
|
||||
virtual void send_create(OrderServices&,SessionServices&) = 0;
|
||||
virtual void send_cancel_replace(OrderServices&,SessionServices&) = 0;
|
||||
virtual void send_cancel(OrderServices&,SessionServices&) = 0;
|
||||
};
|
||||
|
||||
#+END_SRC
|
||||
*** class iLink2OrderEncoder : public IGLBXOrderEncoder
|
||||
iLink2OrderEncoder provides FIX based encoding of GLBX orders. This logic is carried over essentially unchanged from previous versions of Spark with care being taken to re-use as much as possible elements of previous encodings on every call. The generated FIX messages are forwarded, as FIX, to the OrderServices::queue_fix template member function:
|
||||
|
||||
#+BEGIN_SRC c++
|
||||
void queue_fix(SessionServices &ss, jetfix::MessageTypes mt,
|
||||
jetfix::FIXFragment const &f) {
|
||||
ss.queue_fix(mt, f, corid());
|
||||
}
|
||||
#+END_SRC
|
||||
|
||||
*** class iLink3OrderEncoder : public IGLBXOrderEncoder
|
||||
iLink3OrderEncoder provides a thin adapter that accepts order encoding requests from GLBXNativeOrder and maps those requests to the protocol agnostic order management data structures: CreateOrderMsg, CancelReplaceOrderMsg and CancelOrderMsg.
|
||||
|
||||
After this mapping, iLink3OrderEncoder forwards the order operation in question to its OrderServices instance, through the protocol independent queue_order_msg template function:
|
||||
|
||||
#+BEGIN_SRC c++
|
||||
template <class OP>
|
||||
void queue_order_msg (SessionServices &ss, OP const&msg) {
|
||||
ss.queue_order_msg(msg,corid());
|
||||
}
|
||||
#+END_SRC
|
||||
|
||||
*** Protocol independent order operation data structures
|
||||
The simple data structures in IExecutionGateway.h provide an exchange protocol independent way of representing order operations. They are intended to facilitate the addition of new exchange protocols. They are as follows:
|
||||
|
||||
#+BEGIN_SRC c++
|
||||
struct CreateOrderMsg {
|
||||
OrderKey key;
|
||||
Price price;
|
||||
Quantity quantity;
|
||||
api::Security const *security;
|
||||
api::Side side;
|
||||
Price stop_px;
|
||||
Quantity display_quantity;
|
||||
api::orderman::NativeOrderType order_type;
|
||||
api::orderman::TimeInForce time_in_force;
|
||||
api::orderman::ManualOrderIndicator manual_order_indicator;
|
||||
api::orderman::RoutingRecord const *routing_record;
|
||||
};
|
||||
|
||||
struct CancelReplaceOrderMsg {
|
||||
CreateOrderMsg create_fields;
|
||||
ExchangeOrderID64 exchange_order_id;
|
||||
};
|
||||
|
||||
struct CancelOrderMsg {
|
||||
OrderKey key;
|
||||
ExchangeOrderID64 exchange_order_id;
|
||||
api::orderman::ManualOrderIndicator manual_order_indicator;
|
||||
api::Security const *security;
|
||||
api::orderman::RoutingRecord const *routing_record;
|
||||
api::Side side;
|
||||
};
|
||||
|
||||
using OrderMsg =
|
||||
std::variant<CreateOrderMsg, CancelReplaceOrderMsg, CancelOrderMsg>;
|
||||
|
||||
#+END_SRC
|
||||
|
||||
These data structures are used as vocabulary data types understood by all future exchange execution implementation code. They are consumed by implementations of the IExecutionGateway interface.
|
||||
|
||||
*** class IExecutionGateway
|
||||
IExecutionGateway provides an abstraction for the implementation of exchange gateways. It provides methods for both FIX and non FIX based exchanges. Ordinarily implementations of this interface will either provide FIX or non FIX functionality but not both.
|
||||
|
||||
#+BEGIN_SRC c++
|
||||
class IExecutionGateway {
|
||||
public:
|
||||
IExecutionGateway() = default;
|
||||
virtual ~IExecutionGateway() {}
|
||||
|
||||
virtual void start() = 0;
|
||||
virtual void dispatch_incoming_fix_messages() = 0;
|
||||
virtual void on_securities(const mercury::Update<NewSecuritiesEvent> &) = 0;
|
||||
virtual void on_admin_data(const mercury::Update<NewAdminDataEvent> &) = 0;
|
||||
virtual void send_fix(const jetfix::OutFIXPtr&, trace::CorID) = 0;
|
||||
virtual void send_msgs(std::vector<OrderMsg> const&, trace::CorID) = 0;
|
||||
virtual OnExeReport& on_exe_report() = 0;
|
||||
virtual OnGwStatusChange& on_gw_status_change() = 0;
|
||||
virtual OnCancelReject &on_cancel_reject() = 0;
|
||||
private:
|
||||
BTS_NO_COPY(IExecutionGateway);
|
||||
};
|
||||
#+END_SRC
|
||||
|
||||
IExecutionGateway implements are responsible for establishing execution sessions as well as mapping to and from protocol independent order operations to their gateway specific implementations. Presently there are three implementations of IExecutionGateway: ICE, iLink2 and iLink3. Only the iLink3 implementation is new.
|
||||
|
||||
*** class GLBXiLink3ExecutionGateway : public IExecutionGateway
|
||||
This class implements provides a facade that hides, coordinates and interfaces with all the components needed to implement an iLink3 gateway including a TCP connection, a persistent store and the actual iLink3 encoding/decoding logic. GLBXiLink3ExecutionGateway role is identical to those of the GLBXExecutionGateway and ICEExecutionGateway, which existed prior to iLink3. In essence GLBXilink3executiongateway is in charge of managing the life-cycle of an iLink3 exchange connection as well as translating between exchange agnostic order operations and the iLink3 specific interfaces. The actual exchange interaction is delegated to the IL3GW class.
|
||||
*** class IL3GW : IL3ConnectionHandler
|
||||
The IL3GW class is responsible for iLink3 session management, including login, logout, recovery and heartbeat response. Additionally this class is responsible for mapping order messages to and from their network binary representation. This class is able to handle network events including connection, disconnection and data arrival via its implementation of the IL3ConnectionHandler interface:
|
||||
|
||||
|
||||
#+BEGIN_SRC c++
|
||||
struct IL3ConnectionHandler {
|
||||
virtual ~IL3ConnectionHandler() ;
|
||||
virtual void on_connect_success() = 0;
|
||||
virtual void on_disconnect() = 0;
|
||||
// Send available data and length. Handler will return what it consumed
|
||||
virtual size_t on_data(const std::string_view&) = 0;
|
||||
};
|
||||
#+END_SRC
|
||||
|
||||
IL3GW integrates these external events with the instructions it receives from the rest of the system through its public interface:
|
||||
|
||||
#+BEGIN_SRC c++
|
||||
void connect();
|
||||
void send_order(const CreateOrderMsg &);
|
||||
void send_cancel_replace(const CancelReplaceOrderMsg &);
|
||||
void send_cancel(const CancelOrderMsg &);
|
||||
void send_terminate(uint16_t code = 0);
|
||||
#+END_SRC
|
||||
|
||||
And provides an integrated high-level view of the connection state via its event callbacks:
|
||||
|
||||
#+BEGIN_SRC c++
|
||||
void subscribe_state(OnStateChange o);
|
||||
void subscribe_execution_reports(OnExecutionReport sub);
|
||||
void subscribe_session(OnSessionChange cb);
|
||||
void subscribe_cancel_reject(OnCancelReject cb);
|
||||
#+END_SRC
|
||||
|
||||
** Code Generation
|
||||
To facilitate encoding IL3GW uses code generated by the CME sponsored tools by real logic. These tools can be found here:
|
||||
|
||||
https://github.com/real-logic/simple-binary-encoding/wiki/Sbe-Tool-Guide
|
||||
|
||||
The CME provides template files that be used as an input to these tools. For more details see:
|
||||
|
||||
https://www.cmegroup.com/confluence/display/EPICSANDBOX/iLink+3+-+Simple+Binary+Encoding
|
||||
|
||||
The generation was done manually and the generated code integrated into source control.
|
||||
|
||||
** Operational Notes
|
||||
- Like iLink2, the iLink3 implementation uses weekly sessions
|
||||
- Sessions are stored under sparkdata/ilink3/session_name/date-of-session
|
||||
- Within each session directory there are two files:
|
||||
- log: is a json log of all messages sent and received from the exchange
|
||||
- seqnum: contains the current sequence numbers for the session. Additionally the session binary name is also represented for use in trouble-shooting
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "BookUtils.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
using Size = bts::md::Size;
|
||||
using Side = bts::api::Side;
|
||||
namespace bts::orderman {
|
||||
using Size = md::Size;
|
||||
using Side = api::Side;
|
||||
using PriceSize = md::PriceSize;
|
||||
|
||||
Size BookUtils::volume_at_or_better(const Book& book, Side side, Price price) {
|
||||
return volume_at_or_better(book, side, price.value());
|
||||
@@ -22,5 +22,154 @@ Size BookUtils::volume_at_or_better(const Book& book, Side side, double price) {
|
||||
SidePriceComp BookUtils::price_comp(Side side) {
|
||||
return SidePriceComp(side);
|
||||
}
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
|
||||
inline bool is_empty(const PriceSize& ps) {
|
||||
return ps.size() == 0 || ps.int_price().is_nan();
|
||||
}
|
||||
|
||||
void BookUtils::change_unit_qty(
|
||||
const BookSide& book_in, std::vector<md::PriceSize>& book_out, int unit_qty) {
|
||||
//
|
||||
bts_assert(unit_qty > 0);
|
||||
int mlev = 0, mlev_qty_used = 0;
|
||||
std::vector<md::PriceSize> unit_lev_span;
|
||||
for (uint32_t i = 0; i < book_in.size();) {
|
||||
int mlev_qty_rem = book_in[i].size() - mlev_qty_used;
|
||||
if (mlev_qty_rem == 0) {
|
||||
mlev_qty_used = 0;
|
||||
mlev++;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if (unit_lev_span.size() == 0) {
|
||||
md::Size mlev_units_rem = mlev_qty_rem / unit_qty;
|
||||
if (mlev_units_rem > 0) {
|
||||
book_out.emplace_back(book_in[i].int_price(), mlev_units_rem);
|
||||
mlev_qty_used += mlev_units_rem * unit_qty;
|
||||
} else {
|
||||
unit_lev_span.emplace_back(book_in[i].int_price(), mlev_qty_rem);
|
||||
mlev_qty_used = 0;
|
||||
mlev++;
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
// the unit spans across multiple [input]price levels: compute its
|
||||
// [output]price. It will be in its own [output]price level.
|
||||
auto unit_rem = unit_qty;
|
||||
for (auto lev : unit_lev_span)
|
||||
unit_rem -= lev.size();
|
||||
if (mlev_qty_rem >= unit_rem) {
|
||||
mlev_qty_used += unit_rem;
|
||||
auto unit_price = md::INT_NAN;
|
||||
for (uint32_t adj_lev = 0; adj_lev < unit_lev_span.size(); adj_lev++) {
|
||||
auto leg_price = unit_lev_span[adj_lev].int_price() *
|
||||
static_cast<int>(unit_lev_span[adj_lev].size());
|
||||
if (unit_price.is_nan())
|
||||
unit_price = leg_price;
|
||||
else
|
||||
unit_price += leg_price;
|
||||
}
|
||||
unit_lev_span.clear();
|
||||
book_out.emplace_back(unit_price, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BookUtils::compute_synthetic_book(
|
||||
std::vector<PriceSize>& dest,
|
||||
const std::vector<std::tuple<Size, md::IntPrice, BookSide>>&
|
||||
leg_mkts,
|
||||
uint32_t depth) {
|
||||
//
|
||||
if (leg_mkts.size() == 0)
|
||||
return;
|
||||
|
||||
struct Leg {
|
||||
std::vector<PriceSize> book;
|
||||
uint32_t curr_level;
|
||||
Size curr_level_qty_used;
|
||||
int leg_qty;
|
||||
|
||||
Leg() : book(), curr_level(0), curr_level_qty_used(0), leg_qty(0) {}
|
||||
|
||||
md::IntPrice curr_price() const {
|
||||
// Assert that the book isn't 'empty' yet.
|
||||
// Note: one could argue that nan be returned in this event,
|
||||
// but since the loop is designed to return "greedily,"
|
||||
// 'curr_price' should not be accessed after it has been emptied.
|
||||
// This assertion enforces that the behavior is only changed
|
||||
// as a result of deliberate action, rather than an inadvertant
|
||||
// side-effect.
|
||||
bts_assert(!is_empty());
|
||||
return book[curr_level].int_price();
|
||||
}
|
||||
Size curr_level_qty_rem() const {
|
||||
return book[curr_level].size() - curr_level_qty_used;
|
||||
}
|
||||
// The implied market's volume is limited by its thinnest market.
|
||||
// When one leg 'is_empty,' the full volume of the implied market
|
||||
// has been realized.
|
||||
bool is_empty() const { return curr_level >= book.size(); }
|
||||
};
|
||||
|
||||
std::vector<Leg> legs;
|
||||
for (const auto& [qty, price_mult, book] : leg_mkts) {
|
||||
// todo: implement price mult logic (for now just assert nan or 1)
|
||||
bts_assert(price_mult.is_nan() || price_mult.price() == 1);
|
||||
auto& l = legs.emplace_back();
|
||||
bts_assert(qty != 0);
|
||||
l.leg_qty = qty;
|
||||
if (book.empty() || is_empty(book.front()))
|
||||
return;
|
||||
change_unit_qty(
|
||||
book, l.book, std::abs(l.leg_qty));
|
||||
if (l.book.empty())
|
||||
return;
|
||||
}
|
||||
|
||||
auto any_legs_empty = [&]() {
|
||||
for (auto& l : legs)
|
||||
if (l.is_empty())
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
while (!any_legs_empty() && depth-- > 0) {
|
||||
// legs can't be empty, because it is a 1:1 mapping of leg_mkts,
|
||||
// and it has already been established that the latter isn't empty.
|
||||
auto limiting_factor = legs[0].curr_level_qty_rem();
|
||||
for (uint32_t i = 0; i < legs.size(); i++) {
|
||||
if (legs[i].curr_level_qty_rem() == 0) {
|
||||
legs[i].curr_level++;
|
||||
if (legs[i].is_empty()) {
|
||||
// book is complete
|
||||
return;
|
||||
}
|
||||
legs[i].curr_level_qty_used = Size(0);
|
||||
}
|
||||
limiting_factor =
|
||||
std::min(legs[i].curr_level_qty_rem(), limiting_factor);
|
||||
if (limiting_factor == 0)
|
||||
return;
|
||||
}
|
||||
bts_assert(limiting_factor > 0);
|
||||
for (uint32_t i = 0; i < legs.size(); i++)
|
||||
legs[i].curr_level_qty_used += limiting_factor;
|
||||
auto marginal_cost = md::INT_NAN;
|
||||
for (auto& l : legs) {
|
||||
// The book's prices have already been multiplied by abs(leg_qty);
|
||||
// Subtract the leg's cost if qty is negative, otherwise add it
|
||||
// to the synthetic's marginal cost.
|
||||
auto lcost = l.curr_price();
|
||||
if (l.leg_qty < 0)
|
||||
lcost = -lcost;
|
||||
if (marginal_cost.is_nan())
|
||||
marginal_cost = lcost;
|
||||
else
|
||||
marginal_cost += lcost;
|
||||
}
|
||||
dest.emplace_back(marginal_cost, limiting_factor);
|
||||
}
|
||||
}
|
||||
} // namespace bts::orderman
|
||||
@@ -6,13 +6,18 @@
|
||||
#include "lib/orderman/orderman_utils/Book.h"
|
||||
#include "lib/orderman/orderman_utils/PriceComp.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
namespace bts::orderman {
|
||||
struct BookUtils {
|
||||
static md::Size volume_at_or_better(const Book& book, api::Side side, Price price);
|
||||
static md::Size volume_at_or_better(const Book& book, api::Side side, double price);
|
||||
static SidePriceComp price_comp(api::Side side);
|
||||
|
||||
static void change_unit_qty(
|
||||
const BookSide& book_in, std::vector<md::PriceSize>& book_out, int unit_qty);
|
||||
|
||||
static void compute_synthetic_book(
|
||||
std::vector<md::PriceSize>& dest,
|
||||
const std::vector<std::tuple<md::Size, md::IntPrice, BookSide>>& leg_mkts,
|
||||
uint32_t depth);
|
||||
};
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
} // namespace bts::orderman
|
||||
Reference in new issue
Block a user