Merge branch 'master' of bitbucket.org:bluetradesys/spark

This commit is contained in:
Taha Afzal committed 2017-11-02 23:47:02 -04:00
commit dccb675d18
44 files changed
+655 -488

No files matched your search

+1
View File
@@ -2,6 +2,7 @@
#include "lib/quickbus/quickbus.h"
#include "lib/config/config.h"
#include "lib/logging/logging.h"
#include "lib/utils/bts_assert.h"
#include "../public/ServiceContext.h"
#include "../public/Result.h"
+1
View File
@@ -1,6 +1,7 @@
#include "ApiServerInterop.h"
#include "lib/quickbus/quickbus.h"
#include "lib/logging/logging.h"
#include "lib/utils/bts_assert.h"
namespace bts {
namespace api {
+2
View File
@@ -1,3 +1,5 @@
#include "lib/utils/windows_wrapper.h"
#include "ConfigDownloader.h"
#include <stdio.h>
+5 -5
View File
@@ -147,10 +147,10 @@ JetFIX {
}
SparkConnection {
rule: "System.host_name=='pp-6'"
value {connection_name: "cme_m5y"}
}
# SparkConnection {
# rule: "System.host_name=='pp-6'"
# value {connection_name: "cme_m5y"}
# }
SparkConnection {
rule: "System.host_name=='TAHA-SUPER_spark'"
@@ -163,4 +163,4 @@ SparkConnection {
value {connection_name: "cme_mc8"}
}
SparkConnection {value {connection_name: "cme_mbx"}}
SparkConnection {value {connection_name: "sim"}}
+1
View File
@@ -1,5 +1,6 @@
#include "HTTPServer.h"
#include "lib/utils/bts_assert.h"
using boost::asio::ip::tcp;
+2
View File
@@ -1,5 +1,7 @@
#pragma once
#include "lib/utils/windows_wrapper.h"
#include <stdint.h>
#include <array>
#include <limits>
+4 -5
View File
@@ -2,7 +2,6 @@
#include "MsgPacking.h"
#include "LogRec.h"
#include "lib/utils/bts_assert.h"
#include <thread>
#include <atomic>
@@ -38,7 +37,7 @@ public:
void enqueue (Subsystem subsystem,Level lv, const char*file, int line,
const char *msg_template, Args&&... msg_args)
{
bts_assert(_active);
assert(_active);
lock();
if (lv.ordinal >= _filter[subsystem.ordinal].ordinal) {
if (_wcursor == _write_q->size())
@@ -123,7 +122,7 @@ public:
void mark_inactive()
{
lock();
bts_assert(_active);
assert(_active);
_active=false;
unlock();
}
@@ -131,8 +130,8 @@ public:
~Logger()
{
#ifndef WIN32
bts_assert(!_active);
bts_assert(_wcursor == 0);
assert(!_active);
assert(_wcursor == 0);
#endif
}
+2
View File
@@ -4,6 +4,8 @@
#include "lib/utils/bts_chrono.h"
#include "Logger.h"
#include "lib/os/os.h"
#include "lib/utils/bts_assert.h"
#include <thread>
#include <mutex>
#include <atomic>
+1
View File
@@ -4,6 +4,7 @@
#include "lib/os/os.h"
#include "lib/utils/datetime.h"
#include "lib/utils/file_utils.h"
#include "lib/utils/bts_assert.h"
#include <fmt/ostream.h>
#include <fstream>
+13 -9
View File
@@ -10,6 +10,7 @@
#include "lib/md/common.h"
#include "lib/md/protos/co2.pb.h"
#include "lib/config/protos/system.pb.h"
#include "lib/utils/bts_chrono.h"
#include <boost/filesystem.hpp>
#include <google/protobuf/text_format.h>
@@ -132,15 +133,18 @@ void replay_recording(istream& in, IRelayWriter& writer, int32_t naggle_ms) {
}
void replay_file(const std::string& filename, IRelayWriter& writer, int32_t naggle_ms, bool loop = false) {
ifstream in;
in.open(filename, ios::binary | ios::in);
if (in.is_open()) {
replay_recording(in, writer, naggle_ms);
}
else {
LOG(MarketData,Diag, "Cannot read file {}", filename);
}
if (loop) replay_file(filename, writer, naggle_ms, true);
do {
ifstream in;
in.open(filename, ios::binary | ios::in);
if (in.is_open()) {
replay_recording(in, writer, naggle_ms);
}
else {
LOG(MarketData,Diag, "Cannot read file {}", filename);
if (loop)
sleep_for(10s);
}
} while (loop);
}
void replay_url(const std::string& url, IRelayWriter& writer, int32_t naggle_ms) {
+1 -6
View File
@@ -991,11 +991,6 @@ BTS_EXPORT std::string host_ip (std::string const &src_interface_name)
return default_ip;
}
BTS_EXPORT void debug_break()
{
DEBUG_BREAK();
}
BTS_EXPORT void set_thread_name(std::string const&n)
{set_thread_name(n.c_str());}
@@ -1027,7 +1022,7 @@ BTS_EXPORT void set_thread_name(const char* name)
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info);
#ifdef _MSC_VER
}
__except(EXCEPTION_EXECUTE_HANDLER)
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
#endif
-1
View File
@@ -72,7 +72,6 @@ BTS_EXPORT std::string username();
BTS_EXPORT char* strncpy(char* dest, const char* src, size_t count);
BTS_EXPORT void setenv(const char* name, const char* value);
BTS_EXPORT void debug_break();
BTS_EXPORT void set_thread_name(std::string const&);
BTS_EXPORT void set_thread_name(const char* name);
+1
View File
@@ -4,6 +4,7 @@
#include "lib/quickbus/routing/Router.h"
#include "lib/quickbus/routing/NodeID.h"
#include "lib/logging/logging.h"
#include "lib/utils/bts_assert.h"
namespace bts {
namespace qbus {
@@ -4,6 +4,7 @@
#include "lib/utils/PBUtils.h"
#include "lib/utils/datetime.h"
#include "lib/logging/logging.h"
#include "lib/utils/bts_assert.h"
#include "lib/quickbus/routing/Router.h"
#include "lib/quickbus/network/endpoint_description.h"
@@ -4,6 +4,7 @@
#include "lib/quickbus/network/QBConnection.h"
#include "lib/logging/logging.h"
#include "lib/quickbus/network/endpoint_description.h"
#include "lib/utils/bts_assert.h"
#include "lib/config/protos/quickbus_cfg.pb.h"
+1
View File
@@ -5,6 +5,7 @@
#include "lib/quickbus/rpc/rpc_utils.h"
#include "lib/quickbus/core/Advertisement.h"
#include "lib/logging/logging.h"
#include "lib/utils/bts_assert.h"
#include <unordered_map>
#include <atomic>
-1
View File
@@ -2,7 +2,6 @@
#pragma once
#include "lib/utils/bts_no_copy.h"
#include "lib/utils/bts_assert.h"
#include "lib/utils/bts_export.h"
#include <functional>
+1
View File
@@ -1,6 +1,7 @@
#include "HTTPStream.h"
#include "lib/logging/logging.h"
#include "lib/utils/defer.h"
#include "lib/utils/bts_assert.h"
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
+1
View File
@@ -5,6 +5,7 @@
#include "lib/utils/SharedMemory.h"
#include "lib/utils/bts_array_size.h"
#include "lib/logging/logging.h"
#include "lib/utils/bts_assert.h"
#include "lib/os/os.h"
#include "lib/config/config.h"
+1 -1
View File
@@ -13,7 +13,7 @@ typedef std::unique_ptr<sqlite3_stmt, int(*)(sqlite3_stmt*)> sqlite3_stmt_ptr;
do { \
if (x != SQLITE_OK) \
{ \
bts_assert_msg(false ,sqlite3_errmsg(c)); \
bts_assert_msg(false ,sqlite3_errmsg(c.get())); \
} \
} while(0)
+10 -4
View File
@@ -1,5 +1,9 @@
#pragma once
#include <iostream>
#include <csignal>
#include "lib/logging/logging.h"
#include "lib/utils/bts_debugger.h"
#ifdef _WIN32
#define TERMINATE ::_exit(-1);
@@ -7,10 +11,12 @@
#define TERMINATE abort ();
#endif
#define bts_assert_msg(EXP, msg) do { \
if (!(EXP)) { \
std::cerr << "Assert failure: " << __FILE__ << ":" << __LINE__ << " Exp: " << #EXP << std::endl; \
TERMINATE; \
#define bts_assert_msg(EXP, msg) do { \
if (!(EXP)) { \
LOG(Assert,Fatal, "Assert failure: {} {}",std::string(#EXP),std::string(msg) ); \
if (is_debugger_present()) \
debug_break(); \
TERMINATE; \
}} while(0)
#define bts_assert(EXP) bts_assert_msg(EXP, "")
+5
View File
@@ -1,6 +1,7 @@
#pragma once
#include <chrono>
#include <ctime>
#include <thread>
namespace bts {
@@ -24,6 +25,10 @@ inline int64_t sec_diff (TimeStamp t1, TimeStamp t2) {
return std::chrono::duration_cast<std::chrono::seconds>(t1 - t2).count() ;
}
template <class T> void sleep_for (T t)
{
std::this_thread::sleep_for(t);
}
}
inline std::ostream &operator<<(std::ostream &o,const bts::TimeStamp ts)
+41 -11
View File
@@ -1,16 +1,46 @@
#ifndef BTS_DEBUGGER_H_
#define BTS_DEBUGGER_H_
#pragma once
#include "../os/os.h"
#include <csignal>
#include <sys/stat.h>
#include <fcntl.h>
#include "windows_wrapper.h"
#ifdef _WIN32
#define DEBUG_BREAK() do { if (IsDebuggerPresent()) __debugbreak(); } while(0)
#else
//#include <sys/ptrace.h>
//#include <signal.h>
// #define DEBUG_BREAK() do { if (ptrace(PTRACE_TRACEME, 0, NULL, 0) == -1) raise(SIGTRAP); } while(0)
#define DEBUG_BREAK()
#endif
inline bool is_debugger_present()
{
#ifdef WIN32
return IsDebuggerPresent();
#else
char buf[1024];
int debugger_present = 0;
int status_fd = open("/proc/self/status", O_RDONLY);
if (status_fd == -1)
return 0;
ssize_t num_read = read(status_fd, buf, sizeof(buf)-1);
if (num_read > 0)
{
static const char TracerPid[] = "TracerPid:";
char *tracer_pid;
buf[num_read] = 0;
tracer_pid = strstr(buf, TracerPid);
if (tracer_pid)
debugger_present = !!atoi(tracer_pid + sizeof(TracerPid) - 1);
}
return debugger_present;
#endif
}
inline void debug_break()
{
#ifdef _WIN32
__debugbreak();
#else
std::raise(SIGINT);
#endif
}
+1 -1
View File
@@ -1 +1 @@
set(sources ;cmds/CmdRegistry.cpp;cmds/ConfigCheck.cpp;cmds/Help.cpp;cmds/Md.cpp;cmds/Run.cpp;cmds/RunSim.cpp;cmds/Test.cpp;cmds/TestCeloxica.cpp;cmds/TestOrderman.cpp;event_grid/EventNode.cpp;exchange_sim/Application.cpp;exchange_sim/ExchangeSim.cpp;exchange_sim/Market.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/store_tests.cpp;main.cpp;md/platforms/celoxica/CXListener.cpp;md/platforms/celoxica/CXMain.cpp;md/platforms/celoxica/tests/cx_tests.cpp;md/platforms/mdp3_onixs/MDP3Listener.cpp;md/platforms/mdp3_onixs/MDP3Main.cpp;md/platforms/mdp3_onixs/MDP3Utils.cpp;md/platforms/mdp3_onixs/tests/mdp3_tests.cpp;md/run_md.cpp;orderman/components/FillRecorder.cpp;orderman/components/Gateway.cpp;orderman/components/MDSource.cpp;orderman/components/NativeOrderMan.cpp;orderman/components/OrderRecorder.cpp;orderman/components/SpreaderOrderMan.cpp;orderman/events/ExecutionReport.cpp;orderman/events/NativeOrderStateChange.cpp;orderman/events/SpreaderOrderStateChange.cpp;orderman/events/TimeChange.cpp;orderman/native_orders/NativeOrder.cpp;orderman/native_orders/NativeOrderBuilder.cpp;orderman/native_orders/NativeOrderFactory.cpp;orderman/persistence/FillDB.cpp;orderman/persistence/OrderDB.cpp;orderman/persistence/gen_order_id.cpp;orderman/service/OrderServiceServer.cpp;orderman/spreader_orders/SpreaderOrder.cpp;orderman/spreader_orders/SpreaderOrderBase.cpp;orderman/spreader_orders/spreader_states/SpreaderEndStateWorker.cpp;orderman/spreader_orders/spreader_states/SpreaderStartStateWorker.cpp;orderman/spreader_orders/spreader_states/SpreaderWaitingForCancelAllStateWorker.cpp;orderman/spreader_orders/spreader_states/SpreaderWaitingForFirstConnStateWorker.cpp;orderman/spreader_orders/spreader_states/SpreaderWorkingStateWorker.cpp;orderman/tests/spreader_order_tests.cpp;orderman/utils/fix_order_codec.cpp;orderman/utils/orderman_utils.cpp;persistence/IStore.cpp;persistence/PersistenceServiceServer.cpp;persistence/SqliteStore.cpp;persistence/tests/PersistenceServiceTests.cpp;risk_limits/IRiskLimitObserver.cpp;risk_limits/RiskLimitManager.cpp;risk_limits/RiskLimiter.cpp;risk_limits/SharedRiskLimiter.cpp;risk_limits/SymbolKey.cpp;risk_limits/tests/RiskLimitsTests.cpp;securities/SecurityDB.cpp;spreader/QuoteLegPriceQuantityState.cpp;spreader/SingleFillHedger.cpp;spreader/SingleLegQuoter.cpp;spreader/hedger/hedger_states/HedgerEndStateWorker.cpp;spreader/hedger/hedger_states/HedgerStartStateWorker.cpp;spreader/hedger/hedger_states/HedgerWaitingForCancelAckStateWorker.cpp;spreader/hedger/hedger_states/HedgerWaitingForFirstAckCancelledStateWorker.cpp;spreader/hedger/hedger_states/HedgerWaitingForFirstAckStateWorker.cpp;spreader/hedger/hedger_states/HedgerWorkingStateWorker.cpp;testing/catch_test_runner.cpp;user/UserServiceServer.cpp)
set(sources ;cmds/CmdRegistry.cpp;cmds/ConfigCheck.cpp;cmds/Help.cpp;cmds/Md.cpp;cmds/Run.cpp;cmds/RunSim.cpp;cmds/Test.cpp;cmds/TestCeloxica.cpp;cmds/TestOrderman.cpp;event_grid/EventNode.cpp;exchange_sim/ExchangeSim.cpp;exchange_sim/ExchangeSimApplication.cpp;exchange_sim/Market.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/store_tests.cpp;main.cpp;md/platforms/celoxica/CXListener.cpp;md/platforms/celoxica/CXMain.cpp;md/platforms/celoxica/tests/cx_tests.cpp;md/platforms/mdp3_onixs/MDP3Listener.cpp;md/platforms/mdp3_onixs/MDP3Main.cpp;md/platforms/mdp3_onixs/MDP3Utils.cpp;md/platforms/mdp3_onixs/tests/mdp3_tests.cpp;md/run_md.cpp;orderman/components/FillRecorder.cpp;orderman/components/Gateway.cpp;orderman/components/MDSource.cpp;orderman/components/NativeOrderMan.cpp;orderman/components/OrderRecorder.cpp;orderman/components/SpreaderOrderMan.cpp;orderman/events/ExecutionReport.cpp;orderman/events/NativeOrderStateChange.cpp;orderman/events/SpreaderOrderStateChange.cpp;orderman/events/TimeChange.cpp;orderman/native_orders/NativeOrder.cpp;orderman/native_orders/NativeOrderBuilder.cpp;orderman/native_orders/NativeOrderFactory.cpp;orderman/persistence/FillDB.cpp;orderman/persistence/OrderDB.cpp;orderman/persistence/gen_order_id.cpp;orderman/service/OrderServiceServer.cpp;orderman/spreader_orders/SpreaderOrder.cpp;orderman/spreader_orders/SpreaderOrderBase.cpp;orderman/spreader_orders/spreader_states/SpreaderEndStateWorker.cpp;orderman/spreader_orders/spreader_states/SpreaderStartStateWorker.cpp;orderman/spreader_orders/spreader_states/SpreaderWaitingForCancelAllStateWorker.cpp;orderman/spreader_orders/spreader_states/SpreaderWaitingForFirstConnStateWorker.cpp;orderman/spreader_orders/spreader_states/SpreaderWorkingStateWorker.cpp;orderman/tests/spreader_order_tests.cpp;orderman/utils/fix_order_codec.cpp;orderman/utils/orderman_utils.cpp;persistence/IStore.cpp;persistence/PersistenceServiceServer.cpp;persistence/SqliteStore.cpp;persistence/tests/PersistenceServiceTests.cpp;risk_limits/IRiskLimitObserver.cpp;risk_limits/RiskLimitManager.cpp;risk_limits/RiskLimiter.cpp;risk_limits/SharedRiskLimiter.cpp;risk_limits/SymbolKey.cpp;risk_limits/tests/RiskLimitsTests.cpp;securities/SecurityDB.cpp;spreader/QuoteLegPriceQuantityState.cpp;spreader/SingleFillHedger.cpp;spreader/SingleLegQuoter.cpp;spreader/hedger/hedger_states/HedgerEndStateWorker.cpp;spreader/hedger/hedger_states/HedgerStartStateWorker.cpp;spreader/hedger/hedger_states/HedgerWaitingForCancelAckStateWorker.cpp;spreader/hedger/hedger_states/HedgerWaitingForFirstAckCancelledStateWorker.cpp;spreader/hedger/hedger_states/HedgerWaitingForFirstAckStateWorker.cpp;spreader/hedger/hedger_states/HedgerWorkingStateWorker.cpp;testing/catch_test_runner.cpp;user/UserServiceServer.cpp)
+16 -8
View File
@@ -237,12 +237,14 @@ int TestOrderman::execute(std::vector<std::string> const &)
std::cout <<
"Commands:\n"
"\tcreate native order : n sec_key b/s price quantity\n"
"\tcreate spreader order : s b/s price quantity\n"
"\tupdate order : u price quantity\n"
"\tcancel order : x\n"
"\tchange current order: o order_key n|s\n\n";
"\tcreate native order : n b/s price quantity\n"
"\tcreate spreader order : s b/s price quantity\n"
"\tupdate order : u price quantity\n"
"\tcancel order : x\n"
"\tchange current order : o order_key s|n \n"
"\tchange current security : k security_key\n";
auto sec_key = SecurityKey(get_front_month_es_futures().first->id());
while (true) {
std::cout << "> ";
std::cout.flush();
@@ -250,11 +252,11 @@ int TestOrderman::execute(std::vector<std::string> const &)
std::cin >> choice;
switch (choice) {
case 'n': {
uint32_t sec_key;char side; double price; int quantity;
std::cin >> sec_key >> side >> price >> quantity;
char side; double price; int quantity;
std::cin >> side >> price >> quantity;
display_order_updates = true;
auto resp = client.create_order(
make_native_order_create_request(SecurityKey(sec_key),
make_native_order_create_request(sec_key,
side == 'b' ? api::SIDE_BUY : api::SIDE_SELL,
Price(price),
Quantity(quantity)));
@@ -326,6 +328,12 @@ int TestOrderman::execute(std::vector<std::string> const &)
<< (current_order_type == CurrentOrderType::NATIVE? "native" : "spreader");
break;
}
case 'k': {
std::cin >> sec_key.value() ;
std::cout << "Current security key: "
<< sec_key.value();
break;
}
}
}
}
@@ -1,206 +0,0 @@
#include "Application.h"
#include "lib/logging/logging.h"
#include <quickfix/Session.h>
#include <quickfix/fix42/ExecutionReport.h>
namespace bts {
namespace sim {
void Application::onLogon( const FIX::SessionID& ) {}
void Application::onLogout( const FIX::SessionID& ) {}
void Application::fromApp( const FIX::Message& message,
const FIX::SessionID& sessionID )
throw( FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::UnsupportedMessageType )
{
crack( message, sessionID );
}
void Application::onMessage( const FIX42::NewOrderSingle& message, const FIX::SessionID& )
{
FIX::SenderCompID senderCompID;
FIX::TargetCompID targetCompID;
FIX::ClOrdID clOrdID;
FIX::Symbol symbol;
FIX::Side side;
FIX::OrdType ordType;
FIX::Price price;
FIX::OrderQty orderQty;
FIX::TimeInForce timeInForce( FIX::TimeInForce_DAY );
message.getHeader().get( senderCompID );
message.getHeader().get( targetCompID );
message.get( clOrdID );
message.get( symbol );
message.get( side );
message.get( ordType );
if ( ordType == FIX::OrdType_LIMIT )
message.get( price );
message.get( orderQty );
message.getFieldIfSet( timeInForce );
LOG(ExSim,Info, "Got new order: {}", clOrdID.getString());
try
{
if ( timeInForce != FIX::TimeInForce_DAY )
throw std::logic_error( "Unsupported TIF, use Day" );
Order order( clOrdID, symbol, senderCompID, targetCompID,
convert( side ), convert( ordType ),
price, (long)orderQty );
processOrder( order );
}
catch ( std::exception & e )
{
rejectOrder( senderCompID, targetCompID, clOrdID, symbol, side, e.what() );
}
}
void Application::onMessage( const FIX42::OrderCancelRequest& message, const FIX::SessionID& )
{
FIX::OrigClOrdID origClOrdID;
FIX::Symbol symbol;
FIX::Side side;
message.get( origClOrdID );
message.get( symbol );
message.get( side );
LOG(ExSim,Info, "Got order cancelation for: {}", origClOrdID.getString());
try
{
processCancel( origClOrdID, symbol, convert( side ) );
}
catch ( std::exception& ) {}
}
void Application::updateOrder( const Order& order, char status )
{
FIX::TargetCompID targetCompID( order.getOwner() );
FIX::SenderCompID senderCompID( order.getTarget() );
FIX42::ExecutionReport fixOrder
( FIX::OrderID ( order.getClientID() ),
FIX::ExecID ( m_generator.genExecutionID() ),
FIX::ExecTransType ( FIX::ExecTransType_NEW ),
FIX::ExecType ( status ),
FIX::OrdStatus ( status ),
FIX::Symbol ( order.getSymbol() ),
FIX::Side ( convert( order.getSide() ) ),
FIX::LeavesQty ( order.getOpenQuantity() ),
FIX::CumQty ( order.getExecutedQuantity() ),
FIX::AvgPx ( order.getAvgExecutedPrice() ) );
fixOrder.set( FIX::ClOrdID( order.getClientID() ) );
fixOrder.set( FIX::OrderQty( order.getQuantity() ) );
if ( status == FIX::OrdStatus_FILLED ||
status == FIX::OrdStatus_PARTIALLY_FILLED )
{
fixOrder.set( FIX::LastShares( order.getLastExecutedQuantity() ) );
fixOrder.set( FIX::LastPx( order.getLastExecutedPrice() ) );
}
try
{
FIX::Session::sendToTarget( fixOrder, senderCompID, targetCompID );
}
catch ( FIX::SessionNotFound& ) {}}
void Application::rejectOrder
( const FIX::SenderCompID& sender, const FIX::TargetCompID& target,
const FIX::ClOrdID& clOrdID, const FIX::Symbol& symbol,
const FIX::Side& side, const std::string& message )
{
FIX::TargetCompID targetCompID( sender.getValue() );
FIX::SenderCompID senderCompID( target.getValue() );
FIX42::ExecutionReport fixOrder
( FIX::OrderID ( clOrdID.getValue() ),
FIX::ExecID ( m_generator.genExecutionID() ),
FIX::ExecTransType ( FIX::ExecTransType_NEW ),
FIX::ExecType ( FIX::ExecType_REJECTED ),
FIX::OrdStatus ( FIX::ExecType_REJECTED ),
symbol, side, FIX::LeavesQty( 0 ), FIX::CumQty( 0 ), FIX::AvgPx( 0 ) );
fixOrder.set( clOrdID );
fixOrder.set( FIX::Text( message ) );
try
{
FIX::Session::sendToTarget( fixOrder, senderCompID, targetCompID );
}
catch ( FIX::SessionNotFound& ) {}}
void Application::processOrder( const Order& order )
{
if ( m_orderMatcher.insert( order ) )
{
acceptOrder( order );
std::queue < Order > orders;
m_orderMatcher.match( order.getSymbol(), orders );
while ( orders.size() )
{
fillOrder( orders.front() );
orders.pop();
}
}
else
rejectOrder( order );
}
void Application::processCancel( const std::string& id,
const std::string& symbol, Order::Side side )
{
Order & order = m_orderMatcher.find( symbol, side, id );
order.cancel();
cancelOrder( order );
m_orderMatcher.erase( order );
}
Order::Side Application::convert( const FIX::Side& side )
{
switch ( side )
{
case FIX::Side_BUY: return Order::buy;
case FIX::Side_SELL: return Order::sell;
default: throw std::logic_error( "Unsupported Side, use buy or sell" );
}
}
Order::Type Application::convert( const FIX::OrdType& ordType )
{
switch ( ordType )
{
case FIX::OrdType_LIMIT: return Order::limit;
default: throw std::logic_error( "Unsupported Order Type, use limit" );
}
}
FIX::Side Application::convert( Order::Side side )
{
switch ( side )
{
case Order::buy: return FIX::Side( FIX::Side_BUY );
case Order::sell: return FIX::Side( FIX::Side_SELL );
default: throw std::logic_error( "Unsupported Side, use buy or sell" );
}
}
FIX::OrdType Application::convert( Order::Type type )
{
switch ( type )
{
case Order::limit: return FIX::OrdType( FIX::OrdType_LIMIT );
default: throw std::logic_error( "Unsupported Order Type, use limit" );
}
}
}}
@@ -1,101 +0,0 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef ORDERMATCH_APPLICATION_H
#define ORDERMATCH_APPLICATION_H
#include "IDGenerator.h"
#include "OrderMatcher.h"
#include "Order.h"
#include <queue>
#include <iostream>
#include <quickfix/Application.h>
#include <quickfix/MessageCracker.h>
#include <quickfix/Values.h>
#include <quickfix/Utility.h>
#include <quickfix/Mutex.h>
#include <quickfix/fix42/NewOrderSingle.h>
#include <quickfix/fix42/OrderCancelRequest.h>
#include "lib/utils/warn_ctrl.h"
namespace bts {
namespace sim {
GCC_DIAG_OFF("-Woverloaded-virtual")
class Application
: public FIX::Application,
public FIX::MessageCracker
{
// Application overloads
void onCreate( const FIX::SessionID& ) {}
void onLogon( const FIX::SessionID& sessionID );
void onLogout( const FIX::SessionID& sessionID );
void toAdmin( FIX::Message&, const FIX::SessionID& ) {}
void toApp( FIX::Message&, const FIX::SessionID& )
throw( FIX::DoNotSend ) {}
void fromAdmin( const FIX::Message&, const FIX::SessionID& )
throw( FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::RejectLogon ) {}
void fromApp( const FIX::Message& message, const FIX::SessionID& sessionID )
throw( FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::UnsupportedMessageType );
// MessageCracker overloads
void onMessage( const FIX42::NewOrderSingle&, const FIX::SessionID& );
void onMessage( const FIX42::OrderCancelRequest&, const FIX::SessionID& );
// Order functionality
void processOrder( const Order& );
void processCancel( const std::string& id, const std::string& symbol, Order::Side );
void updateOrder( const Order&, char status );
void rejectOrder( const Order& order )
{ updateOrder( order, FIX::OrdStatus_REJECTED ); }
void acceptOrder( const Order& order )
{ updateOrder( order, FIX::OrdStatus_NEW ); }
void fillOrder( const Order& order )
{
updateOrder( order,
order.isFilled() ? FIX::OrdStatus_FILLED
: FIX::OrdStatus_PARTIALLY_FILLED );
}
void cancelOrder( const Order& order )
{ updateOrder( order, FIX::OrdStatus_CANCELED ); }
void rejectOrder( const FIX::SenderCompID&, const FIX::TargetCompID&,
const FIX::ClOrdID& clOrdID, const FIX::Symbol& symbol,
const FIX::Side& side, const std::string& message );
// Type conversions
Order::Side convert( const FIX::Side& );
Order::Type convert( const FIX::OrdType& );
FIX::Side convert( Order::Side );
FIX::OrdType convert( Order::Type );
OrderMatcher m_orderMatcher;
IDGenerator m_generator;
public:
const OrderMatcher& orderMatcher() { return m_orderMatcher; }
};
GCC_DIAG_RESTORE()
}}
#endif
@@ -1,4 +1,4 @@
#include "Application.h"
#include "ExchangeSimApplication.h"
#include <quickfix/FileStore.h>
#include <quickfix/SocketAcceptor.h>
@@ -48,7 +48,7 @@ int start_exchange_sim()
std::istringstream str{str_settings};
FIX::SessionSettings settings( str );
Application application;
ExchangeSimApplication application;
FIX::FileStoreFactory storeFactory( settings );
FIX::FileLogFactory logFactory( settings );
FIX::SocketAcceptor acceptor( application, storeFactory, settings, logFactory );
@@ -0,0 +1,295 @@
#include "ExchangeSimApplication.h"
#include "lib/logging/logging.h"
#include "lib/utils/datetime.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <quickfix/fix42/ExecutionReport.h>
#include <quickfix/fix42/OrderCancelReplaceRequest.h>
namespace bts {
namespace sim {
GCC_DIAG_OFF("-Wdeprecated")
GCC_DIAG_OFF("-Wignored-qualifiers")
void ExchangeSimApplication::onLogon( const FIX::SessionID& ) {}
void ExchangeSimApplication::onLogout( const FIX::SessionID& ) {}
void ExchangeSimApplication::fromApp( const FIX::Message& message,
const FIX::SessionID& sessionID )
throw( FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::UnsupportedMessageType )
{
crack( message, sessionID );
}
void ExchangeSimApplication::onMessage( const FIX42::NewOrderSingle& message, const FIX::SessionID& )
{
FIX::SenderCompID senderCompID;
FIX::TargetCompID targetCompID;
FIX::SenderSubID senderSubID;
FIX::ClOrdID clOrdID;
FIX::Account account;
FIX::SecurityDesc sec_desc;
FIX::Side side;
FIX::OrdType ordType;
FIX::Price price;
FIX::OrderQty orderQty;
FIX::TimeInForce timeInForce( FIX::TimeInForce_DAY );
FIX::ManualOrderIndicator moi;
message.getHeader().get( senderCompID );
message.getHeader().get( targetCompID );
message.getHeader().get( senderSubID );
message.get( clOrdID );
message.get( account );
message.get( sec_desc );
message.get( side );
message.get( ordType );
if ( ordType == FIX::OrdType_LIMIT )
message.get( price );
message.get( orderQty );
message.getFieldIfSet( timeInForce );
message.getField(moi);
LOG(ExSim,Info, "Got new order: {}", clOrdID.getString());
try
{
if ( timeInForce != FIX::TimeInForce_DAY )
throw std::logic_error( "Unsupported TIF, use Day" );
Order order( clOrdID, sec_desc, account,senderCompID, targetCompID, senderSubID,
convert( side ), convert( ordType ),
price, (long)orderQty,convert(moi) );
processOrder( order );
}
catch ( std::exception & e )
{
rejectOrder( senderCompID, targetCompID, clOrdID, sec_desc, side, e.what() );
}
}
void ExchangeSimApplication::onMessage( const FIX42::OrderCancelReplaceRequest&message, const FIX::SessionID& )
{
FIX::Price price;
FIX::OrderQty orderQty;
FIX::ClOrdID clOrdID;
FIX::SecurityDesc sec_desc;
FIX::Side side;
FIX::SenderCompID senderCompID;
FIX::TargetCompID targetCompID;
message.getHeader().get( senderCompID );
message.getHeader().get( targetCompID );
message.get( clOrdID );
message.get( price );
message.get( orderQty );
message.get( sec_desc );
message.get( side );
try {
Order & order = m_orderMatcher.find( sec_desc, convert(side), clOrdID );
order.update(price,orderQty);
updateOrder(order,FIX::OrdStatus_REPLACED);
std::queue < Order > orders;
m_orderMatcher.match( order.getSecDesc(), orders );
while ( orders.size() )
{
fillOrder( orders.front() );
orders.pop();
}
}
catch ( std::exception & e )
{
rejectOrder( senderCompID, targetCompID, clOrdID, sec_desc, side, e.what() );
}
}
void ExchangeSimApplication::onMessage( const FIX42::OrderCancelRequest& message, const FIX::SessionID& )
{
FIX::OrigClOrdID origClOrdID;
FIX::SecurityDesc sec_desc;
FIX::Side side;
message.get( origClOrdID );
message.get( sec_desc );
message.get( side );
LOG(ExSim,Info, "Got order cancellation for: {}", origClOrdID.getString());
try
{
processCancel( origClOrdID, sec_desc, convert( side ) );
}
catch ( std::exception& ) {}
}
void ExchangeSimApplication::updateOrder( const Order& order, char status )
{
FIX::TargetCompID targetCompID( order.getOwner() );
FIX::SenderCompID senderCompID( order.getTarget() );
FIX::TargetSubID( order.getSenderSubID() ) ;
FIX42::ExecutionReport fixOrder;
fixOrder.set(FIX::OrderID ("0"));
fixOrder.set(FIX::ExecID ( m_generator.genExecutionID() ));
fixOrder.set(FIX::ExecTransType ( FIX::ExecTransType_NEW ));
fixOrder.set(FIX::ExecType ( status ));
fixOrder.set(FIX::OrdStatus ( status ));
fixOrder.set(FIX::Account ( order.getAccount() ));
fixOrder.set(FIX::SecurityDesc ( order.getSecDesc() ));
fixOrder.set(FIX::Side ( convert( order.getSide() ) ));
fixOrder.set(FIX::LeavesQty ( order.getOpenQuantity() ));
fixOrder.set(FIX::CumQty ( order.getExecutedQuantity() ));
fixOrder.set(FIX::AvgPx ( order.getAvgExecutedPrice() ) );
fixOrder.set(FIX::ClOrdID( order.getClientID() ) );
fixOrder.set(FIX::OrderQty( order.getQuantity() ) );
fixOrder.set(FIX::TimeInForce( FIX::TimeInForce_DAY));
fixOrder.set(FIX::OrdType( convert(order.getType())));
fixOrder.set(FIX::Price(order.getPrice()));
fixOrder.set(FIX::OrderQty(order.getQuantity()));
fixOrder.setField(convert(order.getMOI()));
boost::posix_time::ptime now = boost::posix_time::second_clock::universal_time ();
fixOrder.set (FIX::TransactTime (FIX::UtcTimeStamp (now.time_of_day ().hours (),
now.time_of_day ().minutes (),
now.time_of_day ().seconds (),
now.date ().day (), now.date ().month (),
now.date ().year ()),true));
if ( status == FIX::OrdStatus_FILLED ||
status == FIX::OrdStatus_PARTIALLY_FILLED )
{
fixOrder.set( FIX::LastShares( order.getLastExecutedQuantity() ) );
fixOrder.set( FIX::LastPx( order.getLastExecutedPrice() ) );
}
fixOrder.getHeader().set(FIX::TargetSubID(order.getSenderSubID()));
try
{
FIX::Session::sendToTarget( fixOrder, senderCompID, targetCompID);
}
catch ( FIX::SessionNotFound& ) {}}
void ExchangeSimApplication::rejectOrder
( const FIX::SenderCompID& sender, const FIX::TargetCompID& target,
const FIX::ClOrdID& clOrdID, const FIX::SecurityDesc& symbol,
const FIX::Side& side, const std::string& message )
{
FIX::TargetCompID targetCompID( sender.getValue() );
FIX::SenderCompID senderCompID( target.getValue() );
FIX42::ExecutionReport fixOrder;
fixOrder.set (FIX::OrderID ( clOrdID.getValue() ));
fixOrder.set (FIX::ExecID ( m_generator.genExecutionID() ));
fixOrder.set (FIX::ExecTransType ( FIX::ExecTransType_NEW ));
fixOrder.set (FIX::ExecType ( FIX::ExecType_REJECTED ));
fixOrder.set (FIX::OrdStatus ( FIX::ExecType_REJECTED ));
fixOrder.set (symbol);
fixOrder.set (side);
fixOrder.set (FIX::LeavesQty( 0 ));
fixOrder.set (FIX::CumQty( 0 ));
fixOrder.set (FIX::AvgPx( 0 ));
fixOrder.set( clOrdID );
fixOrder.set( FIX::Text( message ) );
try
{
FIX::Session::sendToTarget( fixOrder, senderCompID, targetCompID );
}
catch ( FIX::SessionNotFound& ) {}}
void ExchangeSimApplication::processOrder( const Order& order )
{
if ( m_orderMatcher.insert( order ) )
{
acceptOrder( order );
std::queue < Order > orders;
m_orderMatcher.match( order.getSecDesc(), orders );
while ( orders.size() )
{
fillOrder( orders.front() );
orders.pop();
}
}
else
rejectOrder( order );
}
void ExchangeSimApplication::processCancel( const std::string& id,
const std::string& symbol, Order::Side side )
{
Order & order = m_orderMatcher.find( symbol, side, id );
order.cancel();
cancelOrder( order );
m_orderMatcher.erase( order );
}
Order::Side ExchangeSimApplication::convert( const FIX::Side& side )
{
switch ( side )
{
case FIX::Side_BUY: return Order::buy;
case FIX::Side_SELL: return Order::sell;
default: throw std::logic_error( "Unsupported Side, use buy or sell" );
}
}
Order::Type ExchangeSimApplication::convert( const FIX::OrdType& ordType )
{
switch ( ordType )
{
case FIX::OrdType_LIMIT: return Order::limit;
default: throw std::logic_error( "Unsupported Order Type, use limit" );
}
}
FIX::Side ExchangeSimApplication::convert( Order::Side side )
{
switch ( side )
{
case Order::buy: return FIX::Side( FIX::Side_BUY );
case Order::sell: return FIX::Side( FIX::Side_SELL );
default: throw std::logic_error( "Unsupported Side, use buy or sell" );
}
}
FIX::OrdType ExchangeSimApplication::convert( Order::Type type )
{
switch ( type )
{
case Order::limit: return FIX::OrdType( FIX::OrdType_LIMIT );
default: throw std::logic_error( "Unsupported Order Type, use limit" );
}
}
FIX::ManualOrderIndicator ExchangeSimApplication::convert (const Order::MOI &moi)
{
switch (moi)
{
case Order::moi_yes:
return FIX::ManualOrderIndicator(true);
default:
return FIX::ManualOrderIndicator(false);
}
}
Order::MOI ExchangeSimApplication::convert (const FIX::ManualOrderIndicator &moi)
{
if (moi.getValue())
return Order::moi_yes;
else
return Order::moi_no;
}
GCC_DIAG_RESTORE()
GCC_DIAG_RESTORE()
}}
@@ -0,0 +1,112 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef ORDERMATCH_APPLICATION_H
#define ORDERMATCH_APPLICATION_H
#include "lib/utils/warn_ctrl.h"
GCC_DIAG_OFF("-Woverloaded-virtual")
GCC_DIAG_OFF("-Wdeprecated")
GCC_DIAG_OFF("-Wignored-qualifiers")
#include "IDGenerator.h"
#include "OrderMatcher.h"
#include "Order.h"
#include <queue>
#include <iostream>
#include <quickfix/Application.h>
#include <quickfix/MessageCracker.h>
#include <quickfix/Values.h>
#include <quickfix/Utility.h>
#include <quickfix/Mutex.h>
#include <quickfix/fix42/NewOrderSingle.h>
#include <quickfix/fix42/OrderCancelRequest.h>
namespace bts {
namespace sim {
class ExchangeSimApplication
: public FIX::Application,
public FIX::MessageCracker
{
// Application overloads
void onCreate( const FIX::SessionID& ) {}
void onLogon( const FIX::SessionID& sessionID );
void onLogout( const FIX::SessionID& sessionID );
void toAdmin( FIX::Message&, const FIX::SessionID& ) {}
void toApp( FIX::Message&, const FIX::SessionID& )
throw( FIX::DoNotSend ) {}
void fromAdmin( const FIX::Message&, const FIX::SessionID& )
throw( FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::RejectLogon ) {}
void fromApp( const FIX::Message& message, const FIX::SessionID& sessionID )
throw( FIX::FieldNotFound, FIX::IncorrectDataFormat, FIX::IncorrectTagValue, FIX::UnsupportedMessageType );
// MessageCracker overloads
void onMessage( const FIX42::NewOrderSingle&, const FIX::SessionID& );
void onMessage( const FIX42::OrderCancelReplaceRequest&, const FIX::SessionID& );
void onMessage( const FIX42::OrderCancelRequest&, const FIX::SessionID& );
// Order functionality
void processOrder( const Order& );
void processCancel( const std::string& id, const std::string& symbol, Order::Side );
void updateOrder( const Order&, char status );
void rejectOrder( const Order& order )
{ updateOrder( order, FIX::OrdStatus_REJECTED ); }
void acceptOrder( const Order& order )
{ updateOrder( order, FIX::OrdStatus_NEW ); }
void fillOrder( const Order& order )
{
updateOrder( order,
order.isFilled() ? FIX::OrdStatus_FILLED
: FIX::OrdStatus_PARTIALLY_FILLED );
}
void cancelOrder( const Order& order )
{ updateOrder( order, FIX::OrdStatus_CANCELED ); }
void rejectOrder( const FIX::SenderCompID&, const FIX::TargetCompID&,
const FIX::ClOrdID& clOrdID, const FIX::SecurityDesc& symbol,
const FIX::Side& side, const std::string& message );
// Type conversions
Order::Side convert( const FIX::Side& );
Order::Type convert( const FIX::OrdType& );
Order::MOI convert (const FIX::ManualOrderIndicator &);
FIX::ManualOrderIndicator convert (const Order::MOI &moi);
FIX::Side convert( Order::Side );
FIX::OrdType convert( Order::Type );
OrderMatcher m_orderMatcher;
IDGenerator m_generator;
public:
const OrderMatcher& orderMatcher() { return m_orderMatcher; }
};
}}
GCC_DIAG_RESTORE()
GCC_DIAG_RESTORE()
GCC_DIAG_RESTORE()
#endif
@@ -26,6 +26,9 @@
#include "Market.h"
#include <iostream>
namespace bts {
namespace sim {
bool Market::insert( const Order& order )
{
if ( order.getSide() == Order::buy )
@@ -135,3 +138,4 @@ void Market::display() const
for ( iAsk = m_askOrders.begin(); iAsk != m_askOrders.end(); ++iAsk )
std::cout << iAsk->second << std::endl;
}
}}
+4 -1
View File
@@ -28,6 +28,9 @@
#include <string>
#include <functional>
namespace bts {
namespace sim {
class Market
{
public:
@@ -47,5 +50,5 @@ private:
BidOrders m_bidOrders;
AskOrders m_askOrders;
};
}}
#endif
+103 -82
View File
@@ -1,23 +1,23 @@
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef ORDERMATCH_ORDER_H
#define ORDERMATCH_ORDER_H
@@ -26,86 +26,107 @@
#include <iomanip>
#include <ostream>
namespace bts {
namespace sim {
class Order
{
friend std::ostream& operator<<( std::ostream&, const Order& );
friend std::ostream& operator<<( std::ostream&, const Order& );
public:
enum Side { buy, sell };
enum Type { market, limit };
enum Side { buy, sell };
enum Type { market, limit };
enum MOI { moi_yes, moi_no };
Order( const std::string& clientId, const std::string& symbol,
const std::string& owner, const std::string& target,
Side side, Type type, double price, long quantity )
: m_clientId( clientId ), m_symbol( symbol ), m_owner( owner ),
m_target( target ), m_side( side ), m_type( type ), m_price( price ),
m_quantity( quantity )
{
m_openQuantity = m_quantity;
m_executedQuantity = 0;
m_avgExecutedPrice = 0;
m_lastExecutedPrice = 0;
m_lastExecutedQuantity = 0;
}
Order( const std::string& clientId, const std::string& sec_desc,
std::string const&account, const std::string& owner,
const std::string& target,
const std::string& sender_sub_id,
Side side, Type type, double price, long quantity,
MOI moi)
: m_clientId( clientId ), m_sec_desc( sec_desc ), m_account(account),m_owner( owner ),
m_target( target ),
m_sender_sub_id( sender_sub_id ),
m_side( side ), m_type( type ), m_price( price ),
m_quantity( quantity ),
m_moi(moi)
{
m_openQuantity = m_quantity;
m_executedQuantity = 0;
m_avgExecutedPrice = 0;
m_lastExecutedPrice = 0;
m_lastExecutedQuantity = 0;
}
const std::string& getClientID() const { return m_clientId; }
const std::string& getSymbol() const { return m_symbol; }
const std::string& getOwner() const { return m_owner; }
const std::string& getTarget() const { return m_target; }
Side getSide() const { return m_side; }
Type getType() const { return m_type; }
double getPrice() const { return m_price; }
long getQuantity() const { return m_quantity; }
const std::string& getClientID() const { return m_clientId; }
const std::string& getAccount() const { return m_account; }
const std::string& getSecDesc() const { return m_sec_desc; }
const std::string& getOwner() const { return m_owner; }
const std::string& getTarget() const { return m_target; }
const std::string& getSenderSubID() const { return m_sender_sub_id; }
Side getSide() const { return m_side; }
Type getType() const { return m_type; }
double getPrice() const { return m_price; }
long getQuantity() const { return m_quantity; }
long getOpenQuantity() const { return m_openQuantity; }
long getExecutedQuantity() const { return m_executedQuantity; }
double getAvgExecutedPrice() const { return m_avgExecutedPrice; }
double getLastExecutedPrice() const { return m_lastExecutedPrice; }
long getLastExecutedQuantity() const { return m_lastExecutedQuantity; }
void update (double price, long quantity) {
m_price = price;
m_quantity = quantity;
}
MOI getMOI() const { return m_moi; }
bool isFilled() const { return m_quantity == m_executedQuantity; }
bool isClosed() const { return m_openQuantity == 0; }
long getOpenQuantity() const { return m_openQuantity; }
long getExecutedQuantity() const { return m_executedQuantity; }
double getAvgExecutedPrice() const { return m_avgExecutedPrice; }
double getLastExecutedPrice() const { return m_lastExecutedPrice; }
long getLastExecutedQuantity() const { return m_lastExecutedQuantity; }
void execute( double price, long quantity )
{
m_avgExecutedPrice =
( ( quantity * price ) + ( m_avgExecutedPrice * m_executedQuantity ) )
/ ( quantity + m_executedQuantity );
bool isFilled() const { return m_quantity == m_executedQuantity; }
bool isClosed() const { return m_openQuantity == 0; }
m_openQuantity -= quantity;
m_executedQuantity += quantity;
m_lastExecutedPrice = price;
m_lastExecutedQuantity = quantity;
}
void cancel()
{
m_openQuantity = 0;
}
void execute( double price, long quantity )
{
m_avgExecutedPrice =
( ( quantity * price ) + ( m_avgExecutedPrice * m_executedQuantity ) )
/ ( quantity + m_executedQuantity );
m_openQuantity -= quantity;
m_executedQuantity += quantity;
m_lastExecutedPrice = price;
m_lastExecutedQuantity = quantity;
}
void cancel()
{
m_openQuantity = 0;
}
private:
std::string m_clientId;
std::string m_symbol;
std::string m_owner;
std::string m_target;
Side m_side;
Type m_type;
double m_price;
long m_quantity;
long m_openQuantity;
long m_executedQuantity;
double m_avgExecutedPrice;
double m_lastExecutedPrice;
long m_lastExecutedQuantity;
std::string m_clientId;
std::string m_sec_desc;
std::string m_account;
std::string m_owner;
std::string m_target;
std::string m_sender_sub_id;
Side m_side;
Type m_type;
double m_price;
long m_quantity;
MOI m_moi;
long m_openQuantity;
long m_executedQuantity;
double m_avgExecutedPrice;
double m_lastExecutedPrice;
long m_lastExecutedQuantity;
};
inline std::ostream& operator<<( std::ostream& ostream, const Order& order )
{
return ostream
<< "ID: " << std::setw( 10 ) << "," << order.getClientID()
<< " OWNER: " << std::setw( 10 ) << "," << order.getOwner()
<< " PRICE: " << std::setw( 10 ) << "," << order.getPrice()
<< " QUANTITY: " << std::setw( 10 ) << "," << order.getQuantity();
return ostream
<< "ID: " << std::setw( 10 ) << "," << order.getClientID()
<< " OWNER: " << std::setw( 10 ) << "," << order.getOwner()
<< " PRICE: " << std::setw( 10 ) << "," << order.getPrice()
<< " QUANTITY: " << std::setw( 10 ) << "," << order.getQuantity();
}
}}
#endif
@@ -26,21 +26,24 @@
#include <map>
#include <iostream>
namespace bts {
namespace sim {
class OrderMatcher
{
typedef std::map < std::string, Market > Markets;
public:
bool insert( const Order& order )
{
Markets::iterator i = m_markets.find( order.getSymbol() );
Markets::iterator i = m_markets.find( order.getSecDesc() );
if ( i == m_markets.end() )
i = m_markets.insert( std::make_pair( order.getSymbol(), Market() ) ).first;
i = m_markets.insert( std::make_pair( order.getSecDesc(), Market() ) ).first;
return i->second.insert( order );
}
void erase( const Order& order )
{
Markets::iterator i = m_markets.find( order.getSymbol() );
Markets::iterator i = m_markets.find( order.getSecDesc() );
if ( i == m_markets.end() ) return ;
i->second.erase( order );
}
@@ -87,5 +90,5 @@ public:
private:
Markets m_markets;
};
}}
#endif
+2 -1
View File
@@ -5,6 +5,7 @@
#include <memory>
#include <double-conversion/double-conversion.h>
namespace bts {
inline int f_toa (float n,char*buffer, size_t buffer_size,int pad=0)
{
static double_conversion::DoubleToStringConverter const &c =
@@ -39,4 +40,4 @@ inline int f_toa (float n,char*buffer, size_t buffer_size,int pad=0)
return pad;
}
}
}
+1 -1
View File
@@ -47,7 +47,7 @@ void clean_dir(const std::string base_path) {
void run_replay() {
auto naggle_ms = config::get<RelayOptions>().naggle_ms();
auto file = "http://mdreplay/spark/futures.coconut";
auto file = "http://mdreplay.bluetradesys.local/spark/futures.coconut";
replay_recording(file, naggle_ms);
}
@@ -19,6 +19,7 @@ boost::filesystem::path db_location (std::string const&store_root,std::string co
std::string base_path = store_root;
boost::filesystem::path result = utils::normalize_data_path (base_path);
result /= "databases";
result /= db;
result /= db + ".sqlite";
return result;
}
@@ -9,14 +9,14 @@
namespace bts {
namespace orderman {
SingleFillHedger::SingleFillHedger(ISpreaderManager& spreader_manager,
SingleFillHedger::SingleFillHedger(ISpreaderManager& ,
const LegPropertyData& leg_property_data,
bts::orderman::SpreaderOrderBase::ChildOrder order,
bts::Price hedge_price,
bts::Quantity hedge_quantity,
api::Side hedge_side)
:
_spreader_manager(spreader_manager),
// _spreader_manager(spreader_manager),
_leg_property_data (leg_property_data),
_order (order),
_price_quantity_state(hedge_price, hedge_quantity, hedge_side),
@@ -22,7 +22,7 @@ class SpreaderOrderUpdateMessage;
class SingleFillHedger
{
private:
ISpreaderManager& _spreader_manager;
// ISpreaderManager& _spreader_manager;
const LegPropertyData& _leg_property_data;
bts::orderman::SpreaderOrderBase::ChildOrder _order;
HedgePriceQuantityState _price_quantity_state;
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/bash
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
#$SCRIPTPATH/replicate_to_windows_vm.py && \
$SCRIPTPATH/replicate_to_windows_vm.py && \
ssh -p 2222 bts@localhost "cd /mnt/c/Users/bts/spark/tools && /mnt/c/Windows/System32/cmd.exe /c clientbuild.cmd"
+4 -1
View File
@@ -9,11 +9,14 @@ root = socket://localhost:8080/$TARGET
ignore = Path build
ignore = Path .git
ignore = Path externals
ignore = Path cmake-build-debug
ignore = Path .idea
ignore = Path docker
ignore = Regex .*\.pyc
ignore = Path x64
ignore = Path .vs
repeat = watch
prefer = $SOURCE
#repeat = watch
batch = true
'''
+1 -31
View File
@@ -3,34 +3,10 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
mkdir -p $DIR/../build/
cd $DIR/../build/
rm -rf gcc_debug
mkdir gcc_debug
cd gcc_debug
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=g++ ../..
cd ..
rm -rf gcc_release
mkdir gcc_release
cd gcc_release
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ ../..
cd ..
rm -rf clang_debug
mkdir clang_debug
cd clang_debug
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=clang++ ../..
cd ..
rm -rf clang_release
mkdir clang_release
cd clang_release
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++ ../..
cd ..
rm -rf ninja_debug
mkdir ninja_debug
cd ninja_debug
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=g++ ../..
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=/usr/lib/ccache/g++ ../..
cd ..
rm -rf ninja_release
@@ -40,12 +16,6 @@ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ ../..
cd ..
if hash rtags 2>/dev/null; then
rm -rf rtags
mkdir rtags
cd rtags
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=rtags ../..
cd ..
rm -rf rtags_ninja
mkdir rtags_ninja
cd rtags_ninja