Compare commits

..
Author SHA1 Message Date
Pete Fisher d4afcd8379 fixed time on ilink2 audit 2020-09-16 16:35:11 -04:00
Pedro Pinto d2704a5430 Fixed time reporting in iLink3. 2020-09-16 16:34:55 -04:00
Pedro Pinto 85cdfb9eeb Merged from master 2020-08-31 08:20:21 -04:00
Pedro Pinto 167c8c23a0 Fixed batching of orders under iLink3. 2020-08-27 08:19:47 -04:00
Pete Fisher d235f4be41 fixed jetfix.conf ports on relay 2020-08-25 10:03:09 -04:00
Pedro Pinto ec43dbd82d Maybe fixed the self match prevention problem. 2020-08-24 17:02:58 -04:00
Pedro Pinto f07998d6a6 Fixed order rounding error in ilink3 2020-08-24 16:17:31 -04:00
Pedro Pinto b3dc2cdcd4 Changed logging subsystem from ilink3 to iLink3 2020-08-24 11:06:44 -04:00
Pete Fisher 0963aee137 added audit log scripts to be run by the docker container 2020-08-19 17:49:47 -04:00
Pedro Pinto 0cf6af4a85 Merged from master 2020-08-10 14:10:25 -04:00
Pedro Pinto 4e67956f88 Merged with master 2020-06-08 16:16:33 -04:00
Pedro Pinto cd7db5f3a6 Updated subrepos 2020-05-28 12:00:24 -04:00
John Colvin c15ae7b0b0 update jenkinsbuild.cmd to use externals nuget source (for windows) 2020-05-27 11:39:16 -05:00
Pedro Pinto e675db59d7 Merge branch 'cqg_package' of bitbucket.org:bluetradesys/spark into cqg_package 2020-05-27 12:29:58 -04:00
John Colvin 8bd29973df Correctly update externals with windows nuget packages 2020-05-27 11:29:24 -05:00
John Colvin d84d521603 nuget_restore.cmd uses externals package source (builds offline) 2020-05-27 10:56:33 -05:00
John Colvin 53ecf735e0 update externals with windows nuget packages 2020-05-27 10:55:14 -05:00
Pedro Pinto 17435c23a9 Added -f when removing simlinks in build setup. 2020-05-27 11:52:01 -04:00
Pedro Pinto 8873bf56ee Maybe fixed server side build to not require internet 2020-05-26 21:17:46 -04:00
Pedro Pinto b848accc8f Removed dependency on nuget website 2020-05-26 17:30:46 -04:00
Pedro Pinto 8c1606e7c9 Updated setup_builds to work even if its run outside the tree. 2020-05-26 11:29:22 -04:00
John Colvin d277511806 hard code 5 second ladder-recenter-interval 2020-05-24 11:11:08 -05:00
Pedro Pinto 05ed3a39ac Removed private jetfix sessions 2020-05-21 17:42:14 -04:00
Pedro Pinto a389609e73 Made OnixS optional at compile time 2020-05-21 17:20:35 -04:00
Pedro Pinto 6c5ac7f8e0 Defaulted configuration to not use OnixS. 2020-05-21 10:28:59 -04:00
Pedro Pinto 68599af2e4 Removed Onix license from code. 2020-05-20 11:59:42 -04:00
Pedro Pinto 2cd12516b2 Removed ops_notes 2020-05-19 11:55:54 -04:00
Pedro Pinto f48ebcb00d Removed npm download build step 2020-05-19 11:52:04 -04:00
Pedro Pinto a7f404d88f Removed propietary algos, celoxica, passwords, cert_secure_log file 2020-05-19 10:15:03 -04:00
200 changed files with 1689 additions and 92003 deletions

No files matched your search

+8
View File
@@ -1,12 +1,15 @@
cmake_minimum_required(VERSION 3.5)
project(spark)
set (USE_ONIX "FALSE")
if (WIN32)
set (platform "windows")
else ()
set (platform "linux")
endif ()
set (EXTERNALS_ROOT "${CMAKE_SOURCE_DIR}/externals/${platform}")
set (SPARK_PYTHON "${EXTERNALS_ROOT}/python")
set (SPARK_BIN "${EXTERNALS_ROOT}/bin")
@@ -40,6 +43,11 @@ else ()
-fPIC -Wall -pedantic -Wextra -Werror \
-Wno-missing-braces -Wno-ignored-qualifiers \
--std=c++17 -fdiagnostics-color")
if (${USE_ONIX})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DUSE_ONIX")
endif()
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -DNDEBUG -O3")
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wno-undef")
-26
View File
@@ -1,26 +0,0 @@
2.14.0
- Load Algos in libspark.so automatically (no symlink needed)
- Specify commands to run when sparkd starts. These will automatically be killed when sparkd terminates if they are still running.
1.5.7
- Fixed Aggressor coloring and ladder high/low coloring in SIM
1.4.2
- Be sure the system has a bts user before deployment. bts is the superuser, he has all permissions and can see all market data
- After deployment re-permission all existing users for trading, riskadmin, and/or md admin permissions as appropriate
- Also note which users can add other users and accounts and permission them appropriately (Can Add?)
- Permission users for appropriate market data entitlements; this has monetary consequences so ask Kevin if you aren't sure.
- MIC reporting needs to be added to audit Jenkins job (https://bluetradesys.atlassian.net/browse/SPARK-1900)
1.3.5
- Change in market data wire format. Old shell will get only direct market data instead of merged which may not match what the servers is driving from.
1.3.4
- Changed default logging config for Windows. If Logging config is overridden for a system it should be adjusted to override only linux.
1.1.0
- With this release we dropped wild cards from limits, so any user
that has limits expressed in terms of wild cards will have to have
those re-entered explicitly
- With this release we add per user location and smp id tags. At least
the location will have to be set through the admin UI for every user
+1 -3
View File
@@ -10,18 +10,16 @@ using System.Threading.Tasks;
namespace mbts.ui {
[Export(typeof(IShellDaemon))]
class RecenterDaemon : IShellDaemon, IDisposable {
static readonly TimeSpan _time_to_center = TimeSpan.FromSeconds(5);
bool _run = true;
readonly IBus _bus;
readonly TimeSpan _time_to_center;
DateTime _last_recenter;
IDisposable _dispose;
[ImportingConstructor]
public RecenterDaemon(IBus bus) {
_bus = bus;
_time_to_center = TimeSpan.FromSeconds(config.Configuration.get<bts.config.LadderKnobs>().seconds_to_recenter);
_last_recenter = DateTime.UtcNow;
_dispose = _bus.subscribe(SparkTags.RequestRecenterLadder).Subscribe(_ => trigger_recenter(SparkTags.RecenterLadderNow));
run();
}
+1 -2
View File
@@ -36,8 +36,7 @@ namespace bts {
Plugin,
Sdk,
Http,
Spartan,
iLink3
iLink3
// Please keep this list in sync with logging.h/logging.cpp
}
+1 -1
View File
@@ -1 +1 @@
set(sources files/cert_secure_logon.txt;files/futures.coconut.xz;files/onixs_ice/ConnectivityConfiguration.APITest.xml;files/onixs_ice/ConnectivityConfiguration.APITest.xml.orig;files/onixs_ice/ConnectivityConfiguration.PerfTest.xml;files/onixs_ice/ConnectivityConfiguration.Production.xml;files/perf_trace/compiled.css;files/perf_trace/index.html;files/perf_trace/jquery-3.3.1.min.js;files/perf_trace/main.js;files/perf_trace/perf_log.sql;files/perf_trace/perf_trace_analysis.sql;files/perf_trace/plotly-latest.min.js;files/small_es.pcap.xz)
set(sources files/audit_ilink3.py;files/audit_upload.sh;files/audit_uploader.py;files/example.conf;files/futures.coconut.xz;files/onixs_ice/ConnectivityConfiguration.APITest.xml;files/onixs_ice/ConnectivityConfiguration.APITest.xml.orig;files/onixs_ice/ConnectivityConfiguration.PerfTest.xml;files/onixs_ice/ConnectivityConfiguration.Production.xml;files/perf_trace/compiled.css;files/perf_trace/index.html;files/perf_trace/jquery-3.3.1.min.js;files/perf_trace/main.js;files/perf_trace/perf_log.sql;files/perf_trace/perf_trace_analysis.sql;files/perf_trace/plotly-latest.min.js)
+405
View File
@@ -0,0 +1,405 @@
import json
import csv
import datetime, time
import argparse, os
def valid_file(f):
if not os.path.exists(f):
# Argparse uses the ArgumentTypeError to give a rejection message like:
# error: argument input: x does not exist
raise argparse.ArgumentTypeError("{0} does not exist".format(f))
return f
def valid_date(s):
try:
return datetime.datetime.strptime(s, "%Y%m%d")
except ValueError:
raise argparse.ArgumentTypeError("Not a valid date: '{0}'.".format(s))
def print_headers():
# From https://www.cmegroup.com/confluence/display/EPICSANDBOX/iLink+3+-+Minimum+Acceptable+Audit+Trail+Elements+-+Data+Definitions+and+Validation+Rules
line_to_write = "Sending Timestamps,Message Direction,Operator ID,Session ID,Manual Order Indicator,Message Type,Instrument,Order Flow ID,\
CME Globex Order ID,Client Order ID,Order Request ID,Buy/Sell Indicator,Quantity,Limit Price,Stop Price,Order Type,Order Qualifier,IFM Flag,\
Display Quantity,Minimum Quantity,Country of Origin,Fill Price,Fill Quantity,Cumulative Quantity,Remaining Quantity,Aggressor Flag,Source of Cancellation,\
Reject Reason,CME Globex Message ID,Cross ID,Quote Request ID,Message Quote ID,Quote Set ID,Quote Entry ID,Bid Price,Bid Size,Offer Price,Offer Size,\
Processed Entries,Party Details List Request ID,ListUpdateAction,Self-Matching Prevention ID,Self-Match Prevention Instr,Customer Type Indicator,\
AvgPxGroupID,Average Px Ind,CmtaGiveUpCD,Origin,Clearing Trade Price Type,Customer Handling Instr,Executing Firm ID,Account Number,Take Up Firm,Take up Account"
with open (args.output_file, 'w') as the_file:
the_file.write(line_to_write)
the_file.write("\n")
def set_blanks():
return ""
def get_value(json_key):
prices = ["Price", "LastPx", "StopPx"]
if json_key in json_data:
if json_key in prices:
x = json_data[json_key]
return x['mantissa']/100000000000
else:
return json_data[json_key]
else:
return ""
# 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(int(epochtime) / 1e9).strftime('%Y%m%d-%H:%M:%S.%f')
return TIME
# Column 2 - Message Direction
def direction(whichway):
if whichway == '<':
DIRECTION = "FROM CME"
else:
DIRECTION = "TO CME"
return DIRECTION
# Column 3 - Operator ID
def SenderID(sender):
if "SenderID" in json_data:
SENDER = json_data["SenderID"]
return SENDER
else:
return SESSIONID
# Column 4 - Session ID
# Column 5 - Manual Order Indicator
def ManualOrderIndicator(manual):
if "ManualOrderIndicator" in json_data:
if manual == "Manual":
return "1"
else:
return "0"
# Column 6 - Message Type
def MessageType(msg_type,orderstatus):
if msg_type == "NewOrderSingle514":
return "D"
elif msg_type == "ExecutionReportNew522":
return "8--0"
if "ExecutionReportTrade" in msg_type:
if orderstatus == "PartiallyFilled":
return "8--1"
else:
return "8--2"
elif msg_type == "ExecutionReportCancel534":
return "8--4"
elif msg_type == "ExecutionReportModify531":
return "8--5"
elif msg_type == "ExecutionReportCancel534":
return "8--H"
elif msg_type == "ExecutionReportReject523":
return "8--8"
elif msg_type == "OrderCancelReplaceReject536":
return "9--2"
elif msg_type == "OrderCancelReject535":
return "9--1"
elif msg_type == "PartyDetailsDefinitionRequest518":
return "CX"
elif msg_type == "PartyDetailsDefinitionRequestAck519":
return "CY"
elif msg_type == "OrderCancelRequest516":
return "F"
elif msg_type == "OrderCancelReplaceRequest515":
return "G"
# Column 12 - Buy-Sell Indicator/Side
def Side(indicator):
if "Side" in json_data:
if indicator == "Buy":
return "1"
else:
return "2"
# Column 16 - Order Type/OrdType
def OrdType(ordertype):
if "OrdType" in json_data:
if ordertype == "MarketWithProtection" or ordertype == "MarketwithProtection":
return "1"
elif ordertype == "Limit":
return "2"
elif ordertype == "StopWithProtection" or ordertype == "StopwithProtection":
return "3"
elif ordertype == "StopLimit":
return "4"
elif ordertype == "MarketLimit":
return "K"
else:
return ""
# Column 17 - Order Qualifier/TimeInForce
def TimeInForce(orderqual):
if "TimeInForce" in json_data:
if orderqual == "Day":
return "0"
elif orderqual == "GTC":
return "1"
elif orderqual == "FAK":
return "3"
elif orderqual == "GTD":
return "6"
else:
return ""
# Column 18 IFM Flag/OFMOverride
def OFMOverride(imfflag):
if "OFMOverride" in json_data:
if imfflag == "Enabled":
return "1"
else:
return "0"
# Column 19 Display Quantity/DisplayQty
def DisplayQty(qty):
if "DisplayQty" in json_data:
if str(qty) == "0":
return ""
elif str(qty) == "4294967295":
return ""
else:
return qty
# Column 26 - Aggressor Flag/AggressorIndicator
def AggressorIndicator(aggressor):
if "AggressorIndicator" in json_data:
if aggressor == "True":
return "1"
else:
return "0"
# Column 27 - Source of Cancellation/ExecRestatementReason
def ExecRestatementReason(sourcecancel):
if "ExecRestatementReason" in json_data:
if sourcecancel == "Exchange":
return "8"
elif sourcecancel == "CancelledNotBest":
return "9"
elif sourcecancel == "CancelOnDisconnect":
return "100"
elif sourcecancel == "CancelRestingDueToSelfMatchPrevention":
return "103"
elif sourcecancel == "CancelFromCMEGlobexCreditControlsViolation":
return "104"
elif sourcecancel == "CancelFromCMEOne":
return "105"
elif sourcecancel == "CancelFromRiskManagementAPI":
return "106"
elif sourcecancel == "CancelAggressingDueToSelfMatchPrevention":
return "107"
elif sourcecancel == "CancelDueToVolatilityQuoteOptionLessThanMinOrderSize":
return "108"
else:
return ""
# Column 43 - Self-Match Prevention Instr/SelfMatchPreventionInstruction
def SelfMatchPreventionInstruction(instr):
if "SelfMatchPreventionInstruction" in json_data:
if instr == "CancelOldest":
return "O"
elif instr == "CancelNewest":
return "N"
else:
return ""
# Column 44 - Customer Type Indicator/CustOrderCapacity
def CustOrderCapacity(custord):
if "CustOrderCapacity" in json_data:
if custord == "NULL_VALUE":
return ""
elif custord == "Membertradingfortheirownaccount":
return "1"
elif custord == "ClearingFirmtradingforitsproprietaryaccount":
return "2"
elif custord == "Membertradingforanothermember":
return "3"
else:
return "4"
# Column 46 - Average Px Ind/AvgPxInd
def AvgPxInd(avgpxindicator):
if "AvgPxInd" in json_data:
if avgpxindicator == "NULL_VALUE":
return ""
else:
return avgpxindicator
# Column 48 - Origin/ClearingAccountType
def ClearingAccountType(accounttype):
if "ClearingAccountType" in json_data:
if accounttype == "Customer":
return "0"
elif accounttype == "Firm":
return "1"
else:
return ""
# Column 49 - Clearing Trade Price Type/ClearingTradePriceType
def ClearingTradePriceType(clrtrdprice):
if "ClearingTradePriceType" in json_data:
if clrtrdprice == "NULL_VALUE":
return "0"
else:
return "3"
# Column 50 - Customer Handling Instr/CustOrderHandlingInst
def CustOrderHandlingInst(custorderinst):
if "CustOrderHandlingInst" in json_data:
if custorderinst == "ClientElectronic":
return "C"
elif custorderinst == "TEST":
return "D"
else:
return ""
# Column 51 and 52 - Getting the Firm and Account Number
def partyid(partydetailid,column):
for x in partydetailid:
role = x['PartyDetailRole']
id = x['PartyDetailID']
if column == "51" and role == "ExecutingFirm":
return id
if column == "52" and role == "CustomerAccount":
return id
parser = argparse.ArgumentParser()
parser.add_argument("json_log", help="the json log[.gz] you wish to process", type=valid_file)
parser.add_argument("output_file", help="the destination csv file you wish to write")
parser.add_argument("-d", "--date", help="the date you wish to parse from the log, specified as YYYYmmdd",
default=datetime.datetime.today().strftime("%Y%m%d"), type=valid_date)
args = parser.parse_args()
print_headers()
list_types = ['NewOrderSingle514', 'OrderCancelReplaceRequest515', 'OrderCancelRequest516', 'PartyDetailsDefinitionRequest518', 'PartyDetailsDefinitionRequestAck519', \
'ExecutionReportNew522', 'ExecutionReportReject523', 'ExecutionReportTradeOutright525', 'ExecutionReportTradeSpread526', 'ExecutionReportTradeSpreadLeg527', \
'ExecutionReportModify531', 'ExecutionReportCancel534', 'OrderCancelReject535', 'OrderCancelReplaceReject536', ]
# Note that the timedeltas specificed in trade_day_start and trade_day_end
# are based on Chicago times; as such, this script should run on a machine
# set to a Chicago timezone. A future impromovement would be to determine
# the current machine's timezone and determine the appropriate offset
# versus Chicago time, but for now we assume this will run on a Chicago
# tz machine.
input_as_datetime = args.date
trade_day_start = input_as_datetime - datetime.timedelta(days=1) + datetime.timedelta(hours=16, minutes=30)
trade_day_utc_start = time.gmtime((time.mktime(trade_day_start.timetuple())))
trade_day_end = input_as_datetime + datetime.timedelta(hours=16)
trade_day_utc_end = time.gmtime((time.mktime(trade_day_end.timetuple())))
file_opener = None
if args.json_log.endswith(".gz"):
import gzip
file_opener = gzip.open
else:
file_opener = open
#inputFile = open(fileInput) #open json file
#outputFile = open(fileOutput, 'w') #load csv file
# Get Session
with file_opener(args.json_log) as json_file:
for line in json_file:
data = json.loads(line)
json_data = data['msg_json']
if "Session" in json_data:
SESSIONID = json_data["Session"]
#inputFile = open(fileInput) #open json file
#outputFile = open(fileOutput, 'w') #load csv file
with file_opener(args.json_log) as json_file:
for line in json_file:
data = json.loads(line)
line_timestamp = time.strptime(data['time'], "%Y%m%d-%H:%M:%S.%f")
if trade_day_utc_start <= line_timestamp <= trade_day_utc_end:
json_data = data['msg_json']
NAME = json_data["Name"]
if NAME in list_types:
EXECUTING_FIRM_ID = ""
ACCOUNT_NUMBER = ""
DIRECTION = direction(data['direction'])
# Set Blanks
blank_json = {'QuoteReqID': '', 'QuoteID': '', 'QuoteSetID': '', 'QuoteEntryID': '', 'BidPx': '', 'BidSize': '', 'OfferPx': '', \
'OfferSize': '', 'NoProcessedEntries': '', 'ListUpdateAction': '', 'MinQty': '', 'AvgPxGroupID': '', \
'CmtaGiveUpCD': '', 'TAKE_UP_FIRM': '', 'TAKE_UP_ACCOUNT': '',}
# No Data Processing
straight_json = {'SecurityID': '', 'ClOrdID': '', 'OrderID': '', 'OrderRequestID': '', 'OrderQty': '', \
'Location': '', 'LastQty': '', 'CumQty': '', 'LeavesQty': '', 'Text': '', 'SideTradeID': '', 'CrossID': '', 'SelfMatchPreventionID': '', \
'Price': '', 'StopPx': '', 'LastPx': '', 'PartyDetailsListReqID': '', 'OrdStatus': ''}
# Processing Data
process_json = {'SendingTimeEpoch': '', 'ManualOrderIndicator': '', 'SenderID': '', 'Side': '', 'OrdType': '', 'TimeInForce': '', \
'OFMOverride': '', 'AggressorIndicator': '', 'ExecRestatementReason': '', 'SelfMatchPreventionInstruction': '', 'CustOrderCapacity': '', \
'AvgPxInd': '', 'ClearingAccountType': '', 'ClearingTradePriceType': '', 'CustOrderHandlingInst': '', 'DisplayQty': ''}
for d in straight_json:
test = get_value(d)
if test != "None" or test != "":
if "," in str(test):
test = test.replace(",",";")
if "4294967295" in str(test):
test = ""
if "us;" in str(test):
test = test.upper()
if d == "SelfMatchPreventionID" and len(str(test)) > 8:
test = ""
straight_json[d] = test
else:
straight_json[d] = ''
for d in process_json:
if d in json_data:
function = locals()[d]
test = function(json_data[d])
if test != "None":
process_json[d] = test
else:
process_json[d] = ''
elif d == "SenderID":
function = locals()[d]
test = function(SenderID)
if test != "None":
process_json[d] = test
# Party Message Fields
# Column 51 - Executing Firm ID
if "NoPartyDetails" in json_data:
EXECUTING_FIRM_ID = partyid(json_data['NoPartyDetails'], "51")
# Column 52 - Party Account Number
ACCOUNT_NUMBER = partyid(json_data['NoPartyDetails'], "52")
line_to_write = process_json['SendingTimeEpoch'] + "," + DIRECTION + "," + process_json['SenderID'] + "," + SESSIONID + "," + process_json['ManualOrderIndicator'] + "," + \
MessageType(NAME,straight_json['OrdStatus']) + "," + str(straight_json['SecurityID']) + "," + str(straight_json['ClOrdID']) + "," + str(straight_json['OrderID']) + "," + str(straight_json['ClOrdID']) + "," + \
str(straight_json['OrderRequestID']) + "," + process_json['Side'] + "," + str(straight_json['OrderQty']) + "," + str(straight_json['Price']) + "," + \
str(straight_json['StopPx']) + "," + process_json['OrdType'] + "," + process_json['TimeInForce'] + "," + process_json['OFMOverride'] + "," + str(process_json['DisplayQty']) + "," + \
blank_json['MinQty'] + "," + straight_json['Location'] + "," + str(straight_json['LastPx']) + "," + str(straight_json['LastQty']) + "," + str(straight_json['CumQty']) + "," + \
str(straight_json['LeavesQty']) + "," + process_json['AggressorIndicator'] + "," + process_json['ExecRestatementReason'] + "," + str(straight_json['Text']) + "," + \
str(straight_json['SideTradeID']) + "," + str(straight_json['CrossID']) + "," + blank_json['QuoteReqID'] + "," + blank_json['QuoteID'] + "," + blank_json['QuoteSetID'] + "," + \
blank_json['QuoteEntryID'] + "," + blank_json['BidPx'] + "," + blank_json['BidSize'] + "," + blank_json['OfferPx'] + "," + blank_json['OfferSize'] + "," + \
blank_json['NoProcessedEntries'] + "," + str(straight_json['PartyDetailsListReqID']) + "," + blank_json['ListUpdateAction'] + "," + str(straight_json['SelfMatchPreventionID']) + "," + \
process_json['SelfMatchPreventionInstruction'] + "," + process_json['CustOrderCapacity'] + "," + blank_json['AvgPxGroupID'] + "," + process_json['AvgPxInd'] + "," + \
blank_json['CmtaGiveUpCD'] + "," + str(process_json['ClearingAccountType']) + "," + process_json['ClearingTradePriceType'] + "," + process_json['CustOrderHandlingInst'] + "," + \
EXECUTING_FIRM_ID + "," + str(ACCOUNT_NUMBER) + "," + blank_json['TAKE_UP_FIRM'] + "," + blank_json['TAKE_UP_ACCOUNT']
#print(line_to_write)
with open (args.output_file, 'a') as the_file:
the_file.write(line_to_write)
the_file.write("\n")
+73
View File
@@ -0,0 +1,73 @@
#/bin/bash
function help_and_exit()
{
echo
echo Usage: $0 [option]... config_file
echo
echo Can also be used in cron like the following
echo 40 16 * * 1-5 /usr/bin/docker exec spark_10000 bash /sparkbin/data_files/audit_upload.sh /sparkdata/data/audit_uploads/example.conf
echo example.conf included. The location of the conf file should be relative to the docker container, not the host
echo
echo Options are as follows:
echo " -d|--date YYYYMMDD Example is 20180731"
echo " Help: "
echo " -h|--help Display this message."
echo
exit 1
}
DATE=$(date +%Y%m%d)
ORIG_DIR=$(pwd)
ERROR_LEVEL="0"
while getopts "d:h" option; do
case $option in
d) DATE=$OPTARG ;;
h) help_and_exit;;
\?) echo "Invalid option: -$OPTARG" >&2;
exit 1;;
esac
done
shift $((OPTIND-1))
CONFIG_FILE=$1
declare -A conf_vars; while read line; do conf_vars[${line%=*}]=${line#*=}; done <$CONFIG_FILE
SESSION_ID=${conf_vars[session_id]}
FCM=${conf_vars[fcm]}
CLIENT=${conf_vars[client]}
cd /sparkbin/data_files
for SESSION in $(ls /sparkdata/data/ilink3/); do
if [[ $SESSION == *$SESSION_ID* ]]; then
echo "Session is $SESSION"
SESSION_DAY=$(date +%Y-%m-%d)
if [[ $SESSION == "cme_"* ]]; then
SESSION_DAY=$(date -d "$DATE -$(date -d $DATE +%u) days" +"%Y-%m-%d")
AUDIT_SCRIPT="audit_ilink3.py"
fi
echo $SESSION_DAY
if [[ ! -d /sparkdata/data/ilink3/$SESSION/audit_logs ]]; then
mkdir -p /sparkdata/data/ilink3/$SESSION/audit_logs
fi
if [[ -d /sparkdata/data/ilink3/$SESSION/$SESSION_DAY ]]; then
echo "Starting the creation of the audit log"
python $AUDIT_SCRIPT -d $DATE /sparkdata/data/ilink3/$SESSION/$SESSION_DAY/log /sparkdata/data/ilink3/$SESSION/audit_logs/"$FCM"_audit_"$SESSION"_"$DATE".csv
fi
if [[ ! -d /sparkdata/data/md_audit ]]; then
mkdir /sparkdata/data/md_audit
fi
if [[ -d /sparkdata/data/md_audit ]]; then
# Running the MD Audit csv generation
cd /sparkbin
./sparkd adminreport md > /sparkdata/data/md_audit/"$FCM"_md_"$CLIENT"_"$DATE".csv
cd /sparkbin/data_files
fi
echo "Uploading to the (s)FTP Server"
python audit_uploader.py --config_file="$CONFIG_FILE" --datestamp $DATE --session="$SESSION" --client="$CLIENT" --fcm="$FCM"
fi
done
+150
View File
@@ -0,0 +1,150 @@
import getopt, sys, datetime
import paramiko, ftplib
#########################################################
# Commandline Args #
#########################################################
def usage():
print "-------------------------------------------------------"
print "-Usage: -"
print "-------------------------------------------------------"
print "- --config_file= : Path to upload config file -"
print "- -if no path is specified look -"
print "- in the working directory. -"
print "- -"
print "- --help : Print this message -"
print "- -"
print "- --datestamp= : Optional, defaults to today -"
print "- -replaces *datestamp in the -"
print "- the upload config file -"
print "- -"
print "- --fcm : Optional, spark input -"
print "- -"
print "- --session : Optional, spark jf session -"
print "-------------------------------------------------------"
fcm = ''
session = ''
try:
options, arguments = getopt.getopt(sys.argv[1:],"h",['config_file=', 'datestamp=', 'help', 'fcm=', 'client=', 'session='])
except getopt.GetoptError, err:
print str(err)
usage()
sys.exit(2)
for option, value in options:
if option in ("-h","--h","-help","--help"):
usage()
sys.exit()
elif option in ("-config_file","--config_file"):
config_file = value
elif option in ("-datestamp","--datestamp"):
datestamp = value
elif option in ("-fcm","--fcm"):
fcm = value
elif option in ("-client","--client"):
client = value
elif option in ("-session","--session"):
session = value
for argument in arguments:
if argument in ("h", "help"):
usage()
sys.exit()
else:
print "Unrecognized commandline argument. Type help for usage."
sys.exit()
if len(options) <= 0:
print "Requires a config file to run."
usage()
sys.exit()
#########################################################
# Read Config Function #
#########################################################
def read_config_file(config_file, datestamp=datetime.datetime.today().strftime('%Y%m%d'), fcm=fcm, session=session):
'''
Parse our config file that gets passed in as a commandline parameter.
All config keys must be of the form key=value. White space is ignored.
All config keys must be seperated by a newline character.
Called during initialization.
'''
upload_config = {}
config_file = open(config_file, 'r')
config_file = config_file.read()
for config in config_file.split("\n"):
if '=' in config:
cleaned_key = config.split('=')[0].strip().upper()
cleaned_value = config.split('=')[1].strip()
if '*datestamp*' in cleaned_value:
cleaned_value = cleaned_value.replace('*datestamp*',datestamp)
if '*fcm*' in cleaned_value:
cleaned_value = cleaned_value.replace('*fcm*',fcm)
if '*client*' in cleaned_value:
cleaned_value = cleaned_value.replace('*client*',client)
if '*session*' in cleaned_value:
cleaned_value = cleaned_value.replace('*session*',session)
upload_config[cleaned_key] = cleaned_value
else:
pass
return upload_config
#########################################################
# FTP File Transfer Function #
#########################################################
def putfile_ftp(file, put_path, site, user, password, port=21, verbose=True):
if verbose: print 'Uploading', file
local = open(file, 'rb')
remote = ftplib.FTP(site)
remote.login(user, password)
remote.storbinary(put_path, local, 1024)
remote.quit()
local.close()
if verbose: print 'Upload done.'
#########################################################
# SFTP File Transfer Function #
#########################################################
def putfile_sftp(file, put_path, site, username, password, port=22, verbose=True):
transport = paramiko.Transport((site, port))
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
sftp.put(file, put_path)
sftp.close()
transport.close()
#########################################################
# Main #
#########################################################
#if datestamp != None:
# upload_config = read_config_file(config_file, datestamp)
#else:
# upload_config = read_config_file(config_file)
try:
datestamp
except NameError:
upload_config = read_config_file(config_file)
else:
upload_config = read_config_file(config_file, datestamp)
print upload_config
if upload_config["PROTOCOL_PUT"] in ['FTP','ftp']:
print "Protocol = FTP"
putfile_ftp(upload_config["GET_ILINK3_FILE_PATH"] + upload_config["GET_ILINK3_FILE_NAME"], upload_config["PUT_ILINK3_FILE_PATH"] + upload_config["PUT_ILINK3_FILE_NAME"], upload_config["PUT_HOST"], upload_config["USERNAME_PUT"], upload_config["PASSWORD_PUT"], upload_config["PORT_PUT"] )
putfile_ftp(upload_config["GET_MD_FILE_PATH"] + upload_config["GET_MD_FILE_NAME"], upload_config["PUT_MD_FILE_PATH"] + upload_config["PUT_MD_FILE_NAME"], upload_config["PUT_HOST"], upload_config["USERNAME_PUT"], upload_config["PASSWORD_PUT"], upload_config["PORT_PUT"] )
elif upload_config["PROTOCOL_PUT"] in ['SFTP','sftp']:
print "Protocol = SFTP"
putfile_sftp(upload_config["GET_ILINK3_FILE_PATH"] + upload_config["GET_ILINK3_FILE_NAME"], upload_config["PUT_ILINK3_FILE_PATH"] + upload_config["PUT_ILINK3_FILE_NAME"], upload_config["PUT_HOST"], upload_config["USERNAME_PUT"], upload_config["PASSWORD_PUT"], int(upload_config["PORT_PUT"]) )
putfile_sftp(upload_config["GET_MD_FILE_PATH"] + upload_config["GET_MD_FILE_NAME"], upload_config["PUT_MD_FILE_PATH"] + upload_config["PUT_MD_FILE_NAME"], upload_config["PUT_HOST"], upload_config["USERNAME_PUT"], upload_config["PASSWORD_PUT"], int(upload_config["PORT_PUT"]) )
@@ -1,19 +0,0 @@
Session ID Access ID Secret Key Creation Date Expiration Date Environment
M4D lLtjH74y1Kh5XUJTLyH2 f1K_tROQp2lTIplVp34WxKa7xDUgfFnIteolfik061o 2019-09-03 2020-09-03 CERT
MC1 VEMlkDuLz74OVHSuacQB IuHyYT3b-9KUo3WsuXykt-fXsjzp7L-JOrdCSQZLNl0 2019-09-03 2020-09-03 CERT
MC5 77lzSUwPLlM9obaXh2mK z6aA9qfASDKfZkYTVKFqJd-78i0HZ2Q9ec3CKCYIqHg 2019-09-03 2020-09-03 CERT
MC7 RphzI3rn71oGUEiYnX9e y6OvvPPyoyj2S8YAnE1gFduXT8v29HIMjO5EngYxSNg 2019-09-03 2020-09-03 CERT
MC8 PYBIm2TI9gFPIxmHbuYl 6o-ZolGH2DdeQOlGtJ5Zqoh_kg7VdbxkmjeOHmigKwU 2019-09-03 2020-09-03 CERT
NGG RYcigz3bSLIIBBF2A2Hq qB1dm9VkTKeXcdQpFzla8B3_jwTgya_-Fk5iyEJvr2E 2020-06-15 2021-06-15 NEWRELEASE
NGF o4OTmmTLQ7Lv4g6bCm26 HbD3FneMyb9Fu-FkCDLscCczHqFcFE2PyWv978RXGyA 2019-12-20 2020-12-20 NEWRELEASE
UZE EeFdZ1FPepk6U4k3xBZA 2LjEtdLvBLLB1QuDJ4KiJW6M4dF6IHWd_UKmo7p3_Us 2020-06-24 2021-06-24 NEWRELEASE
VAE Y8iqatTewuoHX16gghw8 FNcCB3Ks1qleS56quYzH4V7zAu78YY2bCdLRi9tmU9E 2020-06-24 2021-06-24 NEWRELEASE
+16
View File
@@ -0,0 +1,16 @@
fcm=FCM
client=NAME
session_id=ses
put_host=ftpc.example.com
port_put=2222
username_put=user
password_put=password
protocol_put=sftp
get_ilink3_file_path=/sparkdata/data/ilink3/*session*/audit_logs/
put_ilink3_file_path=/
get_ilink3_file_name=*fcm*_audit_*session*_*datestamp*.csv
put_ilink3_file_name=*fcm*_audit_*session*_*datestamp*.csv
get_md_file_path=/sparkdata/data/md_audit/
put_md_file_path=/
get_md_file_name=*fcm*_md_*client*_*datestamp*.csv
put_md_file_name=*fcm*_md_*client*_*datestamp*.csv
@@ -15,8 +15,8 @@
<server name="default">
<ip>63.247.113.163</ip>
<port>3000</port>
<userName>katas2f-ps</userName>
<password>Starts123</password>
<userName></userName>
<password></password>
<getStripInfoMessages>N</getStripInfoMessages>
<strategyPreference>New</strategyPreference>
<localNetworkInterface></localNetworkInterface>
@@ -24,8 +24,8 @@
<server name="endex">
<ip>63.247.113.77</ip>
<port>3000</port>
<userName>katas2f-ps</userName>
<password>Starts123</password>
<userName>Value from ICE Support</userName>
<password>Value from ICE Support</password>
<getStripInfoMessages>N</getStripInfoMessages>
<strategyPreference>New</strategyPreference>
<localNetworkInterface></localNetworkInterface>
@@ -33,8 +33,8 @@
<server name="liffe-eu">
<ip>63.247.113.229</ip>
<port>3000</port>
<userName>bluetrdl-ps</userName>
<password>Starts123</password>
<userName></userName>
<password></password>
<getStripInfoMessages>N</getStripInfoMessages>
<strategyPreference>New</strategyPreference>
<localNetworkInterface></localNetworkInterface>
@@ -17,8 +17,8 @@
<server name="default">
<ip>63.247.113.214</ip>
<port>3000</port>
<userName>bt_ps</userName>
<password>Starts123</password>
<userName></userName>
<password></password>
<getStripInfoMessages>N</getStripInfoMessages>
<strategyPreference>New</strategyPreference>
<localNetworkInterface></localNetworkInterface>
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/service_helpers/PositionUtilities.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/BasePositionService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarginService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/MarketDataService.proto;api/services/MoneyFileService.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/position_cfg.conf;config/defaults/span.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/AlgoTypes.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/keycode.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/position_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/span.proto;config/protos/spartan.proto;config/protos/spreader.proto;config/protos/subprocess.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/sod.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.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/sample_fix.cpp;jetfix/tests/store_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/Product.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityMapper.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/service/MarketDataServiceServer.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;md/vendor/OnixsUtils.cpp;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/ExecutoLine truncated
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/service_helpers/PositionUtilities.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/BasePositionService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarginService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/MarketDataService.proto;api/services/MoneyFileService.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/position_cfg.conf;config/defaults/span.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/AlgoTypes.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/keycode.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/position_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/span.proto;config/protos/spreader.proto;config/protos/subprocess.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/sod.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.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/sample_fix.cpp;jetfix/tests/store_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/Product.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityMapper.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/service/MarketDataServiceServer.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;md/vendor/OnixsUtils.cpp;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cLine truncated
+1 -1
View File
@@ -1 +1 @@
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/service_helpers/PositionUtilities.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/BasePositionService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarginService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/MarketDataService.proto;api/services/MoneyFileService.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/position_cfg.conf;config/defaults/span.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/AlgoTypes.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/keycode.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/position_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/span.proto;config/protos/spartan.proto;config/protos/spreader.proto;config/protos/subprocess.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/sod.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/Product.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityMapper.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/service/MarketDataServiceServer.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;md/vendor/OnixsUtils.cpp;os/os.cpp;os/tests/os_tests.cpp;quickbus/core/LocalNode.cpp;quickbus/core/Quickbus.cpp;quickbus/core/SubscriptionID.cpp;quickbus/core/TableID.cpp;quickbus/message_model/Update.cpp;quickbus/message_model/merge_updates.cpp;quickbus/network/QBConnection.cpp;quickbus/network/QBConnectionManager.cpp;quickbus/network/endpoint_description.cpp;quickbus/network/quickbus_msgs.proto;quickbus/pubsub/TablePublisher.cpp;quickbus/pubsub/TableSubscriber.cpp;quickbus/pubsub/tests/qb_pubsub_tests.cpp;quickbus/routing/INode.cpp;quickbus/routing/NodeID.cpp;quickbus/routing/Router.cpp;quickbus/rpc/RPCClient.cpp;quickbus/rpc/RPCServer.cpp;quickbus/rpc/RPCSessionID.cpp;quickbus/rpc/rpc_utils.cpp;quickbus/rpc/tests/qb_rpc_tests.cpp;quickbus/tests/quickbus_tests.cpp;sparkproto/SparkProtos.proto;testing/catch_testLine truncated
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/service_helpers/PositionUtilities.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/BasePositionService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarginService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/MarketDataService.proto;api/services/MoneyFileService.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/position_cfg.conf;config/defaults/span.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/AlgoTypes.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/keycode.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/position_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/span.proto;config/protos/spreader.proto;config/protos/subprocess.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/sod.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/Product.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityMapper.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/service/MarketDataServiceServer.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;md/vendor/OnixsUtils.cpp;os/os.cpp;os/tests/os_tests.cpp;quickbus/core/LocalNode.cpp;quickbus/core/Quickbus.cpp;quickbus/core/SubscriptionID.cpp;quickbus/core/TableID.cpp;quickbus/message_model/Update.cpp;quickbus/message_model/merge_updates.cpp;quickbus/network/QBConnection.cpp;quickbus/network/QBConnectionManager.cpp;quickbus/network/endpoint_description.cpp;quickbus/network/quickbus_msgs.proto;quickbus/pubsub/TablePublisher.cpp;quickbus/pubsub/TableSubscriber.cpp;quickbus/pubsub/tests/qb_pubsub_tests.cpp;quickbus/routing/INode.cpp;quickbus/routing/NodeID.cpp;quickbus/routing/Router.cpp;quickbus/rpc/RPCClient.cpp;quickbus/rpc/RPCServer.cpp;quickbus/rpc/RPCSessionID.cpp;quickbus/rpc/rpc_utils.cpp;quickbus/rpc/tests/qb_rpc_tests.cpp;quickbus/tests/quickbus_tests.cpp;sparkproto/SparkProtos.proto;testing/catch_test_runner.cpp;utils/AuthSessioLine truncated
-4
View File
@@ -130,13 +130,9 @@ else ()
cryptopp
pugixml
lttng-ust
Pcap++
Packet++
Common++
ssh2
-lrt
-ldl
-lpcap
-static-libgcc
-static-libstdc++
-pthread)
@@ -1645,9 +1645,9 @@ void AdminServiceUtils::bootstrap_data (bts::api::admin::AdminData& data){
exchange_user_data.mutable_ice_data()->set_operator_id("op_id_" + user_1->name());
exchange_user_data.mutable_ice_data()->set_company_id(51251);
exchange_user_data.mutable_ice_data()->set_authorized_trader("bluetrd-fx");
exchange_user_data.mutable_ice_data()->set_authorized_trader("");
exchange_user_data.mutable_ice_data()->set_authorized_group("Group");
exchange_user_data.mutable_ice_data()->set_password("Starts123");
exchange_user_data.mutable_ice_data()->set_password("");
exchange_user_data.mutable_ice_data()->set_mifid_direct_electronic_access(-1);
exchange_user_data.mutable_ice_data()->set_mifid_trading_capacity(-1);
exchange_user_data.mutable_ice_data()->set_mifid_liquidity_provision(-1);
@@ -1666,9 +1666,9 @@ void AdminServiceUtils::bootstrap_data (bts::api::admin::AdminData& data){
exchange_user_data.mutable_ice_data()->set_operator_id("op_id_" + user_2->name());
exchange_user_data.mutable_ice_data()->set_company_id(51251);
exchange_user_data.mutable_ice_data()->set_authorized_trader("bluetrd-fx");
exchange_user_data.mutable_ice_data()->set_authorized_trader("");
exchange_user_data.mutable_ice_data()->set_authorized_group("Group");
exchange_user_data.mutable_ice_data()->set_password("Starts123");
exchange_user_data.mutable_ice_data()->set_password("");
exchange_user_data.mutable_ice_data()->set_mifid_direct_electronic_access(-1);
exchange_user_data.mutable_ice_data()->set_mifid_trading_capacity(-1);
exchange_user_data.mutable_ice_data()->set_mifid_liquidity_provision(-1);
@@ -1688,9 +1688,9 @@ void AdminServiceUtils::bootstrap_data (bts::api::admin::AdminData& data){
exchange_user_data.mutable_ice_data()->set_operator_id("op_id_" + user_3->name());
exchange_user_data.mutable_ice_data()->set_company_id(51251);
exchange_user_data.mutable_ice_data()->set_authorized_trader("bluetrd-fx");
exchange_user_data.mutable_ice_data()->set_authorized_trader("");
exchange_user_data.mutable_ice_data()->set_authorized_group("Group");
exchange_user_data.mutable_ice_data()->set_password("Starts123");
exchange_user_data.mutable_ice_data()->set_password("");
exchange_user_data.mutable_ice_data()->set_mifid_direct_electronic_access(-1);
exchange_user_data.mutable_ice_data()->set_mifid_trading_capacity(-1);
exchange_user_data.mutable_ice_data()->set_mifid_liquidity_provision(-1);
+137 -130
View File
@@ -1,136 +1,143 @@
#
# Common Market data options
#
MarketDataConfig {
rule: "DeploymentType.type == 'PROD'"
value {
use_sim: false
}
}
PublisherOptions {
rule: "DeploymentType.type == 'dev'"
value {
disable_heartbeat: true
}
}
PlatformMap {
value {
glbx_platform: "PLATFORM_MDP3ONIXS"
ice_platform: "PLATFORM_ICEONIXS"
}
}
PublisherNamespace {
value {
shared_memory_namespace: @System.os_user
}
}
CMEOptions {
value {
feed_engine {
name: "mdp3feed"
# udp_socket_buffer_size: 425984
# channels_per_thread: 1
spin_time: 0
}
channel {
id: "*"
feed_engine: "mdp3feed"
use_tcp_replay: false
}
}
}
#
# Common Market data options
#
MarketDataConfig {
rule: "DeploymentType.type == 'PROD'"
value {
use_sim: false
}
}
MarketDataConfig {
value {
use_sim: true
use_onixs: false
}
}
PublisherOptions {
rule: "DeploymentType.type == 'dev'"
value {
disable_heartbeat: true
}
}
PlatformMap {
value {
glbx_platform: "PLATFORM_MDP3ONIXS"
ice_platform: "PLATFORM_ICEONIXS"
}
}
PublisherNamespace {
value {
shared_memory_namespace: @System.os_user
}
}
CMEOptions {
value {
feed_engine {
name: "mdp3feed"
# udp_socket_buffer_size: 425984
# channels_per_thread: 1
spin_time: 0
}
channel {
id: "*"
feed_engine: "mdp3feed"
use_tcp_replay: false
}
}
}
ICEPublisherOptions {
value {
network_interface: "eth1"
}
}
#to make this work in dev clone the operations repo
#go here: c:\\code\\bts\\operations\\ice\\ICE_iMpactMulticastFeed_GettingStarted-1_1_36\\bin\\easyTunnel>
#modify the easyTunnelProxy.properties file to replace
#tunnel.multicast.interface=10.96.18.37 with your local ip
#run easyTunnelProxy.bat BRENT-FI for Brent Full implied
#you should see ice data
ICEOptions {
value {
channel {
name: "oil" #these names are arbitrary and are for debugging
market_type: 3
uds_market_type: 3
market_type: 4 #ICE IPE Gas Oil Futures
uds_market_type: 4
market_type: 5 #ICE Futures Brent, IPE Brent Futures
uds_market_type: 5
market_type: 9 #ICE Futures WTI, ICE WTI Crude Futures
uds_market_type: 9
market_type: 13 #ICE Heating Oil Futures
uds_market_type: 13
market_type: 15 #ICE NYH (RBOB) Gasoline Futures
uds_market_type: 15
##market_type: 21 #ICE Futures US Agricultures, Coffee C
##uds_market_type: 21
##market_type: 23 #ICE Futures US Agricultures, FCOJ A
##uds_market_type: 23
##market_type: 26 #ICE Futures US Financials DX
##uds_market_type: 26
uds_market_type: 11 #ICE WTI-Brent spreads
uds_market_type: 14 #ICE Heating Oil/WTI Futures Crack
uds_market_type: 16 #ICE NYH (RBOB) Gasoline/WTI Futures Crack
uds_market_type: 58 #ICE Futures UI Heating Oil / Brent
uds_market_type: 59 #ICE NYH (RBOB) Gasoline/Brent Futures Crack
uds_market_type: 66 #ICE NYH (RBOB) Gasoline/Heating Oil Spread
uds_market_type: 70 #ICE Heating Oil/LS Gasoil Futures Spread
uds_market_type: 71 #ICE LS Gasoil/Brent Futures Crack
uds_market_type: 72 #ICE NYH (RBOB) Gasoline/LS Gasoil Futures Spread
#onixs_log_mode: Debug
}
# channel {
# name: "juice"
# market_type: 26 #ICE Futures US Agricultures, FCOJ A
# }
ice_config_file: "ConnectivityConfiguration.APITest.xml"
#ice_config_file: "ConnectivityConfiguration.PerfTest.xml"
}
}
MDBootDelayWindow {
rule: "DeploymentType.type == 'dev'"
value {
delay_seconds: 0
}
}
MDBootDelayWindow {
value {
delay_seconds: 120
standard {
start: "16:30"
end: "16:40"
}
sunday {
start: "14:00"
end: "14:10"
}
}
}
DisplayFactorOverride {
value {
override {
symbol: "SOM"
exchange: "GLBX"
type: "SPREAD"
price_multiplier: 1
}
}
}
#to make this work in dev clone the operations repo
#go here: c:\\code\\bts\\operations\\ice\\ICE_iMpactMulticastFeed_GettingStarted-1_1_36\\bin\\easyTunnel>
#modify the easyTunnelProxy.properties file to replace
#tunnel.multicast.interface=10.96.18.37 with your local ip
#run easyTunnelProxy.bat BRENT-FI for Brent Full implied
#you should see ice data
ICEOptions {
value {
channel {
name: "oil" #these names are arbitrary and are for debugging
market_type: 3
uds_market_type: 3
market_type: 4 #ICE IPE Gas Oil Futures
uds_market_type: 4
market_type: 5 #ICE Futures Brent, IPE Brent Futures
uds_market_type: 5
market_type: 9 #ICE Futures WTI, ICE WTI Crude Futures
uds_market_type: 9
market_type: 13 #ICE Heating Oil Futures
uds_market_type: 13
market_type: 15 #ICE NYH (RBOB) Gasoline Futures
uds_market_type: 15
##market_type: 21 #ICE Futures US Agricultures, Coffee C
##uds_market_type: 21
##market_type: 23 #ICE Futures US Agricultures, FCOJ A
##uds_market_type: 23
##market_type: 26 #ICE Futures US Financials DX
##uds_market_type: 26
uds_market_type: 11 #ICE WTI-Brent spreads
uds_market_type: 14 #ICE Heating Oil/WTI Futures Crack
uds_market_type: 16 #ICE NYH (RBOB) Gasoline/WTI Futures Crack
uds_market_type: 58 #ICE Futures UI Heating Oil / Brent
uds_market_type: 59 #ICE NYH (RBOB) Gasoline/Brent Futures Crack
uds_market_type: 66 #ICE NYH (RBOB) Gasoline/Heating Oil Spread
uds_market_type: 70 #ICE Heating Oil/LS Gasoil Futures Spread
uds_market_type: 71 #ICE LS Gasoil/Brent Futures Crack
uds_market_type: 72 #ICE NYH (RBOB) Gasoline/LS Gasoil Futures Spread
#onixs_log_mode: Debug
}
# channel {
# name: "juice"
# market_type: 26 #ICE Futures US Agricultures, FCOJ A
# }
ice_config_file: "ConnectivityConfiguration.APITest.xml"
#ice_config_file: "ConnectivityConfiguration.PerfTest.xml"
}
}
MDBootDelayWindow {
rule: "DeploymentType.type == 'dev'"
value {
delay_seconds: 0
}
}
MDBootDelayWindow {
value {
delay_seconds: 120
standard {
start: "16:30"
end: "16:40"
}
sunday {
start: "14:00"
end: "14:10"
}
}
}
DisplayFactorOverride {
value {
override {
symbol: "SOM"
exchange: "GLBX"
type: "SPREAD"
price_multiplier: 1
}
}
}
File diff suppressed because it is too large. Load diff
-21
View File
@@ -1,21 +0,0 @@
syntax='proto2';
package bts.config;
message SpartanTASCfg {
message TASSide {
required uint32 quantity = 2;
required int32 ticks_away = 3;
}
message TASTrigger {
required string security = 1;
required TASSide buy = 3;
required TASSide sell = 4;
}
required string user = 1;
required string account = 2;
repeated TASTrigger tas_trigger = 3;
}
-12
View File
@@ -32,18 +32,6 @@ std::string descriptor(api::Security const &sec) {
return "No descriptor for non glbx / ice exchange";
}
api::SecurityType security_type(api::Security const&sec) {
if (sec.has_future())
return api::SecurityType::SECURITYTYPE_FUTURE;
else if (sec.has_option())
return api::SecurityType::SECURITYTYPE_OPTION;
else if (sec.has_spread())
return api::SecurityType::SECURITYTYPE_SPREAD;
else if (sec.has_synthetic())
return api::SecurityType::SECURITYTYPE_SYNTHETIC;
else
return api::SecurityType::SECURITYTYPE_UNSET;
}
boost::gregorian::date smallest_leg(
::google::protobuf::RepeatedPtrField<::bts::api::ContractLeg> const &l) {
+7 -49
View File
@@ -26,7 +26,6 @@ SecurityKey security_key(api::Security const &);
std::string to_str(api::Security const &);
std::pair<bool, api::Security> from_str(std::string const &);
std::string descriptor(api::Security const &);
api::SecurityType security_type(api::Security const&);
inline std::string const &side_name(api::Side side) {
return api::Side_Name(side);
@@ -42,30 +41,6 @@ inline api::Side other_side(api::Side side) {
return side;
}
}
template <class V> class TwoSided {
public:
TwoSided() : buy(), sell() {}
TwoSided(V const &buy, V const &sell) : buy(buy), sell(sell) {}
V const &get(api::Side side) const {
if (side == api::SIDE_BUY)
return buy;
else
return sell;
}
void set(api::Side side, V const &v) {
if (side == api::SIDE_BUY)
buy = v;
else
sell = v;
}
private:
V buy;
V sell;
};
inline double market_epsilon() { return 1e-10; }
@@ -115,25 +90,6 @@ inline Price better_price(api::Side side, Price p1, Price p2) {
return is_equal_or_better(side, p1, p2) ? p1 : p2;
}
// Returns the worst possible price representable in the Price data type for the side in question
inline Price worst_price(api::Side side) {
switch (side) {
case api::SIDE_BUY:
return Price {std::numeric_limits<double>::min()};
case api::SIDE_SELL:
return Price {std::numeric_limits<double>::max()};
default:
bts_assert(false);
break;
}
bts_assert(false);
return Price(0);
}
inline Price best_price(api::Side side) {
return worst_price(other_side(side));
}
inline Price decode_exchange_price(api::Security const &sec, Price in) {
return Price(in.value() * sec.contract_spec().price_multiplier());
}
@@ -224,15 +180,17 @@ inline int price_diff_to_ticks(double price_1, double price_2,
}
// returns the difference (in ticks) bw and order and a market.
// if the order has crossed the market, returns -ve ticks
// (ie the buy order price > market_price or
// (ie the buy order price > market_price or
// sell_order_price < market_price)
inline int order_diff_market(double order_price, double market_price,
api::Side side, double tick_size) {
inline int order_diff_market(double order_price,
double market_price,
api::Side side,
double tick_size){
switch (side) {
case api::SIDE_BUY:
return price_diff_to_ticks(order_price, market_price, tick_size);
return price_diff_to_ticks(order_price,market_price,tick_size);
case api::SIDE_SELL:
return price_diff_to_ticks(market_price, order_price, tick_size);
return price_diff_to_ticks(market_price,order_price,tick_size);
default:
bts_assert(false);
break;
-6
View File
@@ -50,12 +50,6 @@ public:
std::vector<jetfix::FIXEncodingStream> fix;
jetfix::FIXEncodingStream& first_stream() {bts_assert (fix.size()); return fix[0];}
void close_all() {
for (auto &s : fix)
s.close();
}
};
}}
-2
View File
@@ -144,8 +144,6 @@ CoreGateway::~CoreGateway() {
me->timer_thread.join();
}
config::JetFIX::Connection const &CoreGateway::cfg() {return me->cfg;}
void CoreGateway::send(OutFIXPtr const &fix, trace::CorID trace) {
me->event_queue.push(EventData(&CoreGateway::sync_send, trace, fix));
}
-2
View File
@@ -30,8 +30,6 @@ public:
trace::PerfLog &);
~CoreGateway();
config::JetFIX::Connection const &cfg();
void start ();
void stop ();
void send (OutFIXPtr const &msgs, trace::CorID trace);
+1 -1
View File
@@ -53,7 +53,7 @@ public:
void stop () {_core.stop ();}
void send (OutFIXPtr const &msgs,trace::CorID trace ) {_core.send (msgs,trace);}
void dispatch_events () {_core.dispatch_events ();}
config::JetFIX::Connection const&cfg () {return _core.cfg();}
std::function<void()> &on_ready () {return _on_ready;}
std::function<void()> &on_disconnect () {return _on_disconnect;}
+62 -51
View File
@@ -2,79 +2,85 @@
#include "lib/logging/logging.h"
#include "lib/os/os.h"
#include "lib/utils/bts_assert.h"
#include "lib/utils/datetime.h"
#include "lib/utils/file_utils.h"
#include "lib/utils/bts_assert.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <fmt/ostream.h>
#include <fstream>
#include <iostream>
#include <boost/filesystem/path.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/filesystem.hpp>
#ifndef WIN32
#include <syslog.h>
#endif
namespace bts {
namespace log {
struct InitSysLog {
InitSysLog() {
#ifndef WIN32
openlog("spark", 0, LOG_USER);
openlog("spark",0,LOG_USER);
#endif
}
} init;
} init;
auto formatter(LoggingConfig const &cfg) {
return [cfg](LogMsg const &m) {
auto formatter(LoggingConfig const&cfg) {
return [cfg] (LogMsg const&m) {
auto iso_date = datetime::iso_date_time_string(datetime::local_now());
iso_date[sizeof("YYYY-MM-DD") - 1] = ' ';
iso_date[sizeof("YYYY-MM-DD")-1] = ' ';
#ifdef _WIN32
return fmt::format(
"{}|{}|{:<8}|{:<5}|{:<3}|{:<4}|{:<35}|{}|{} ", iso_date, m.ts,
m.subsystem_name, m.level_name, m.tid,
// m.thread_name,
os::process_id(),
fmt::format("{}:{}",
boost::filesystem::path(m.file).filename().string(),
m.line),
cfg.deployment_type, m.msg);
return fmt::format("{}|{}|{:<8}|{:<5}|{:<3}|{:<4}|{:<35}|{}|{} ",
iso_date,
m.ts,
m.subsystem_name,
m.level_name,
m.tid,
//m.thread_name,
os::process_id(),
fmt::format("{}:{}",boost::filesystem::path(m.file).filename().string() , m.line),
cfg.deployment_type,
m.msg);
#else
return fmt::format(
"{}|{}|{:<8}|{:<5}|{:<3}|{:<16}|{:<4}|{:<35}|{}|{} ", iso_date, m.ts,
m.subsystem_name, m.level_name, m.tid, m.thread_name,
os::process_id(),
fmt::format("{}:{}",
boost::filesystem::path(m.file).filename().string(),
m.line),
cfg.deployment_type, m.msg);
return fmt::format("{}|{}|{:<8}|{:<5}|{:<3}|{:<16}|{:<4}|{:<35}|{}|{} ",
iso_date,
m.ts,
m.subsystem_name,
m.level_name,
m.tid,
m.thread_name,
os::process_id(),
fmt::format("{}:{}",boost::filesystem::path(m.file).filename().string() , m.line),
cfg.deployment_type,
m.msg);
#endif
};
}
Sink console_sink(LoggingConfig const &) {
return [](LogMsg const &m) {
std::cout << fmt::format("{:<8} | {}", m.subsystem_name, m.msg)
<< std::endl;
};
Sink console_sink(LoggingConfig const&cfg) {
auto f = formatter(cfg);
return [f] (LogMsg const &m) {std::cout << f(m) << std::endl;};
}
Sink syslog_sink(LoggingConfig const &cfg) {
Sink syslog_sink(LoggingConfig const&cfg) {
#ifdef WIN32
return null_sink();
#else
auto f = formatter(cfg);
return [f](LogMsg const &m) {
syslog(LOG_INFO | LOG_USER, "%s", f(m).c_str());
};
return [f] (LogMsg const &m) {syslog (LOG_INFO | LOG_USER,"%s",f(m).c_str ());};
#endif
}
std::ifstream::pos_type filesize(std::string const &filename) {
if (!boost::filesystem::exists(filename))
std::ifstream::pos_type filesize(std::string const&filename)
{
if(!boost::filesystem::exists(filename))
return 0;
else {
std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary);
@@ -82,21 +88,24 @@ std::ifstream::pos_type filesize(std::string const &filename) {
}
}
Sink file_sink(LoggingConfig const &cfg) {
static std::ofstream stream;
static uint64_t bytes_written = 0;
const auto max_sz = 120 * 1024 * 1024;
auto f = formatter(cfg);
Sink file_sink(LoggingConfig const&cfg) {
static std::ofstream stream;
static uint64_t bytes_written = 0;
const auto max_sz = 120 * 1024 * 1024;
auto f= formatter(cfg);
auto path = log_path();
path /= "log";
auto parent = path.parent_path();
if (!boost::filesystem::is_directory(parent))
if (!boost::filesystem::is_directory(parent))
bts_assert(boost::filesystem::create_directories(parent));
if (boost::filesystem::exists(path)) {
if(boost::filesystem::exists(path)) {
auto sz = boost::filesystem::file_size(path);
if (sz > max_sz) {
auto backup = boost::filesystem::path(path.string() + ".old");
@@ -104,9 +113,10 @@ Sink file_sink(LoggingConfig const &cfg) {
}
}
stream = std::ofstream(path.string(), std::ofstream::app);
stream = std::ofstream(path.string(),std::ofstream::app);
return [=] (LogMsg const &m) {
return [=](LogMsg const &m) {
auto msg = f(m);
bytes_written += msg.size();
if (bytes_written >= max_sz) {
@@ -114,15 +124,16 @@ Sink file_sink(LoggingConfig const &cfg) {
stream.close();
auto backup = boost::filesystem::path(path.string() + ".old");
boost::filesystem::rename(path, backup);
stream = std::ofstream(path.string(), std::ofstream::app);
stream = std::ofstream(path.string(),std::ofstream::app);
}
stream << f(m) << std::endl;
};
}
Sink null_sink() {
return [](const LogMsg &) {};
return [](const LogMsg&) {};
}
}}
} // namespace log
} // namespace bts
+1 -2
View File
@@ -120,8 +120,7 @@ void configure_logging(bts::config::Logging const&cfg, bts::config::ThreadGroupC
{log::Plugin,"Plugin"},
{log::Sdk,"Sdk"},
{log::Http,"Http"},
{log::Spartan,"Spartan"},
{log::iLink3,"ilink3"},
{log::iLink3,"iLink3"},
};
real_cfg.sinks["console"] =
+2 -3
View File
@@ -45,9 +45,8 @@ constexpr log::Subsystem Latency {Testing.ordinal+1 };
constexpr log::Subsystem DataFlow {Latency.ordinal+1 };
constexpr log::Subsystem Plugin {DataFlow.ordinal+1 };
constexpr log::Subsystem Sdk {Plugin.ordinal+1 };
constexpr log::Subsystem Http {Sdk.ordinal+1 };
constexpr log::Subsystem Spartan {Http.ordinal+1 };
constexpr log::Subsystem iLink3 {Spartan.ordinal+1 };
constexpr log::Subsystem Http {Sdk.ordinal+1 };
constexpr log::Subsystem iLink3 {Http.ordinal+1 };
struct LoggerHandle {
LoggerHandle(LoggerHandle const&) = delete;
+2 -2
View File
@@ -60,10 +60,10 @@ class IntPrice {
return delta.mantissa() < 0;
}
}
bool operator <=(const IntPrice& other) const {
bool operator <=(const IntPrice& other) {
return *this == other || *this < other;
}
bool operator >=(const IntPrice& other) const {
bool operator >=(const IntPrice& other) {
return !(*this < other);
}
IntPrice operator - (const IntPrice& o) const {
+2 -10
View File
@@ -75,7 +75,7 @@ void apply_compatibilit_mutations(Security& security) {
}
size_t load_securities(
std::function<bool(const UserSymbol &symbo)> const&sym_filter,
const std::set<UserSymbol>& symbols,
const std::function<void(const api::Security&)>& callback) {
size_t count = 0;
@@ -92,7 +92,7 @@ size_t load_securities(
api::Venue venue = (api::Venue)(int) select_stmt.getColumn("venue");
auto type = (api::SecurityType)(int) select_stmt.getColumn("type");
UserSymbol us(symbol, venue, type);
if (sym_filter(us)) {
if (symbols.find(us) != symbols.end()) {
auto blob = select_stmt.getColumn("security_blob");
if (security.ParseFromArray(blob, blob.getBytes())) {
apply_compatibilit_mutations(security);
@@ -109,14 +109,6 @@ size_t load_securities(
return count;
}
size_t load_securities(
const std::set<UserSymbol>& symbols,
const std::function<void(const api::Security&)>& callback) {
return load_securities([&symbols] (UserSymbol const&symbol) {
return symbols.find(symbol) != symbols.end();
},callback);
}
SecurityPtr find_security(SecurityKey key) {
try {
auto db = open_db();
-4
View File
@@ -28,10 +28,6 @@ size_t load_securities(
const std::set<UserSymbol>& symbols,
const std::function<void(const api::Security&)>& callback);
size_t load_securities(
std::function<bool(const UserSymbol &symbo)> const&sym_filter,
const std::function<void(const api::Security&)>& callback) ;
SecurityPtr find_security(SecurityKey);
Result insert_or_replace(const std::vector<SecurityPtr>&);
+1 -23
View File
@@ -13,7 +13,6 @@
#include <boost/filesystem.hpp>
#include <pugixml/pugixml.hpp>
#include <iostream>
#include <mutex>
@@ -23,27 +22,6 @@ using namespace bts::api;
namespace bts {
namespace md {
std::ostream& operator<<(std::ostream&out, md::CMEConnection const&c)
{
out << "feed_type: " << c.feed_type
<< " ip: " << c.ip
<< " port: " << c.port
<< " feed: " << c.feed;
return out;
}
std::ostream& operator<<(std::ostream&out, md::CMEChannel const &ch) {
out << "id: " << ch.id << "\n";
out << "symbols: \n";
for (auto s : ch.symbols)
out << "\t" << s.symbol() << ":" << api::SecurityType_Name(s.type()) << "\n" ;
out << "Connections:\n";
for (auto const &[st,c] : ch.connections)
out << "\t" << st << " -> {" << c << "}\n";
out << "\n";
return out;
}
string data_path() {
auto p = config::get<config::System>().data_path() + "cme_mdp3/";
#ifdef _WIN32
@@ -191,4 +169,4 @@ const vector<CMEChannel> parse_channels(const vector<UserSymbol>& symbols) {
}} //namespace
#endif
#endif
+1 -3
View File
@@ -6,6 +6,7 @@
#include <set>
#include <vector>
namespace bts {
namespace md {
@@ -22,9 +23,6 @@ struct CMEChannel {
std::map<std::string, CMEConnection> connections;
};
std::ostream& operator<<(std::ostream&out, md::CMEConnection const&c);
std::ostream& operator<<(std::ostream&out, md::CMEChannel const &ch);
void await_cme_config();
const std::vector<CMEChannel> get_configured_cme_channels();
const std::vector<CMEChannel> parse_channels(const std::vector<UserSymbol>& symbols);
+2
View File
@@ -1,3 +1,4 @@
#ifdef USE_ONIX
#ifndef _WIN32
#include "ICEUtils.h"
@@ -129,3 +130,4 @@ const std::vector<ICEChannel> get_configured_ice_channels() {
}}} //namespace
#endif
#endif
-14
View File
@@ -13,20 +13,6 @@ namespace md {
// when we write it out in MDP3main.cpp
const char * onixs_license[] = {
"<license version=\"1.0\">",
" <type>production</type>",
" <customer>",
" <name>Blue Trading Systems OF 9420-2</name>",
" </customer>",
" <period>",
" <since>2020-05-01</since>",
" <till>2021-05-12</till>",
" </period>",
" <products>",
" <product id=\"4\" name=\"CME Market Data Handler for C++\" />",
" <product id=\"7\" name=\"ICE iMpact Multicast Price Feed Handler for C++\" />",
" <product id=\"67\" name=\"Eurex Market and Reference Data Interfaces (EMDI, RDI) Handler for C++\" />",
" </products>",
" <checksum>1C9210495AA3C9C884B7A37A4C7AD8F9</checksum>",
"</license>"
};
@@ -243,19 +243,19 @@ void GLBXiLink3ExecutionGateway::send_msgs(std::vector<OrderMsg> const &msgs,
auto create_ptr = std::get_if<CreateOrderMsg>(&m);
if (create_ptr) {
me->gw->send_order(*create_ptr);
break;
continue;
}
// CancelReplace
auto cancel_replace_ptr = std::get_if<CancelReplaceOrderMsg>(&m);
if (cancel_replace_ptr) {
me->gw->send_cancel_replace(*cancel_replace_ptr);
break;
continue;
}
// Cancel
auto cancel_ptr = std::get_if<CancelOrderMsg>(&m);
if (cancel_ptr) {
me->gw->send_cancel(*cancel_ptr);
break;
continue;
}
}
me->gw->flush();
+236 -240
View File
@@ -1,5 +1,4 @@
#include "ICEExecutionGateway.h"
#include "lib/api/services/AdminService.pb.h"
#include "lib/jetfix/codec/MessageDefinitions.h"
#include "lib/jetfix/codec/i32_toa.h"
#include "lib/jetfix/common/OutFIX.h"
@@ -7,18 +6,19 @@
#include "lib/logging/logging.h"
#include "lib/orderman/events/CancelRejectEvent.h"
#include "lib/orderman/events/GatewayStatusChangeEvent.h"
#include "lib/orderman/events/NewAdminDataEvent.h"
#include "lib/orderman/events/NewExecutionReportEvent.h"
#include "lib/orderman/events/NewSecuritiesEvent.h"
#include "lib/orderman/orderman_utils/fix_order_codec.h"
#include "lib/api/services/AdminService.pb.h"
#include "lib/orderman/events/NewAdminDataEvent.h"
#include "lib/tracing/bts_trace.h"
#include "lib/utils/Dispatcher.h"
#include "lib/utils/TimeStamp.h"
#include "lib/utils/bts_chrono.h"
#include "lib/utils/helper_macros.h"
#include "lib/utils/Dispatcher.h"
#include "lib/utils/bts_chrono.h"
#include <atomic>
#include <boost/pool/object_pool.hpp>
#include <atomic>
#include <set>
namespace bts {
@@ -26,19 +26,20 @@ namespace orderman {
using namespace jetfix;
using JFGw =
JetFIXGateway<fix::ICEExecutionReportMsg, fix::BusinessMessageRejectMsg,
fix::RejectMsg, fix::ICECancelRejectMsg,
fix::ICETraderLoginResponseMsg,
fix::ICETraderLogoutResponseMsg>;
using JFGw = JetFIXGateway<fix::ICEExecutionReportMsg, fix::BusinessMessageRejectMsg, fix::RejectMsg,
fix::ICECancelRejectMsg, fix::ICETraderLoginResponseMsg, fix::ICETraderLogoutResponseMsg>;
struct ICEExecutionGateway::PImpl {
struct ICEExecutionGateway::PImpl
{
PImpl(const config::JetFIX::Connection &cfg, trace::PerfLog &l,
md::SecurityOracle o)
: gw(cfg, l), exe_report_pool(), state(State::WAITING_FOR_SECURITIES),
securities(), securities_by_exchange_id(), gw_name(cfg.name()),
cfg(cfg), perf_log(l), admin_data(), nusers(-1), connection_time(),
exec_id_to_memo(), sec_oracle(o) {}
cfg(cfg), perf_log(l), admin_data(), nusers(-1), connection_time(), exec_id_to_memo(),
sec_oracle(o)
{}
JFGw gw;
boost::object_pool<ExecutionReport> exe_report_pool;
@@ -54,285 +55,287 @@ struct ICEExecutionGateway::PImpl {
api::admin::AdminData admin_data;
std::atomic<int> nusers;
TimeStamp connection_time;
std::unordered_map<std::string, std::string>
exec_id_to_memo; // for the bullshit adjusts
std::unordered_map<std::string, std::string> exec_id_to_memo; //for the bullshit adjusts
md::SecurityOracle sec_oracle;
};
ICEExecutionGateway::ICEExecutionGateway(const config::JetFIX::Connection &cfg,
trace::PerfLog &log,
md::SecurityOracle o)
: IExecutionGateway(), me(new PImpl(cfg, log, o)) {
ICEExecutionGateway::ICEExecutionGateway(const config::JetFIX::Connection &cfg, trace::PerfLog &log, md::SecurityOracle o)
: IExecutionGateway(), me(new PImpl(cfg, log, o))
{
me->state = State::WAITING_FOR_ADMIN;
}
ICEExecutionGateway::~ICEExecutionGateway() {}
void ICEExecutionGateway::on_admin_data(
const mercury::Update<NewAdminDataEvent> &update) {
if (update.events) {
for (auto const &ev : *(update.events))
void ICEExecutionGateway::on_admin_data(const mercury::Update<NewAdminDataEvent>& update)
{
if (update.events)
{
for (auto const &ev : *(update.events))
me->admin_data.CopyFrom(*ev.admin_data);
if (me->state == State::WAITING_FOR_ADMIN) {
LOG(OrderMan, Warn, "Received admin data. Waiting for securities {}",
me->gw_name.value());
if (me->state == State::WAITING_FOR_ADMIN)
{
LOG(OrderMan, Warn, "Received admin data. Waiting for securities {}", me->gw_name.value());
me->state = State::WAITING_FOR_SECURITIES;
}
}
}
}
void ICEExecutionGateway::on_securities(
const mercury::Update<NewSecuritiesEvent> &update) {
if (update.events) {
for (auto const &ev : *(update.events)) {
void ICEExecutionGateway::on_securities(const mercury::Update<NewSecuritiesEvent> &update)
{
if (update.events)
{
for (auto const &ev : *(update.events))
{
auto sec_ptr = ev.security;
me->securities[sec_ptr->id()] = sec_ptr;
if (sec_ptr->has_ice())
me->securities_by_exchange_id[sec_ptr->ice().exchange_id()] =
sec_ptr;
if(sec_ptr->has_ice())
me->securities_by_exchange_id[sec_ptr->ice().exchange_id()] = sec_ptr;
}
if (me->state == State::WAITING_FOR_SECURITIES) {
LOG(OrderMan, Warn,
"Received first set of {} securities. Beginning wait 2s for "
"trader login {}",
update.events->size(), me->gw_name.value());
if (me->state == State::WAITING_FOR_SECURITIES)
{
LOG(OrderMan, Warn, "Received first set of {} securities. Beginning wait 2s for trader login {}",
update.events->size(), me->gw_name.value());
// got our security synopsis, ready to start the GW
me->state = State::READY_TO_START_GW;
// subscribe to gateway events
me->gw.on<fix::ICEExecutionReportMsg>() = [this](auto const &msg) {
me->gw.on<fix::ICEExecutionReportMsg>() = [this](auto const &msg)
{
this->on_exe_report(msg);
};
me->gw.on<fix::ICECancelRejectMsg>() = [this](auto const &msg) {
me->gw.on<fix::ICECancelRejectMsg>() = [this](auto const &msg)
{
this->on_cancel_reject(msg);
};
me->gw.on_ready() = [this]() {
me->gw.on_ready() = [this]()
{
this->on_connection_status_change(true);
};
me->gw.on_disconnect() = [this]() {
me->gw.on_disconnect() = [this]()
{
this->on_connection_status_change(false);
};
me->gw.on<fix::BusinessMessageRejectMsg>() = [this](auto const &m) {
me->gw.on<fix::BusinessMessageRejectMsg>() = [this](auto const &m)
{
this->on_business_reject(m);
};
me->gw.on<fix::RejectMsg>() = [this](auto const &m) {
me->gw.on<fix::RejectMsg>() = [this](auto const &m)
{
this->on_session_reject(m);
};
};
}
}
}
void ICEExecutionGateway::start() {
me->gw.start();
bts_assert_msg(me->state == State::READY_TO_START_GW,
"ICEExecutionGateway statemachine failure");
void ICEExecutionGateway::start()
{
me->gw.start();
bts_assert_msg(me->state == State::READY_TO_START_GW, "ICEExecutionGateway statemachine failure");
}
void ICEExecutionGateway::on_connection_status_change(bool is_connected) {
void ICEExecutionGateway::on_connection_status_change(bool is_connected)
{
LOG(OrderMan, Info, "Connection state of {} changed to {}",
me->gw_name.value(),
is_connected ? std::string("connected") : std::string("disconnected"));
if (is_connected && me->state == State::READY_TO_START_GW) {
me->gw_name.value(), is_connected ? std::string("connected") : std::string("disconnected"));
if(is_connected && me->state == State::READY_TO_START_GW)
{
me->state = State::TRADER_LOGIN_TIMEOUT;
me->connection_time = Timer::now();
}
if (me->state == State::READY) {
me->on_gw_status_change(is_connected);
if (!is_connected) // if we disconnect, set state so we log in again
}
if(me->state == State::READY)
{
me->on_gw_status_change(is_connected);
if(!is_connected) //if we disconnect, set state so we log in again
me->state = State::READY_TO_START_GW;
}
}
void ICEExecutionGateway::on_trader_login_timeout_expired() {
if (me->state == State::TRADER_LOGIN_TIMEOUT) {
LOG(OrderMan, Warn,
"Done waiting for login timeout, logging on traders {}",
me->gw_name.value());
void ICEExecutionGateway::on_trader_login_timeout_expired()
{
if (me->state == State::TRADER_LOGIN_TIMEOUT)
{
LOG(OrderMan, Warn, "Done waiting for login timeout, logging on traders {}", me->gw_name.value());
// got our security synopsis, ready to start the GW
me->state = State::LOGIN_TIMEOUT_COMPLETE;
me->gw.on<fix::ICETraderLoginResponseMsg>() =
[&](const fix::ICETraderLoginResponseMsg &lmsg) {
std::string u = lmsg.get<fix::UserName>();
std::string m;
if (lmsg.has<fix::Text>())
m = lmsg.get<fix::Text>();
LOG(OrderMan, Info,
"Successfully logging trader {} into ICE {} {}", u, m,
me->gw_name.value());
if (--me->nusers == 0)
this->on_login();
};
me->gw.on<fix::ICETraderLogoutResponseMsg>() =
[&](const fix::ICETraderLogoutResponseMsg &lmsg) {
std::string u = lmsg.get<fix::UserName>();
std::string m;
if (lmsg.has<fix::Text>())
m = lmsg.get<fix::Text>();
LOG(OrderMan, Error, "Error logging trader {} into ICE {} {}", u,
m, me->gw_name.value());
if (--me->nusers == 0)
this->on_login();
};
me->state = State::LOGIN_TIMEOUT_COMPLETE;
me->gw.on<fix::ICETraderLoginResponseMsg>() = [&](const fix::ICETraderLoginResponseMsg& lmsg)
{
std::string u = lmsg.get<fix::UserName>();
std::string m;
if(lmsg.has<fix::Text>())
m = lmsg.get<fix::Text>();
LOG(OrderMan, Info, "Successfully logging trader {} into ICE {} {}", u, m, me->gw_name.value());
if(--me->nusers == 0)
this->on_login();
};
me->gw.on<fix::ICETraderLogoutResponseMsg>() = [&](const fix::ICETraderLogoutResponseMsg& lmsg)
{
std::string u = lmsg.get<fix::UserName>();
std::string m;
if(lmsg.has<fix::Text>())
m = lmsg.get<fix::Text>();
LOG(OrderMan, Error, "Error logging trader {} into ICE {} {}", u, m, me->gw_name.value());
if(--me->nusers == 0)
this->on_login();
};
std::set<std::string> auth_traders;
for (const auto &u : me->admin_data.users()) {
if (u.has_user_data() && u.user_data().has_exchange_user_data() &&
u.user_data().exchange_user_data().has_ice_data()) {
if (!u.is_present())
for(const auto& u : me->admin_data.users())
{
if(u.has_user_data() && u.user_data().has_exchange_user_data() && u.user_data().exchange_user_data().has_ice_data())
{
if(!u.is_present())
continue;
if (!u.is_active())
if(!u.is_active())
continue;
const auto &ice = u.user_data().exchange_user_data().ice_data();
if (auth_traders.find(ice.authorized_trader()) ==
auth_traders.end()) {
if (ice.authorized_trader() == "")
const auto& ice = u.user_data().exchange_user_data().ice_data();
if(auth_traders.find(ice.authorized_trader()) == auth_traders.end())
{
if(ice.authorized_trader() == "")
continue;
if (ice.company_id() <= 0)
if(ice.company_id() <= 0)
continue;
if (me->nusers == -1)
if(me->nusers == -1)
me->nusers = 0;
me->nusers++;
auto result = std::make_shared<OutFIX>(me->cfg);
auto &stream = result->fix.back();
auto &buffer = stream.new_msg(MessageTypes::ICETraderLogin);
buffer.add<fix::CompanyID>(ice.company_id());
buffer.add<fix::UserName>(ice.authorized_trader());
buffer.add<fix::RawData>(ice.password());
if (ice.mifid_direct_electronic_access() >= 0)
buffer.add<fix::MifidDirectElectronicAccess>(
ice.mifid_direct_electronic_access());
if (ice.mifid_trading_capacity() >= 0)
buffer.add<fix::MifidTradingCapacity>(
ice.mifid_trading_capacity());
if (ice.mifid_liquidity_provision() >= 0)
buffer.add<fix::MifidLiquidityProvision>(
ice.mifid_liquidity_provision());
if (ice.mifid_commodity_deriv_indicator() >= 0)
buffer.add<fix::MifidCommodityDerivIndicator>(
ice.mifid_commodity_deriv_indicator());
if (ice.mifid_investment_decision() > 0)
buffer.add<fix::MifidInvestmentDecision>(
ice.mifid_investment_decision());
if (ice.mifid_execution_decision() > 0)
buffer.add<fix::MifidExecutionDecision>(
ice.mifid_execution_decision());
if (ice.mifid_client_id_code() > 0)
buffer.add<fix::MifidClientIDCode>(
ice.mifid_client_id_code());
if (ice.mifid_id() > 0)
buffer.add<fix::MifidId>(ice.mifid_id());
auto &buffer = stream.new_msg(MessageTypes::ICETraderLogin);
buffer.add<fix::CompanyID>(ice.company_id());
buffer.add<fix::UserName>(ice.authorized_trader());
buffer.add<fix::RawData>(ice.password());
if(ice.mifid_direct_electronic_access() >= 0)
buffer.add<fix::MifidDirectElectronicAccess>(ice.mifid_direct_electronic_access());
if(ice.mifid_trading_capacity() >= 0)
buffer.add<fix::MifidTradingCapacity>(ice.mifid_trading_capacity());
if(ice.mifid_liquidity_provision() >= 0)
buffer.add<fix::MifidLiquidityProvision>(ice.mifid_liquidity_provision());
if(ice.mifid_commodity_deriv_indicator() >= 0)
buffer.add<fix::MifidCommodityDerivIndicator>(ice.mifid_commodity_deriv_indicator());
if(ice.mifid_investment_decision() > 0)
buffer.add<fix::MifidInvestmentDecision>(ice.mifid_investment_decision());
if(ice.mifid_execution_decision() > 0)
buffer.add<fix::MifidExecutionDecision>(ice.mifid_execution_decision());
if(ice.mifid_client_id_code() > 0)
buffer.add<fix::MifidClientIDCode>(ice.mifid_client_id_code());
if(ice.mifid_id() > 0)
buffer.add<fix::MifidId>(ice.mifid_id());
stream.close();
trace::CorID trace;
trace::CorID trace;
send_fix(result, trace);
auth_traders.insert(ice.authorized_trader());
}
}
}
}
LOG(OrderMan, Warn, "{} traders identified as ICE traders {}",
auth_traders.size(), me->gw_name.value());
LOG(OrderMan, Warn, "{} traders identified as ICE traders {}", auth_traders.size(), me->gw_name.value());
}
}
void ICEExecutionGateway::on_login() {
if (me->state == State::LOGIN_TIMEOUT_COMPLETE) {
void ICEExecutionGateway::on_login()
{
if (me->state == State::LOGIN_TIMEOUT_COMPLETE)
{
LOG(OrderMan, Warn, "Successful login traders {}", me->gw_name.value());
me->state = State::READY;
me->on_gw_status_change(true);
}
me->state = State::READY;
me->on_gw_status_change(true);
}
}
OnExeReport &ICEExecutionGateway::on_exe_report() { return me->on_exe_report; }
OnGwStatusChange &ICEExecutionGateway::on_gw_status_change() {
OnGwStatusChange &ICEExecutionGateway::on_gw_status_change()
{
return me->on_gw_status_change;
}
OnCancelReject &ICEExecutionGateway::on_cancel_reject() {
OnCancelReject &ICEExecutionGateway::on_cancel_reject()
{
return me->on_cancel_reject;
}
bool ICEExecutionGateway::process_memo(
const jetfix::fix::ICEExecutionReportMsg &msg, OrderKey *ok,
SecurityKey *sk) {
if (msg.has<fix::Memo>()) {
decode_memo(msg.get<fix::Memo>(), ok, sk);
bool ICEExecutionGateway::process_memo(const jetfix::fix::ICEExecutionReportMsg &msg, OrderKey* ok, SecurityKey* sk)
{
if(msg.has<fix::Memo>())
{
decode_memo(msg.get<fix::Memo>(), ok, sk);
return true;
} else {
if (msg.get<fix::ExecType>() == api::orderman::EXEC_TYPE_TRADE_CORRECT &&
msg.has<fix::ExecRefID>()) {
}
else
{
if (msg.get<fix::ExecType>() == api::orderman::EXEC_TYPE_TRADE_CORRECT && msg.has<fix::ExecRefID>())
{
std::string ref_exec_id = msg.get<fix::ExecRefID>();
auto found = me->exec_id_to_memo.find(ref_exec_id);
if (found == me->exec_id_to_memo.end()) {
if(found == me->exec_id_to_memo.end())
{
auto new_price = Price(0);
if (msg.has<fix::LastPx>())
if(msg.has<fix::LastPx>())
new_price = Price(msg.get<fix::LastPx>());
LOG(OrderMan, Error,
"Received unsupported trade correction msg. This correction "
"will not be forwarded. The trader should be alerted. "
"Partial original fill id: {}. New price: {}",
ref_exec_id, new_price.value());
"Received unsupported trade correction msg. This correction will not be forwarded. The trader should be alerted. "
"Partial original fill id: {}. New price: {}", ref_exec_id, new_price.value());
return false;
} else {
}
else
{
decode_memo(found->second, ok, sk);
return true;
}
}
}
}
return false;
return false;
}
void ICEExecutionGateway::on_exe_report(
const jetfix::fix::ICEExecutionReportMsg &msg) {
void ICEExecutionGateway::on_exe_report(const jetfix::fix::ICEExecutionReportMsg &msg)
{
OrderKey ok;
SecurityKey sk;
if (!process_memo(msg, &ok, &sk)) {
if(!process_memo(msg, &ok, &sk))
{
std::string execid = "";
if (msg.has<fix::ExecID>())
if(msg.has<fix::ExecID>())
execid = msg.get<fix::ExecID>();
LOG(OrderMan, Error,
"Received execution report with no memo execid: {}. Will not be able "
"to process this report. This is likely a bug that could lead "
"to lost fills. Please investigate.",
execid);
return;
"Received execution report with no memo execid: {}. Will not be able to process this report. This is likely a bug that could lead "
"to lost fills. Please investigate.", execid);
return;
}
auto scoped_log =
trace::log_scope(me->perf_log, msg.trace(),
"ICEExecutionGateway::on_exe_report", ok.value());
auto scoped_log = trace::log_scope(me->perf_log, msg.trace(), "ICEExecutionGateway::on_exe_report", ok.value());
LOG(Latency, Info, "Started handling of execution report for order {}",
ok.value());
LOG(Latency, Info, "Started handling of execution report for order {}", ok.value());
auto &sec = me->securities[sk.value()];
if (!sec) {
if (!sec)
{
sec = me->sec_oracle.get_security(SecurityKey(sk.value()));
}
}
if (!sec)
LOG(OrderMan, Error,
"Received execution report for an unknown security {}. Will not be "
"able to process this report. This is likely a bug that could lead "
"Received execution report for an unknown security {}. Will not be able to process this report. This is likely a bug that could lead "
"to lost fills. Please investigate.",
sk.value());
else {
if (sec->has_ice())
else
{
if(sec->has_ice())
me->securities_by_exchange_id[sec->ice().exchange_id()] = sec;
api::Security const *leg_security = nullptr;
if (msg.has<fix::MultiLegReportingType>() &&
msg.get<fix::MultiLegReportingType>() == 2) {
auto it =
me->securities_by_exchange_id.find(msg.get<fix::Int_Symbol>());
if (it == me->securities_by_exchange_id.end()) {
if (msg.has<fix::MultiLegReportingType>() && msg.get<fix::MultiLegReportingType>() == 2)
{
auto it = me->securities_by_exchange_id.find(msg.get<fix::Int_Symbol>());
if (it == me->securities_by_exchange_id.end())
{
LOG(OrderMan, Error,
"Received execution report for an unknown spread leg"
"security {}. Will not be able to process this report. "
@@ -343,22 +346,20 @@ void ICEExecutionGateway::on_exe_report(
return;
}
leg_security = it->second;
}
}
std::string text_msg;
if (msg.has<fix::Text>())
text_msg = msg.get<fix::Text>();
if (msg.has<fix::OrdRejReason>())
text_msg += " Rejected OrdRejReason: " +
std::to_string(msg.get<fix::OrdRejReason>());
text_msg += " Rejected OrdRejReason: " + std::to_string(msg.get<fix::OrdRejReason>());
if (msg.has<fix::DeleteReason>())
text_msg += " Cancelled DeleteReason: " +
std::to_string(msg.get<fix::DeleteReason>());
text_msg += " Cancelled DeleteReason: " + std::to_string(msg.get<fix::DeleteReason>());
// allocate from our pool
auto data = me->exe_report_pool.construct();
if (msg.has<fix::Memo>())
if(msg.has<fix::Memo>())
data->memo = msg.get<fix::Memo>();
data->exec_type = api::orderman::ExecType(msg.get<fix::ExecType>());
data->msg_seq_num = msg.get<fix::MsgSeqNum>();
@@ -369,52 +370,47 @@ void ICEExecutionGateway::on_exe_report(
if (msg.has<fix::TargetSubID>())
str_to(msg.get<fix::TargetSubID>(), &data->operator_id);
if (msg.has<fix::CompanyID>())
data->ice_company_id = msg.get<fix::CompanyID>();
data->ice_company_id = msg.get<fix::CompanyID>();
data->order_key = ok;
data->security = sec;
data->leg_security = leg_security;
data->side = api::Side(msg.get<fix::Side>());
if (msg.has<fix::TimeInForce>())
data->time_in_force =
api::orderman::TimeInForce(msg.get<fix::TimeInForce>());
data->time_in_force = api::orderman::TimeInForce(msg.get<fix::TimeInForce>());
else
data->time_in_force = api::orderman::TIME_IN_FORCE_UNDEFINED;
if (msg.has<fix::OrdType>())
data->order_type =
api::orderman::NativeOrderType(msg.get<fix::OrdType>());
data->order_type = api::orderman::NativeOrderType(msg.get<fix::OrdType>());
else
data->order_type = api::orderman::NATIVE_ORDER_TYPE_UNDEFINED;
data->order_status =
api::orderman::NativeOrderStatus(msg.get<fix::OrdStatus>());
data->order_status = api::orderman::NativeOrderStatus(msg.get<fix::OrdStatus>());
data->manual_order_indicator = api::orderman::MANUAL_ORDER_INDICATOR_NO;
std::string oid_string = get_ice_order_id_string(msg);
str_to(oid_string,
& std::get<ExchangeOrderID>(
data->exchange_order_id));
data->ice_cl_ord_id = 0;
if (msg.has<fix::Int_ClOrdID>())
if(msg.has<fix::Int_ClOrdID>())
data->ice_cl_ord_id = msg.get<fix::Int_ClOrdID>();
if (msg.has<fix::Price>())
data->price = securities::decode_exchange_price(
*sec, Price(msg.get<fix::Price>()));
data->price = securities::decode_exchange_price(*sec, Price(msg.get<fix::Price>()));
else
data->price = Price(os::nan());
if (msg.has<fix::StopPx>())
data->stop_price = securities::decode_exchange_price(
*sec, Price(msg.get<fix::StopPx>()));
data->stop_price = securities::decode_exchange_price(*sec, Price(msg.get<fix::StopPx>()));
else
data->stop_price = Price(os::nan());
if (msg.has<fix::MaxShow>())
data->max_show = Quantity(msg.get<fix::MaxShow>());
else
data->max_show = Quantity(0);
data->max_show = Quantity(0);
if (msg.has<fix::OrderQty>())
data->quantity = Quantity(msg.get<fix::OrderQty>());
@@ -422,27 +418,27 @@ void ICEExecutionGateway::on_exe_report(
data->quantity = Quantity(0);
data->filled_quantity = Quantity(msg.get<fix::CumQty>());
data->last_shares = msg.has<fix::LastShares>()
? Quantity(msg.get<fix::LastShares>())
: Quantity(0);
auto last_px_sec = data->leg_security ? data->leg_security : sec;
data->last_price = msg.has<fix::LastPx>()
? securities::decode_exchange_price(
*last_px_sec, Price(msg.get<fix::LastPx>()))
? securities::decode_exchange_price(*last_px_sec, Price(msg.get<fix::LastPx>()))
: Price(0);
data->avg_price = msg.has<fix::AvgPx>()
? securities::decode_exchange_price(
*last_px_sec, Price(msg.get<fix::AvgPx>()))
? securities::decode_exchange_price(*last_px_sec, Price(msg.get<fix::AvgPx>()))
: Price(0);
if (msg.has<fix::ExecID>()) {
if (msg.has<fix::ExecID>())
{
auto execid = msg.get<fix::ExecID>();
str_to(execid, &data->exchange_fill_id);
if (msg.has<fix::Memo>())
if(msg.has<fix::Memo>())
me->exec_id_to_memo[execid] = msg.get<fix::Memo>();
}
if (msg.has<fix::TransactTimeStr>()) {
if (msg.has<fix::TransactTimeStr>())
{
std::string stamp = msg.get<fix::TransactTimeStr>();
stamp.resize(sizeof(orderman::ExchangeTimeStampStr));
orderman::ExchangeTimeStampStr t;
@@ -456,8 +452,8 @@ void ICEExecutionGateway::on_exe_report(
}
}
void ICEExecutionGateway::on_cancel_reject(
const jetfix::fix::ICECancelRejectMsg &msg) {
void ICEExecutionGateway::on_cancel_reject(const jetfix::fix::ICECancelRejectMsg &msg)
{
OrderKey ok(msg.get<fix::Int_ClOrdID>());
std::string reject_msg;
@@ -469,36 +465,36 @@ void ICEExecutionGateway::on_cancel_reject(
me->on_cancel_reject(CancelReject {ok, CancelRejectReason::Other,reject_msg});
}
void ICEExecutionGateway::on_business_reject(
const jetfix::fix::BusinessMessageRejectMsg &m) {
void ICEExecutionGateway::on_business_reject(const jetfix::fix::BusinessMessageRejectMsg& m)
{
LOG(OrderMan, Error,
"Unexpected business reject in {} gateway . Reason: {}. This should be "
"investigated",
"Unexpected business reject in {} gateway . Reason: {}. This should be investigated",
me->gw_name.value(),
m.has<fix::Text>() ? m.get<fix::Text>() : std::string("Unknown"));
}
void ICEExecutionGateway::on_session_reject(const jetfix::fix::RejectMsg &m) {
void ICEExecutionGateway::on_session_reject(const jetfix::fix::RejectMsg& m)
{
LOG(OrderMan, Error,
"Unexpected reject message in {} gateway . Reason: {}. This should be "
"investigated",
"Unexpected reject message in {} gateway . Reason: {}. This should be investigated",
me->gw_name.value(),
m.has<fix::Text>() ? m.get<fix::Text>() : std::string("Unknown"));
}
void ICEExecutionGateway::dispatch_incoming_fix_messages() {
me->gw.dispatch_events();
if (me->state == State::TRADER_LOGIN_TIMEOUT &&
ms_diff(Timer::now(), me->connection_time) >= 2000) {
void ICEExecutionGateway::dispatch_incoming_fix_messages()
{
me->gw.dispatch_events();
if(me->state == State::TRADER_LOGIN_TIMEOUT && ms_diff(Timer::now(), me->connection_time) >= 2000)
{
on_trader_login_timeout_expired();
}
}
void ICEExecutionGateway::send_fix(const jetfix::OutFIXPtr &fix,
trace::CorID trace) {
auto scoped_log =
trace::log_scope(me->perf_log, trace, "ICEExecutionGateway::send_fix");
me->gw.send(fix, trace);
void ICEExecutionGateway::send_fix(const jetfix::OutFIXPtr& fix, trace::CorID trace)
{
auto scoped_log = trace::log_scope(me->perf_log,trace,"ICEExecutionGateway::send_fix");
me->gw.send(fix,trace);
me->gw.dispatch_events();
}
+1 -6
View File
@@ -176,12 +176,7 @@ uint64_t IL3GW::send_party_details(const api::orderman::RoutingRecord &route) {
msg.selfMatchPreventionID(
PartyDetailsDefinitionRequest518::selfMatchPreventionIDNullValue());
} else {
// CME needs the SMP_ID to be 12 characters or less
// after they to_string() the uint64
bts_assert_d(route.smp_id().size() == 8);
const uint64_t *psmp_id =
reinterpret_cast<const uint64_t *>(&route.smp_id());
uint64_t smp_id = (*psmp_id) % (2UL << 39);
auto smp_id = std::atoi(route.smp_id().c_str());
msg.selfMatchPreventionID(smp_id);
}
msg.cmtaGiveupCD(CmtaGiveUpCD::NULL_VALUE);
+1 -1
View File
@@ -25,7 +25,7 @@ iLinkBinary::SideReq::Value map_side(api::Side side);
api::Side map_side(iLinkBinary::SideReq::Value side);
inline int64_t to_price9(Price p) {
return p.value() * 1E9;
return std::round(p.value() * 1E9);
}
iLinkBinary::OrderTypeReq::Value map_order_type(api::orderman::NativeOrderType ot);
+1 -1
View File
@@ -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();
}
};
@@ -53,7 +53,5 @@ class OrderFactory : public IOrderFactory {
std::unique_ptr<PImpl> me;
};
OrderKey gen_order_id();
} // namespace orderman
} // namespace bts
@@ -1,376 +0,0 @@
#include "DormanAlgo.h"
#include "lib/api/services/OrderService.pb.h"
#include "lib/domain_model/Security.h"
#include "lib/logging/logging.h"
#include "lib/orderman/order_factory/IOrderFactory.h"
#include "lib/orderman/orderman_utils/Book.h"
#include "lib/orderman/orders/algo/IAlgoServices.h"
#include "lib/utils/PBUtils.h"
#include "lib/orderman/orderman_utils/orderman_utils.h"
#include "lib/orderman/orders/algo/utils/Accumulator.h"
namespace bts {
namespace orderman {
namespace dorman {
using namespace api::orderman;
struct FutureQty {
Quantity size;
TimeStamp when;
};
struct DormanAlgo::Impl {
IAlgoServices *algo = nullptr;
AlgoParams params;
api::Side side;
Quantity exposed_qty = {};
std::optional<FutureQty> next_size;
OrderDefinition splitter_definition;
OrderKey child_id;
ChildState child_state;
uint32_t fills ={};
std::vector<OrderKey> profit_orders;
std::optional<Accumulator> trade_accumulator;
std::optional<TimeStamp> pause_until;
};
DormanAlgo::DormanAlgo() :
me(new Impl())
{ }
DormanAlgo::~DormanAlgo() { }
OrderOpResult DormanAlgo::do_before_launch(IBeforeLaunchAlgoServices& ibl) {
const auto& def = ibl.definition();
// Validation
bts_assert(def.has_custom_def());
bts_assert(def.custom_def().has_dynamic());
auto params = to_dorman_params(def.custom_def().dynamic());
if (auto error = std::get_if<OrderOpResult>(&params)) {
return *error;
}
me->params = std::get<AlgoParams>(params);
me->side = def.side();
if (me->side != api::Side::SIDE_BUY && me->side != api::Side::SIDE_SELL) {
return OrderOpResult { ORDER_ERROR_INVALID_ORDER_DEFINITON, "Invalid side" };
}
if (me->params.trade_accumulation) {
auto& t = me->params.trade_accumulation.value();
me->trade_accumulator = {Accumulator {t.contracts, t.seconds, ibl.get_time()}};
}
CustomOrderDefinition default_order;
default_order.mutable_limit();
auto child_def =
get_if<CustomOrderDefinition>(def.custom_def().dynamic().order_params(), "Child")
.value_or(default_order);
update_child_template(ibl, child_def);
if (ibl.is_attaching()) {
return OrderOpResult{ORDER_ERROR_OP_NOT_SUPPORTED,
"This algo does not support attach."};
}
return {/*ok*/};
}
void DormanAlgo::do_launch(IAlgoServices& algo) {
me->algo = &algo;
auto skey = SecurityKey(algo.security().id());
algo.subscribe_book(skey);
algo.subscribe_timer();
if (me->trade_accumulator) {
algo.subscribe_ticker(skey);
}
}
void DormanAlgo::do_launch_attached(IAlgoServices&, OrderKey, ChildState) {
bts_assert(false);
}
void DormanAlgo::do_update(const api::orderman::Update& update) {
LOG(OrderMan, Diag, "Dorman order {} receiving update: {}",
algo().order_key().value(), utils::pb::to_string(update));
if (update.has_custom()) {
if (!update.custom().has_dynamic()) {
algo().cancel("Update cannot change order type");
return;
}
auto params = to_dorman_params(update.custom().dynamic());
if (auto error = std::get_if<OrderOpResult>(&params)) {
algo().cancel(error->error_msg);
}
me->params = std::get<AlgoParams>(params);
auto skey = SecurityKey(algo().security().id());
if (me->params.trade_accumulation && !me->trade_accumulator) {
algo().subscribe_ticker(skey);
auto& t = me->params.trade_accumulation.value();
me->trade_accumulator = {Accumulator {t.contracts, t.seconds, algo().get_time()}};
}
else if (!me->params.trade_accumulation && me->trade_accumulator) {
algo().unsubscribe_ticker(skey);
me->trade_accumulator = std::nullopt;
}
else if (me->params.trade_accumulation &&
me->trade_accumulator &&
(me->trade_accumulator.value().threshold != me->params.trade_accumulation.value().contracts ||
me->trade_accumulator.value().bucket_interval != std::chrono::seconds(me->params.trade_accumulation.value().seconds))
) {
// accumulator params have changed
auto& t = me->params.trade_accumulation.value();
me->trade_accumulator = {Accumulator {t.contracts, t.seconds, algo().get_time()}};
}
// Check for child
auto child = get_if<CustomOrderDefinition>(update.custom().dynamic().order_params(), "Child");
if (child) {
update_child_template(algo(), child.value());
}
}
if (me->fills >= update.quantity()) {
complete();
}
else {
// In case of price/qty change always update the child
// NOTE: it might be useful to cache the available market data size
// and update based on that if the update contains a size table change
update_child(me->exposed_qty);
}
}
void DormanAlgo::on_child_change(OrderKey key, const ChildState& state) {
if (key != me->child_id) return;
if (state.status == ChildStatus::CANCELED && !is_paused()) {
algo().cancel("Unexpected child cancel");
return;
}
auto delta = state.total_fills.value() - me->child_state.total_fills.value();
if (delta != 0) {
me->fills += delta;
algo().update_fill_state(Quantity {me->fills}, state.last_price);
send_profit_order(state.last_price, Quantity {delta});
}
me->child_state = state;
if (me->params.scratch &&
me->fills >= me->params.scratch.value().max_overfill) {
do_scratch();
}
if (me->fills >= algo().quantity().value() || state.status == ChildStatus::COMPLETED) {
complete();
}
}
void DormanAlgo::on_book(SecurityKey key, const Book& book) {
if (key.value() != me->algo->security().id()) { return; }
auto price = me->algo->price();
auto tick = me->algo->security().contract_spec().low_tick();
// Determine available size on the market
auto& side = book.side(me->side);
uint32_t available = 0;
for (const auto& level : side) {
if (securities::test_price_equality(level.price(), price.value(), tick)) {
available += level.size();
break;
}
}
// Check the step_table
auto target = Quantity {0};
if (available > 0) {
for (const auto& entry : me->params.steps.step_table) {
if (std::get<0>(entry) > available) {
break;
}
else {
target = Quantity { std::get<1>(entry) };
}
}
}
target = Quantity { std::min(target.value(), me->params.steps.maximum) };
// First on_book
if (!child_active()) {
update_child(target);
}
// See if we need to adjust
else {
if (target == me->exposed_qty) {
me->next_size = std::nullopt;
}
// If target < size reduce immediately
else if (target < me->exposed_qty) {
update_child(target);
me->next_size = std::nullopt;
}
// if target > size schedule increase
else if (target > me->exposed_qty) {
if (me->next_size) {
// already planning to increase, update the target
me->next_size.value().size = target;
}
else {
// no existing scheduled increase, create one now
me->next_size = { FutureQty { target, me->algo->get_time() + std::chrono::seconds(me->params.steps.trail_seconds) } };
}
}
}
}
void DormanAlgo::on_timer() {
// Check for pending size changes
auto now = algo().get_time();
if (me->pause_until &&
now >= me->pause_until.value()) {
resume();
}
if (me->next_size &&
now >= me->next_size.value().when) {
auto size = me->next_size.value().size;
update_child(size);
me->next_size = std::nullopt;
}
}
void DormanAlgo::on_ticker(SecurityKey, const TradeVector& vec) {
if (me->trade_accumulator) {
size_t contracts = 0;
for (const auto& t : vec) {
contracts += t.quantity.value();
}
auto& acc = me->trade_accumulator.value();
acc.push_back(algo().get_time(), contracts);
if (acc.exceeded()) {
auto delay = std::chrono::seconds(me->params.trade_accumulation.value().sleep_seconds);
pause_for(delay);
}
}
}
IAlgoOrder::OnCancelResponse DormanAlgo::on_cancel() {
// detach any remaining profit orders so they keep running
for(const auto& key : me->profit_orders) {
algo().detach_child(key);
}
return OnCancelResponse::HONOR;
}
IAlgoServices& DormanAlgo::algo() const { return *me->algo; }
//
// private
void DormanAlgo::update_child(Quantity exposed) {
auto& splitter = *me->splitter_definition.mutable_custom_def()->mutable_splitter();
splitter.set_max_order_qty(me->params.clip_limit);
me->exposed_qty = exposed;
splitter.set_exposed_qty(is_paused() ? 0 : exposed.value());
if (!child_active()) {
// launch child
me->child_id = algo().launch_child(me->splitter_definition, algo().price(), algo().quantity());
}
else {
Update update;
update.set_price(algo().price().value());
update.set_quantity(algo().quantity().value());
*update.mutable_custom()->mutable_splitter() = splitter;
algo().update_child(me->child_id, update);
}
}
void DormanAlgo::update_child_template(IBeforeLaunchAlgoServices& ibl, const CustomOrderDefinition& child) {
auto child_def = ibl.definition();
// Insert a spliter between this and the configured child definition.
api::orderman::SplitterOrderDefinition& splitter_def = *child_def.mutable_custom_def()->mutable_splitter();
*splitter_def.mutable_child() = child;
me->splitter_definition = child_def;
}
Quantity DormanAlgo::exposed_qty() const { return me->exposed_qty; }
bool DormanAlgo::child_active() const { return me->child_id.value() != 0; }
void DormanAlgo::do_scratch() {
// When the # of fills exceeds the max overfill quantity
// We enter fills opposite fills at the fill price and terminate
// Use a splitter to bypass clip limit if necessary
OrderDefinition def = me->splitter_definition;
def.set_side(securities::other_side(me->side));
def.mutable_custom_def()->mutable_splitter()->set_exposed_qty(me->fills);
auto price = me->child_state.last_price;
auto scratch_id = algo().launch_child(def, price, Quantity { me->fills }, false);
algo().detach_child(scratch_id);
complete();
}
void DormanAlgo::send_profit_order(Price p, Quantity q) {
if (me->params.profit_orders) {
auto side = securities::other_side(me->side);
Price offset =
Price { algo().security().contract_spec().low_tick() * me->params.profit_orders.value().ticks_away };
auto price =
securities::worsen_price(side, p, offset);
OrderDefinition def = me->splitter_definition;
// BTS Simulator does not currently support GTC
// Note: This could be made a configurable order type in the algo parameters
def.set_time_in_force(TimeInForce::TIME_IN_FORCE_DAY);
def.set_side(side);
def.mutable_custom_def()->mutable_limit();
me->profit_orders.push_back(
algo().launch_child(def, price, q, false));
}
}
void DormanAlgo::complete() {
// Allow profit orders to keep running
if (me->params.profit_orders) {
for(const auto& key : me->profit_orders) {
algo().detach_child(key);
}
}
algo().complete();
}
void DormanAlgo::pause_for(Duration d) {
if (me->params.trade_accumulation) {
if (is_paused()) {
me->pause_until = std::max(me->pause_until.value(), { algo().get_time() + d });
}
else {
me->pause_until = { algo().get_time() + d };
// When paused child update will always expose 0
update_child(me->exposed_qty);
}
}
}
bool DormanAlgo::is_paused() const {
return (bool)(me->pause_until);
}
void DormanAlgo::resume() {
if (is_paused()) {
me->pause_until = std::nullopt;
update_child(me->exposed_qty);
}
}
}}} //namespace
@@ -1,96 +0,0 @@
#pragma once
#include "lib/orderman/orders/algo/IAlgoOrder.h"
#include <memory>
#include <optional>
#include <variant>
#include <map>
namespace bts {
namespace orderman {
namespace dorman {
//
// Algo parameters
//
// This defines the market quantity vs the order quantity
struct StepParams {
std::vector<std::tuple<uint32_t, uint32_t>> step_table;
// This is the cap on the maximum quantity,
// even though the step table can allow for higher quantities (depending on the
// clip size this could be divided across multiple exchange orders)
uint32_t maximum;
// If the market increases don't follow until it has stayed high for trail_seconds;
uint32_t trail_seconds;
};
// If the number of accumulated fills (net of profit orders) touches or goes beyond
// this, the fills will be scratched by entering opposite orders at the fill price
struct ScratchParams {
uint32_t max_overfill;
};
// If this is enabled, then as fills accumulate, profit GTC orders are
// immediately sent N ticks away on the opposite side.
struct ProfitOrderParams {
uint32_t ticks_away;
};
// If N contracts trade in T seconds, then the algo is paused (ie child exchange order
// is/are cancelled) for X seconds. Once the condition clears order is reentered.
struct TradeAccumulationParams {
uint32_t contracts;
uint32_t seconds;
uint32_t sleep_seconds;
};
struct AlgoParams {
StepParams steps;
uint32_t clip_limit;
std::optional<ScratchParams> scratch;
std::optional<ProfitOrderParams> profit_orders;
std::optional<TradeAccumulationParams> trade_accumulation;
};
class DormanAlgo : public IAlgoOrder {
struct Impl;
std::unique_ptr<Impl> me;
IAlgoServices& algo() const;
public:
DormanAlgo();
~DormanAlgo();
OrderOpResult do_before_launch(IBeforeLaunchAlgoServices &) override;
void do_launch(IAlgoServices &) override;
void do_launch_attached(IAlgoServices &, OrderKey, ChildState) override;
void do_update(api::orderman::Update const &) override;
void on_child_change(OrderKey, ChildState const &) override;
void on_book(SecurityKey, const Book&) override;
void on_timer() override;
void on_ticker(SecurityKey, const TradeVector&) override;
IAlgoOrder::OnCancelResponse on_cancel() override;
Quantity exposed_qty() const;
private:
//
// Child management
void update_child_template(IBeforeLaunchAlgoServices&, const api::orderman::CustomOrderDefinition&);
void update_child(Quantity exposed);
bool child_active() const;
void do_scratch();
void send_profit_order(Price, Quantity);
void complete();
void pause_for(Duration);
bool is_paused() const;
void resume();
};
template <class OK,class ERR>
using Result = std::variant<OK,ERR>;
Result<AlgoParams,OrderOpResult> to_dorman_params(const api::orderman::DynamicOrderDefinition&);
}}} //namespace
@@ -1,401 +0,0 @@
#include "lib/orderman/orders/algo/algo_orders/LimitCoverAlgo.h"
#include "lib/sparkproto/SparkProtos.pb.h"
#include "lib/api/services/OrderService.pb.h"
#include "lib/orderman/order_factory/IOrderFactory.h"
#include "lib/orderman/orderman_utils/orderman_utils.h"
#include "lib/orderman/orders/algo/IAlgoServices.h"
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
#include "lib/os/os.h"
#include "lib/utils/PBUtils.h"
#include "lib/orderman/orders/algo/utils/DynamicOrderAdapter.h"
#include "lib/orderman/orders/algo/algo_orders/limit_cover/LimitCoverDefinition.h"
#include "lib/orderman/orders/algo/algo_orders/limit_cover/LimitCoverAdapter.h"
#include <map>
#include <limits>
#include <iostream>
#include <sstream>
#define DEFAULT_LOG_LEVEL Info
#define SUMMARIZE_TRANSACTION_BEGIN(id, type, ...) Summary __LOG_TRANS(this, id, Formatter::fmt(__VA_ARGS__), type, DEFAULT_LOG_LEVEL)
#define SUMMARIZE_TRANSACTION(id, type) Summary __LOG_TRANS(this, id, "", type, DEFAULT_LOG_LEVEL)
#define SUMMARIZE SUMMARIZE_TRANSACTION(__FUNCTION__, SummaryType::StatusChange)
// define 'PRINT_SUMMARIES' to print all logs to the console
// (assuming logs are made with the MSG/MSG_LEVEL macros)
#ifdef PRINT_SUMMARIES
#define _PRINT_MSG(x) std::cout << x << std::endl;
#else
#define _PRINT_MSG(x)
#endif
#define _MSG(level, msg) \
_PRINT_MSG(msg); \
LOG(OrderMan, level, "{}", msg)
#define MSG_LEVEL(level, ...) _MSG(level, (Formatter::fmt(__VA_ARGS__)))
// these automatically prepend log_header() to the args
#define MSG(...) MSG_LEVEL(DEFAULT_LOG_LEVEL, log_header(), " ", __VA_ARGS__)
#define DIAG(...) MSG_LEVEL(Diag, log_header(), " ", __VA_ARGS__)
#define INFO(...) MSG_LEVEL(Info, log_header(), " ", __VA_ARGS__)
#define WARN(...) MSG_LEVEL(Warn, log_header(), " ", __VA_ARGS__)
#define ERROR(...) MSG_LEVEL(Error, log_header(), " ", __VA_ARGS__)
namespace bts {
namespace orderman {
using namespace api::orderman;
using namespace bts::orderman::limit_cover::utils;
using Adapter = bts::orderman::LimitCoverAdapter;
namespace limit_cover {
namespace utils {
void init_delete_and_cover(OrderDefinition& target, const DeleteAndCoverDefinition& def) {
if (!target.has_custom_def())
*target.mutable_custom_def() = CustomOrderDefinition();
init_delete_and_cover(*target.mutable_custom_def(), def);
}
void init_delete_and_cover(CustomOrderDefinition& target, const DeleteAndCoverDefinition& def) {
if (!target.has_delete_and_cover()) {
*target.mutable_delete_and_cover() = DeleteAndCoverDefinition(def);
} else {
target.mutable_delete_and_cover()->CopyFrom(def);
}
}
void init_child_update(Update& target, uint32_t qty, double price, const DeleteAndCoverDefinition& def) {
target.set_quantity(qty);
target.set_price(price);
init_delete_and_cover(*target.mutable_custom(), def);
}
#define INVALID_DEF(x) OrderOpResult(api::orderman::ORDER_ERROR_INVALID_ORDER_DEFINITON, x)
OrderOpResult validate_custom_def(const CustomOrderDefinition& custom_def) {
if (!custom_def.has_dynamic())
return INVALID_DEF("DynamicOrderDefinition is undefined");
return Adapter::validate_proto(custom_def.dynamic());
}
OrderOpResult validate_def(const OrderDefinition& def) {
if (def.attach_target_order_key() != 0) {
return INVALID_DEF("Attach not supported.");
} else if (def.has_custom_def()) {
return validate_custom_def(def.custom_def());
} else {
return INVALID_DEF("CustomOrderDefinition is undefined.");
}
}
OrderOpResult validate_update(const Update& upd) {
return upd.has_custom() ?
validate_custom_def(upd.custom()) : OrderOpResult();
}
} // namespace utils
} // namespace limit_cover
struct LimitCoverAlgo::PImpl {
IAlgoServices *algo = nullptr;
Status status = Status::WAITING_TO_DEPLOY;
OrderKey child_key = null_order_key();
double child_price = os::nan();
uint32_t child_qty = 0;
Book book;
uint32_t limit_volume = 0;
std::map<uint32_t, LimitCoverGate> gates;
double settlement = os::nan();
double price_offset_from_settle = 0;
double limit_price = os::nan();
};
struct LimitCoverAlgo::Summary {
Summary(LimitCoverAlgo* owner, std::string transaction_id, std::string begin_tag = {}, SummaryType type = SummaryType::StatusChange, log::Level level = DEFAULT_LOG_LEVEL)
: _owner(owner), _transaction_id(transaction_id), _original_status(owner->me->status), _type(type), _level(level) {
if (_owner != nullptr && !_transaction_id.empty()) {
std::stringstream str;
str << owner->log_header() << " begin " << transaction_id << ".";
if (!begin_tag.empty()) {
str << " " << begin_tag << ".";
}
if (type == SummaryType::FullState) {
str << " Algo State: " << _owner->fmt_state() << ".";
}
MSG_LEVEL(level, str.str());
}
}
~Summary() {
std::stringstream msg_str;
if (!_transaction_id.empty()) {
msg_str << " end " << _transaction_id << ".";
}
switch (_type) {
case SummaryType::StatusChange:
if (_owner->me->status != _original_status)
msg_str << " Status changed from " << _original_status << " to " << _owner->me->status << ".";
break;
case SummaryType::FullState:
msg_str << " Algo State: " << _owner->fmt_state() << ".";
break;
}
auto msg = msg_str.str();
if (!msg.empty()) {
MSG_LEVEL(_level, _owner->log_header(), msg);
}
}
private:
LimitCoverAlgo *_owner;
std::string _transaction_id;
Status _original_status;
SummaryType _type;
log::Level _level;
};
LimitCoverAlgo::LimitCoverAlgo() : me(new PImpl()) {}
LimitCoverAlgo::~LimitCoverAlgo() {}
OrderOpResult
LimitCoverAlgo::do_before_launch(IBeforeLaunchAlgoServices &balgo) {
SUMMARIZE;
bts_assert(me->status == Status::WAITING_TO_DEPLOY);
bts_assert(me->gates.empty());
auto vd = validate_def(balgo.definition());
if (vd.ok()) {
auto lcdef = Adapter::from_proto(balgo.definition());
me->price_offset_from_settle = lcdef.price_offset();
me->gates = lcdef.normal_gates();
}
return vd;
}
void LimitCoverAlgo::do_launch(IAlgoServices& algo) {
SUMMARIZE;
bts_assert(me->status == Status::WAITING_TO_DEPLOY);
me->algo = &algo;
me->child_qty = algo.quantity().value();
algo.subscribe_book(SecurityKey(algo.security().id()));
algo.subscribe_settlement(SecurityKey(algo.security().id()));
}
void LimitCoverAlgo::do_update(Update const &upd) {
SUMMARIZE_TRANSACTION_BEGIN(__FUNCTION__, SummaryType::StatusChange, utils::pb::to_string(upd));
auto vup = validate_update(upd);
if (!vup.ok()) {
me->status = Status::DONE;
algo().terminate_error(Formatter::fmt("Invalid update: ", vup.error_msg, "."));
return;
}
if (upd.has_custom()) {
auto lcdef = Adapter::from_proto(upd.custom());
if (me->status == Status::WAITING_TO_DEPLOY) {
me->price_offset_from_settle = lcdef.price_offset();
recompute_limit_price();
recompute_limit_volume();
}
me->gates = lcdef.normal_gates();
if (me->status == Status::WORKING)
recompute_gate();
}
switch (me->status) {
case Status::WAITING_TO_DEPLOY:
try_deploy();
break;
case Status::WORKING: {
// don't change the child price; the price param is irrelevant to this algo.
if (upd.has_custom() || me->child_qty != upd.quantity())
update_child(upd.quantity());
break;
}
default:
break;
}
}
void LimitCoverAlgo::on_book(SecurityKey, Book const &b) {
SUMMARIZE_TRANSACTION_BEGIN(__FUNCTION__, SummaryType::StatusChange, "BBO: ", Formatter::to_string(b));
me->book = b;
recompute_limit_volume();
switch (me->status) {
case Status::WAITING_TO_DEPLOY:
try_deploy();
break;
case Status::WORKING: {
if (recompute_gate())
update_child(me->child_qty);
break;
}
default:
break;
}
}
void LimitCoverAlgo::update_child(uint32_t qty) {
bts_assert(me->algo != nullptr);
bts_assert(me->status == Status::WORKING);
me->child_qty = qty;
Update upd;
init_child_update(upd, qty, me->child_price, curr_gate().definition());
MSG("updating algo child: ", utils::pb::to_string(upd));
me->algo->update_child(me->child_key, upd);
}
void LimitCoverAlgo::on_child_change(OrderKey key, ChildState const& state) {
bts_assert(key == me->child_key);
SUMMARIZE_TRANSACTION_BEGIN(__FUNCTION__, SummaryType::FullState, "Child State: ", Formatter::to_string(state));
algo().update_fill_state(state.total_fills, state.last_price);
me->child_price = state.price.value();
switch (me->status) {
case Status::WORKING:
switch (state.status) {
case ChildStatus::WORKING:
break;
case ChildStatus::CANCELED: {
auto msg = Formatter::fmt("main child (", key, ") canceled unexpectedly.");
MSG(msg, ". ", fmt_state());
me->status = Status::DONE;
algo().terminate_error(msg);
break;
}
case ChildStatus::COMPLETED:
me->status = Status::DONE;
algo().complete();
break;
}
break;
case Status::DONE:
break;
default:
bts_assert_msg(false, Formatter::fmt(log_header(), " unexpected status: ", me->status));
break;
}
}
void LimitCoverAlgo::on_settlement(SecurityKey, Price settlement) {
if (me->status == Status::WAITING_TO_DEPLOY) {
MSG("updating settlement from ", me->settlement, " to ", settlement);
me->settlement = settlement.value();
DIAG("recomputing limit price...");
recompute_limit_price();
DIAG("limit price is ", me->limit_price);
DIAG("recomputing limit volume...");
recompute_limit_volume();
DIAG("limit volume is ", me->limit_volume);
try_deploy();
} else {
MSG("ignored settlement update to ", settlement,
": settlement updates are only processed while the algo is ", Status::WAITING_TO_DEPLOY,
". Settlement at time of deploy was ", me->settlement);
}
}
void LimitCoverAlgo::try_deploy() {
MSG("trying to deploy. ", fmt_state());
bts_assert(me->status == Status::WAITING_TO_DEPLOY);
bts_assert(me->algo != nullptr);
// this is probably redundant (better safe than sorry tho).
bts_assert(me->child_key == null_order_key());
if (os::is_nan(me->settlement)) {
MSG("still waiting for settle.");
} else if (me->limit_volume < activation_threshold()) {
MSG("still waiting for limit volume (", me->limit_volume, ") to breech activation threshold (", activation_threshold(), ").");
} else {
bts_assert(!os::is_nan(me->limit_price));
recompute_gate();
OrderDefinition child_def;
bts_assert(!me->gates.empty());
child_def.CopyFrom(algo().definition());
init_delete_and_cover(child_def, curr_gate().definition());
bts_assert(child_def.custom_def().has_delete_and_cover());
MSG("deploying child order: ", utils::pb::to_string(child_def));
me->child_key = algo().launch_child(child_def, Price(me->limit_price), algo().quantity());
me->status = Status::WORKING;
algo().set_ladder_visibility(false);
}
}
template<class T>
bool did_change(T& backing, T new_value) {
if (backing == new_value)
return false;
backing = new_value;
return true;
}
bool LimitCoverAlgo::recompute_gate() {
if (me->gates.empty())
return false;
auto orig_sz = me->gates.size();
auto it = me->gates.lower_bound(me->limit_volume);
if (it == me->gates.end() || (it != me->gates.begin() && it->first > me->limit_volume))
it--;
me->gates.erase(me->gates.begin(), it);
return me->gates.size() < orig_sz;
}
// limit price
double LimitCoverAlgo::compute_limit_price() const {
return os::is_nan(me->settlement) ? os::nan() :
securities::improve_price(side(), Price(me->settlement), Price(me->price_offset_from_settle))
.value();
}
bool LimitCoverAlgo::recompute_limit_price() {
return did_change(me->limit_price, compute_limit_price());
}
// limit volume
uint32_t LimitCoverAlgo::compute_limit_volume() const {
return me->algo == nullptr ? 0 :
BookUtils::volume_at_or_better(me->book, side(), me->limit_price);
}
bool LimitCoverAlgo::recompute_limit_volume() {
return did_change(me->limit_volume, compute_limit_volume());
}
// pseudo properties (const state accessors)
IAlgoServices &LimitCoverAlgo::algo() const { return *me->algo; }
api::Side LimitCoverAlgo::side() const {
return me->algo == nullptr ? api::SIDE_UNDEFINED : me->algo->definition().side();
}
const LimitCoverGate& LimitCoverAlgo::curr_gate() const {
bts_assert(!me->gates.empty());
return me->gates.begin()->second;
}
uint32_t LimitCoverAlgo::activation_threshold() const {
return me->gates.empty() ? std::numeric_limits<uint32_t>::max() : me->gates.begin()->first;
}
std::string LimitCoverAlgo::log_header() const {
std::stringstream ostr;
ostr << "LimitCoverAlgo";
if (me->algo != nullptr) {
ostr << "(" << me->algo->order_key().value() << ")";
}
ostr << "[" << fmt_status(me->status) << "]";
return ostr.str();
}
std::string LimitCoverAlgo::fmt_state() const {
std::stringstream ostr;
if (me->algo != nullptr) {
ostr << " [" << fmt_status(me->status) << "]"
<< Formatter::to_string(side()) << " " << me->algo->quantity().value()
<< " @ " << me->algo->price().value()
<< " (" << me->price_offset_from_settle
<< " away from settle).";
if (me->child_key != null_order_key()) {
ostr << " Main child key: " << me->child_key << ", ";
}
ostr << " Settle: " << me->settlement
<< ", Limit Price: " << me->limit_price
<< ", BBO: " << Formatter::to_string(me->book);
} else {
ostr << "(initializing)";
}
return ostr.str();
}
} // namespace orderman
} // namespace bts
@@ -1,94 +0,0 @@
#pragma once
#include "lib/orderman/orderman_utils/BookUtils.h"
#include "lib/orderman/orderman_utils/Formatter.h"
#include "lib/orderman/orders/algo/IAlgoOrder.h"
#include "lib/orderman/orders/algo/algo_orders/limit_cover/LimitCoverDefinition.h"
#include "lib/orderman/orders/algo/algo_orders/limit_cover/LimitCoverGate.h"
#include <map>
namespace bts {
namespace orderman {
class LimitCoverAlgo : public IAlgoOrder {
public:
LimitCoverAlgo();
~LimitCoverAlgo();
OrderOpResult do_before_launch(IBeforeLaunchAlgoServices &) override;
void do_launch(IAlgoServices &) override;
void do_update(api::orderman::Update const &) override;
void on_book(SecurityKey, Book const &) override;
void on_settlement(SecurityKey, Price settlement) override;
void on_child_change(OrderKey, ChildState const &) override;
enum class Status {
WAITING_TO_DEPLOY,
WORKING,
DONE
};
using Status = bts::orderman::LimitCoverAlgo::Status;
enum SummaryType {
StatusChange,
FullState
};
private:
struct PImpl;
struct Summary;
std::unique_ptr<PImpl> me;
IAlgoServices &algo() const;
api::Side side() const;
std::string log_header() const;
std::string fmt_state() const;
// returns the first gate in gates (asserts that gates isn't empty).
// Note: after the child is deployed, gates with lower thresholds are
// removed when the limit volume passes the next gates' thresh.
const LimitCoverGate& curr_gate() const;
/// On the compute/recompute methods:
/// compute_blah just returns the result (doesn't mutate any state),
/// while recompute_blah assigns the result to the appropriate field,
/// and returns a bool indicating whether or not the value changed.
// limit price
double compute_limit_price() const;
bool recompute_limit_price();
// limit volume
uint32_t compute_limit_volume() const;
bool recompute_limit_volume();
// recomputes the current gate (i.e., the one with the
// highest activation thresh that is still less than
// the limit volume) then removes all gates with lower threshs.
bool recompute_gate();
uint32_t activation_threshold() const;
//
void try_deploy();
void update_child(uint32_t qty);
};
namespace limit_cover {
namespace utils {
inline std::string fmt_status(LimitCoverAlgo::Status status) {
switch (status) {
case LimitCoverAlgo::Status::WAITING_TO_DEPLOY: return "WAITING_TO_DEPLOY";
case LimitCoverAlgo::Status::WORKING: return "WORKING";
case LimitCoverAlgo::Status::DONE: return "DONE";
default: return Formatter::fmt("STATUS_", static_cast<int>(status));
}
}
void init_delete_and_cover(api::orderman::OrderDefinition& target, const api::orderman::DeleteAndCoverDefinition& def);
void init_delete_and_cover(api::orderman::CustomOrderDefinition& target, const api::orderman::DeleteAndCoverDefinition& def);
void init_child_update(api::orderman::Update& target, uint32_t qty, double price, const api::orderman::DeleteAndCoverDefinition& def);
OrderOpResult validate_def(const api::orderman::OrderDefinition&);
OrderOpResult validate_custom_def(const api::orderman::CustomOrderDefinition&);
OrderOpResult validate_update(const api::orderman::Update&);
} // namespace utils
} // namespace limit_cover
inline std::ostream& operator<<(std::ostream& ostr, const LimitCoverAlgo::Status& status) {
ostr << limit_cover::utils::fmt_status(status);
return ostr;
}
} // namespace orderman
} // namespace bts
@@ -1,584 +0,0 @@
#include "lib/orderman/orders/algo/algo_orders/PyramidAlgo.h"
#include "lib/domain_model/Security.h"
#include "lib/orderman/order_factory/IOrderFactory.h"
#include "lib/orderman/orderman_utils/Book.h"
#include "lib/orderman/orderman_utils/orderman_utils.h"
#include "lib/orderman/orders/algo/IAlgoServices.h"
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
#include "lib/os/os.h"
#include "lib/domain_model/Security.h"
#include "lib/utils/PBUtils.h"
#include <stdint.h>
namespace bts {
namespace orderman {
using namespace api::orderman;
enum class PyramidAlgo::Status { WAITING_FOR_MD, WAITING_FOR_MD_ATTACH, WORKING, DONE };
enum class PyramidAlgo::ExitPath { CANCEL, ERR, COMPLETE };
struct LegData{
const size_t index;
const SecurityKey sec_key;
const double tick_size;
const api::Side side; //trading side
ChildTemplate* order_template = nullptr;
OrderKey order_key;
ChildState order_state;
bool recv_book;
Book book;
Quantity top_delete; // this will be DONTCARE for covers
Quantity cover_payup;// this will be DONTCARE for top
LegData (size_t index_a,
SecurityKey sec_key_a,
double tick_size_a,
api::Side side_a,
ChildTemplate* order_template_a,
Quantity qty)
:
index (index_a),
sec_key (sec_key_a),
tick_size(tick_size_a),
side (side_a),
order_template (order_template_a),
order_key(null_order_key()),
order_state(),
recv_book(false),
book(),
top_delete(index == 0 ? qty.value() : 0),
cover_payup(index == 0 ? 0 : qty.value())
{
}
const BookSide& opp_md() const{
return book.side(SpreaderUtils::invert_side(side));
}
bool is_top_spread() const{
return index == 0;
}
void set_book (const Book& book_a){
recv_book = true;
book = book_a;
}
};
struct PyramidAlgo::PImpl {
Status state = Status::WAITING_FOR_MD;
IAlgoServices* algo_services = nullptr;
IBeforeLaunchAlgoServices* bl_algo_services;
PyramidAlgo::PyramidAlgoParams params;
std::vector<LegData> legs;
api::Side side;
Price out_price;
Quantity out_qty;
PImpl(){
}
LegData* find_leg_from_sec (SecurityKey sec_key){
for (auto& l : legs)
if(l.sec_key == sec_key)
return &l;
return nullptr;
}
LegData* find_leg_from_ord_key (OrderKey ord_key){
for (auto& l : legs)
if(l.order_key == ord_key)
return &l;
return nullptr;
}
};
PyramidAlgo::PyramidAlgo() : me(new PImpl()) {}
PyramidAlgo::~PyramidAlgo() {}
IAlgoServices& PyramidAlgo::_algo() const { return *me->algo_services; }
// initialization /////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
OrderOpResult PyramidAlgo::do_before_launch(IBeforeLaunchAlgoServices& serv) {
me->bl_algo_services = &serv;
auto& def = serv.definition();
if (def.has_custom_def() && def.custom_def().has_dynamic()){
auto conv_res = _get_creation_params(def.custom_def(), serv);
if (std::get<1>(conv_res)){
// params are good
me->params = std::get<0>(conv_res);
me->side = def.side();
// top spread
auto* t = _create_top_order_template(serv);
double tick_size = serv.lookup_security(me->params.top_spread)->contract_spec().low_tick();
me->legs.emplace_back(0, me->params.top_spread, tick_size, def.side(), t,
me->params.top_delete);
// covers
size_t i = 0;
for (SecurityKey key : me->params.cover_spreads){
auto side = SpreaderUtils::invert_side(def.side());
auto* t = _create_hedge_order_template(serv,i);
double tick_size = serv.lookup_security(key)->contract_spec().low_tick();
me->legs.emplace_back(i+1, key, tick_size, side, t, me->params.cover_payups[i]);
i++;
}
}
else
return {OrderError::ORDER_ERROR_INVALID_PARAMETER,
std::get<2>(conv_res)};
}
else
return {OrderError::ORDER_ERROR_INVALID_PARAMETER,
std::string("Missing parameters")};
return {};
}
void PyramidAlgo::do_launch(IAlgoServices& algo_services) {
me->algo_services = &algo_services;
me->out_price = algo_services.price();
me->out_qty = algo_services.quantity();
for (const LegData& l : me->legs)
algo_services.subscribe_book(l.sec_key);
}
void PyramidAlgo::do_launch_attached(IAlgoServices& algo_services,
OrderKey key,
ChildState c) {
me->algo_services = &algo_services;
if(c.quantity != algo_services.quantity() ||
!bts::securities::is_same(c.price, algo_services.price())){
_cxl_and_end(ExitPath::ERR,
"Pyramid price or quantity did not match the working order",
true);
}
else{
me->legs[0].order_key = key;
me->out_price = c.price;
me->out_qty = c.quantity;
for (const LegData& l : me->legs)
algo_services.subscribe_book(l.sec_key);
_switch_state(PyramidAlgo::Status::WAITING_FOR_MD_ATTACH);
on_child_change(key,c);
}
}
// updates ////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void PyramidAlgo::do_update(const api::orderman::Update& update) {
LOG(OrderMan, Diag, "PyramidAlgo::do_update order:{} state:{} "
"receiving update: {}",
_algo().order_key().value(),
static_cast<int>(me->state),
utils::pb::to_string(update));
auto conv_res = _get_update_params(update, me->params);
if (!std::get<1>(conv_res)){
LOG(OrderMan, Warn, "PyramidAlgo::do_update order:{} bad update, ignoring",
_algo().order_key().value());
return;
}
const PyramidAlgoParams& algo_params = std::get<0>(conv_res);
Price price = Price(update.price());
Quantity qty = Quantity(update.quantity());
switch(me->state){
case PyramidAlgo::Status::WAITING_FOR_MD:
case PyramidAlgo::Status::WAITING_FOR_MD_ATTACH:
LOG(OrderMan, Info, "PyramidAlgo::do_update order:{} state:{} ignored",
_algo().order_key().value(),static_cast<int>(me->state));
break;
case PyramidAlgo::Status::WORKING:{
bool pq_changed = _copy_update(algo_params, price, qty);
if(_target_reached()){
_cxl_and_end (PyramidAlgo::ExitPath::CANCEL, "Target reached");
return;
}
if (_working_state_met()){
if(pq_changed)
_modify_top_spread_order();
}
else
_cxl_and_end(PyramidAlgo::ExitPath::CANCEL,
"Order cancelled (Cover prices not met)");
break;
}
case PyramidAlgo::Status::DONE:
break;
}
}
// callbacks //////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void PyramidAlgo::on_book(SecurityKey key, const Book& book) {
LegData* leg_data = me->find_leg_from_sec(key);
if(leg_data != nullptr){
leg_data->set_book(book);
_analyze_md_and_act();
}
}
// this only gets called on am explicit algo cancel
// from the outside
IAlgoOrder::OnCancelResponse PyramidAlgo::on_cancel(){
// cancel top spread, let hedges work, cancel algo
switch(me->state){
case PyramidAlgo::Status::WAITING_FOR_MD:
case PyramidAlgo::Status::WAITING_FOR_MD_ATTACH:
case PyramidAlgo::Status::WORKING:
_cxl_and_end(PyramidAlgo::ExitPath::CANCEL,"Algo cancelled");
break;
case PyramidAlgo::Status::DONE:
break;
}
return IAlgoOrder::OnCancelResponse::IGNORE;
}
void PyramidAlgo::on_child_change(OrderKey key, const ChildState &st) {
LOG(OrderMan, Info,
"PyramidAlgo::on_child_change key:{} child_key:{} state:{} status:{} "
"total_fills:{} last_price:{}",
_algo().order_key(),
key,
static_cast<int>(me->state),
static_cast<int>(st.status),
st.total_fills,
st.last_price);
LegData* leg = me->find_leg_from_ord_key (key);
if (me->legs[0].order_key == key){
switch(me->state){
case PyramidAlgo::Status::WAITING_FOR_MD:
bts_assert_msg (false, "No child orders");
break;
case PyramidAlgo::Status::WAITING_FOR_MD_ATTACH:
leg->order_state = st;
_algo().update_fill_state(st.total_fills, st.avg_price);
_check_for_completion();
break;
case PyramidAlgo::Status::WORKING:
leg->order_state = st;
_algo().update_fill_state(st.total_fills, st.avg_price);
_send_hedges(st.last_fills);
_check_for_completion();
break;
case PyramidAlgo::Status::DONE:
break;
}
}
}
///////////////////////////////////////////////////////////////////////////////
// stateless conversion ///////////////////////////////////////////////////////
PyramidAlgo::PyramidAlgoParams PyramidAlgo::_convert_params (
const CustomOrderDefinition& cod){
const DynamicOrderDefinition& def = cod.dynamic();
const auto& params = def.order_params();
PyramidAlgoParams rv;
// top contract
auto r = get_if<uint32_t>(params, "Top Spread");
rv.top_spread = r.has_value() ? SecurityKey(r.value()) : SecurityKey(0);
// top delete
r = get_if<uint32_t>(params, "Delete");
rv.top_delete = Quantity(r.has_value() ? r.value() : UINT32_MAX);
for (size_t i = 0; i < 5; i++){
auto idx = std::to_string(i+1);
auto b = get_if<uint32_t>(params, "Spread " + idx);
if (b.has_value() && b.value() != 0){
rv.cover_spreads.emplace_back(b.value());
auto pu = get_if<uint32_t>(params, "Spread " + idx + " Payup");
rv.cover_payups.emplace_back(pu.has_value() ? pu.value() : UINT32_MAX);
}
}
return rv;
}
std::tuple<PyramidAlgo::PyramidAlgoParams,bool,std::string>
PyramidAlgo::_get_creation_params(const CustomOrderDefinition& cod,
IBeforeLaunchAlgoServices& serv){
PyramidAlgo::PyramidAlgoParams rv = _convert_params(cod);
// error checking
if(rv.top_spread.value() != serv.security().id())
return std::make_tuple(rv,false,
"Algo can only be launched from the Top Spread");
if(rv.cover_spreads.size() < 2)
return std::make_tuple(rv,false,
"Not enough cover spreads");
if (rv.cover_spreads[0].value() == 0 ||
rv.cover_spreads[1].value() == 0)
return std::make_tuple(rv,false,
"Not enough cover spreads");
return std::make_tuple(rv,true,std::string(""));
}
std::tuple<PyramidAlgo::PyramidAlgoParams,bool,std::string>
PyramidAlgo::_get_update_params(const Update& update,
const PyramidAlgoParams& curr_params){
if(update.has_custom() && update.custom().has_dynamic()){
// means there is a params change
PyramidAlgoParams new_params = _convert_params(update.custom());
if(new_params.top_spread != curr_params.top_spread ||
new_params.cover_spreads.size() != curr_params.cover_spreads.size())
return std::make_tuple(new_params,false,"Contracts can not be updated");
for (size_t i=0; i < curr_params.cover_spreads.size(); i++)
if(new_params.cover_spreads[i] != curr_params.cover_spreads[i])
return std::make_tuple(new_params,false,"Contracts can not be updated");
return std::make_tuple(new_params,true,std::string(""));
}
else
return std::make_tuple(curr_params,true,std::string(""));
}
///////////////////////////////////////////////////////////////////////////////
// order template creation/////////////////////////////////////////////////////
ChildTemplate* PyramidAlgo::_create_top_order_template (
IBeforeLaunchAlgoServices& serv) const{
OrderDefinition order_def = serv.definition();
order_def.set_security_key (me->params.top_spread.value());
order_def.set_side(me->side);
order_def.mutable_custom_def()->mutable_limit()->MergeFrom (
LimitOrderDefinition());
return &(serv.make_child_template(order_def));
}
ChildTemplate* PyramidAlgo::_create_hedge_order_template (
IBeforeLaunchAlgoServices& serv,
size_t hedge_idx) const{
OrderDefinition order_def = serv.definition();
order_def.set_attach_target_order_key(null_order_key().value());
order_def.set_security_key (me->params.cover_spreads[hedge_idx].value());
order_def.set_side(SpreaderUtils::invert_side(me->side));
order_def.set_sub_type(ORDER_SUB_TYPE_HEDGING_LEG);
LeanOrderDefinition lean;
lean.mutable_cross_threshold()->set_absolute(me->params.cover_payups[hedge_idx].value());
lean.set_max_chase_ticks(1);
lean.set_trade_toward_behavior(LeanOrderDefinition::NO_CHANGE);
lean.mutable_child()->mutable_limit()->MergeFrom (
LimitOrderDefinition());
order_def.mutable_custom_def()->mutable_lean()->MergeFrom (lean);
return &(serv.make_child_template(order_def));
}
void PyramidAlgo::_analyze_md_and_act(){
switch(me->state){
case PyramidAlgo::Status::WAITING_FOR_MD:
if(!_md_recvd())
return;
// received data for the first time
if (_working_state_met()){
// enter order, and switch state
LegData& top_leg = me->legs[0];
// this is the only place top spread order is sent (once)
top_leg.order_key = _algo().launch_child(
*top_leg.order_template,
me->out_price,
me->out_qty);
LOG(OrderMan, Info,"PyramidAlgo::_analyze_md_and_act launching order key:{} "
"child_key:{} price:{} qty:{}",
_algo().order_key(),
top_leg.order_key,
me->out_price,
me->out_qty);
_switch_state(PyramidAlgo::Status::WORKING);
}
else
_cxl_and_end(PyramidAlgo::ExitPath::CANCEL,
"Order cancelled (Cover prices not met)");
break;
case PyramidAlgo::Status::WAITING_FOR_MD_ATTACH:
if(!_md_recvd())
return;
// received data for the first time
if (_working_state_met())
_switch_state(PyramidAlgo::Status::WORKING);
else
_cxl_and_end(PyramidAlgo::ExitPath::CANCEL,
"Order detached (Cover prices not met)",
true);
break;
case PyramidAlgo::Status::WORKING:
if (!_working_state_met())
_cxl_and_end(PyramidAlgo::ExitPath::CANCEL,
"Order cancelled (Cover prices not met)");
break;
case PyramidAlgo::Status::DONE:
break;
}
}
void PyramidAlgo::_switch_state(Status new_state){
switch(new_state){
case (PyramidAlgo::Status::WAITING_FOR_MD):
bts_assert(false);
break;
case (PyramidAlgo::Status::WAITING_FOR_MD_ATTACH):
bts_assert(me->state == PyramidAlgo::Status::WAITING_FOR_MD);
break;
case (PyramidAlgo::Status::WORKING):
bts_assert(me->state == PyramidAlgo::Status::WAITING_FOR_MD ||
me->state == PyramidAlgo::Status::WAITING_FOR_MD_ATTACH);
break;
case (PyramidAlgo::Status::DONE):
bts_assert(
// when an order is entered and the criteria is not met
me->state == PyramidAlgo::Status::WAITING_FOR_MD ||
// when an order is attached and the market conditions are not met
me->state == PyramidAlgo::Status::WAITING_FOR_MD_ATTACH ||
// when the child order gets into an unexpected state
me->state == PyramidAlgo::Status::WORKING);
break;
}
LOG(OrderMan, Info,"PyramidAlgo::_switch_state key:{} {}->{} ",
_algo().order_key(),
static_cast<int>(me->state),
static_cast<int>(new_state));
me->state = new_state;
}
void PyramidAlgo::_send_hedges (Quantity filled_qty){
if (filled_qty.value() > 0)
for (auto& l : me->legs)
if(!l.is_top_spread()){
const auto& inside_md = l.opp_md()[0];
Price hedge_price = Price(inside_md.price());
uint32_t inside_md_qty = inside_md.size();
if (l.cover_payup.value() != 0 &&
inside_md_qty > l.cover_payup.value())
hedge_price = securities::worsen_price(l.side, hedge_price, Price(l.tick_size));
// check payup
l.order_key = _algo().launch_child(
*l.order_template,
hedge_price,
filled_qty);
_algo().detach_child(l.order_key);
}
}
void PyramidAlgo::_modify_top_spread_order(){
Update child_update;
child_update.set_price(me->out_price.value());
child_update.set_quantity(me->out_qty.value());
LOG(OrderMan, Info,"PyramidAlgo::_modify_top_spread_order modifying order key:{} "
"child_key:{} price:{} qty:{}",
_algo().order_key(),
me->legs[0].order_key,
me->out_price,
me->out_qty);
_algo().update_child(me->legs[0].order_key, child_update);
}
// copies the params, price and qty to the state
// retuns true is the price or qty has changed
bool PyramidAlgo::_copy_update(const PyramidAlgoParams& algo_params,
Price price, Quantity qty){
// copy input params (which are stored seperately)
me->params.top_delete = algo_params.top_delete;
size_t cov_idx = 0;
for (Quantity payup : algo_params.cover_payups)
me->params.cover_payups[cov_idx++] = payup;
// copy leg data
cov_idx = 0;
me->legs[0].top_delete = algo_params.top_delete;
for (Quantity pu : algo_params.cover_payups){
LegData& cover_leg = me->legs[cov_idx+1];
if(cover_leg.cover_payup != pu){
cover_leg.cover_payup = pu;
cover_leg.order_template = _create_hedge_order_template(
*me->bl_algo_services,
cov_idx);
}
cov_idx++;
}
// copy price and qty (returns true is they have changed)
bool pq_changed = me->out_qty.value() != qty.value() ||
!bts::securities::is_same(me->out_price, price);
me->out_price = price;
me->out_qty = qty;
return pq_changed;
}
// if the top spread order is in a final state, the algo
// algo goes to the final state
void PyramidAlgo::_check_for_completion(){
const ChildState& top_ord = me->legs[0].order_state;
switch (top_ord.status){
case (ChildStatus::WORKING):
break;
case (ChildStatus::COMPLETED):
_cxl_and_end(PyramidAlgo::ExitPath::ERR,"");
break;
case (ChildStatus::CANCELED):
_cxl_and_end(PyramidAlgo::ExitPath::ERR,
"Top spread unexpectedly cancelled");
break;
}
}
void PyramidAlgo::_cxl_and_end(PyramidAlgo::ExitPath exit_path,
const std::string& msg,
bool detach_top){
if(me->legs[0].order_key != null_order_key()){
const ChildState& top_ord_state = me->legs[0].order_state;
if(top_ord_state.status == ChildStatus::WORKING){
if(detach_top)
_algo().detach_child(me->legs[0].order_key);
else
_algo().cancel_child(me->legs[0].order_key);
}
}
switch(exit_path){
case PyramidAlgo::ExitPath::ERR:
_algo().terminate_error(msg);
break;
case PyramidAlgo::ExitPath::CANCEL:
_algo().cancel(msg);
break;
case PyramidAlgo::ExitPath::COMPLETE:
_algo().complete();
break;
}
_switch_state(PyramidAlgo::Status::DONE);
}
// true the out qty is changed it be below
// the filled qty
bool PyramidAlgo::_target_reached() const{
return me->legs[0].order_state.total_fills.value() >=
me->out_qty.value();
}
bool PyramidAlgo::_md_recvd() const{
for (const LegData& l : me->legs)
if(!l.recv_book)
return false;
return true;
}
bool gr_than_eq(double p1, double p2){
return securities::test_price_equality(p1,p2) || p1 > p2;
}
bool less_than_eq(double p1, double p2){
return securities::test_price_equality(p1,p2) || p1 < p2;
}
bool PyramidAlgo::_working_state_met() const{
double cover_sum = 0.0;
size_t i = 0;
for (const auto& l : me->legs)
if (i++ > 0)
cover_sum += l.opp_md()[0].price();
bool rv = !os::is_nan(cover_sum) &&
(
(
me->side == api::Side::SIDE_BUY &&
less_than_eq(me->out_price.value(),cover_sum)
)
||
(
me->side == api::Side::SIDE_SELL &&
gr_than_eq(me->out_price.value(),cover_sum)
)
);
if (!rv && !os::is_nan(cover_sum)){
// price condition is not met, but if the
// cum qty at the top leg price is > threashold
// then the condition is met ()
const auto& top_leg = me->legs[0];
Quantity cumm_level_qty;
SpreaderUtils::find_qty_upto_price_level(top_leg.book,
top_leg.side,
Price(me->out_price),
0.0,
cumm_level_qty);
rv = cumm_level_qty.value() > top_leg.top_delete.value();
}
return rv;
}
} // namespace orderman
} // namespace bts
@@ -1,74 +0,0 @@
#pragma once
#include "lib/orderman/orders/algo/IAlgoOrder.h"
namespace bts {
namespace orderman {
class ChildTemplate;
struct LegData;
class PyramidAlgo : public IAlgoOrder {
public:
PyramidAlgo();
~PyramidAlgo();
struct PyramidAlgoParams{
// first one is the top
SecurityKey top_spread;
Quantity top_delete;
std::vector<SecurityKey> cover_spreads;
std::vector<Quantity> cover_payups;
};
public:
OrderOpResult do_before_launch(IBeforeLaunchAlgoServices &) override;
void do_launch(IAlgoServices &) override;
void do_launch_attached(IAlgoServices &, OrderKey, ChildState) override;
void do_update(api::orderman::Update const &) override;
void on_book(SecurityKey, Book const &) override;
void on_child_change(OrderKey, ChildState const &) override;
IAlgoOrder::OnCancelResponse on_cancel() override;
private:
enum class Status;
enum class ExitPath;
struct PImpl;
std::unique_ptr<PImpl> me;
private:
IAlgoServices& _algo() const ;
// converts parameters from the CustomOrderDefinition::dynamic
// to PyramidAlgoParams
static PyramidAlgoParams _convert_params (
const bts::api::orderman::CustomOrderDefinition&);
static std::tuple<PyramidAlgoParams,bool,std::string> _get_creation_params(
const bts::api::orderman::CustomOrderDefinition&,
IBeforeLaunchAlgoServices&);
static std::tuple<PyramidAlgoParams,bool,std::string> _get_update_params(
const api::orderman::Update&,
const PyramidAlgoParams& curr_params);
ChildTemplate* _create_top_order_template (IBeforeLaunchAlgoServices&) const;
ChildTemplate* _create_hedge_order_template (IBeforeLaunchAlgoServices&,
size_t) const;
// acts on md, cognizant of the state
void _analyze_md_and_act();
void _switch_state (Status new_status);
void _send_hedges (Quantity filled_qty);
void _modify_top_spread_order();
// returns true is the price, qty changes
bool _copy_update(const PyramidAlgoParams& algo_params,
Price price, Quantity qty);
void _check_for_completion();
// cxl's the working top leg order (if any), detaches
// all hedges. if is_error then terminates algo, is
// is_cxl then cxl's algo, otherwise completes it
void _cxl_and_end(ExitPath exit_path,
const std::string& err_txt,
bool detach_top = false);
bool _target_reached() const;
// true is all legs have recvd md
bool _md_recvd() const;
bool _working_state_met() const;
};
} // namespace orderman
} // namespace bts
@@ -1,253 +0,0 @@
#include "lib/plugin/SparkServices.h"
#include "lib/api/services/OrderService.pb.h"
#include "lib/logging/logging.h"
#include "lib/orderman/orderman_utils/orderman_utils.h"
#include "lib/orderman/orders/algo/algo_orders/limit_cover/LimitCoverAdapter.h"
#include "lib/orderman/orders/algo/algo_orders/LimitCoverAlgo.h"
#include "lib/config/protos/toggles.pb.h"
#include "lib/config/config.h"
#include "DormanAlgo.h"
#include "PyramidAlgo.h"
#include "TASAlgo.h"
#include "TASCounterAlgo.h"
#include "OnSignalAlgo.h"
using namespace bts;
using namespace api::orderman;
using namespace orderman::dorman;
using namespace orderman;
namespace bts {
namespace orderman {
namespace dorman {
template <class OK,class ERR>
using Result = std::variant<OK,ERR>;
Result<AlgoParams,OrderOpResult> bad_definition(const char* msg) { return {OrderOpResult{ORDER_ERROR_INVALID_ORDER_DEFINITON, msg}}; }
// Validate DynamicOrderDefinition and construct parameter object
Result<AlgoParams,OrderOpResult> to_dorman_params(const api::orderman::DynamicOrderDefinition& def) {
const auto& params = def.order_params();
AlgoParams res;
//
// Step Table
for (size_t x = 0; x < 5; ++x) {
auto xs = std::to_string(x+1);
auto mq = get_if<uint32_t>(params, "Market Quantity " + xs).value_or(0);
auto oq = get_if<uint32_t>(params, "Order Quantity " + xs).value_or(0);
if (mq && oq) {
res.steps.step_table.push_back({ mq, oq });
}
}
std::sort(res.steps.step_table.begin(), res.steps.step_table.end());
res.steps.maximum = get_if<uint32_t>(params, "Max Size").value_or(-1);
res.steps.trail_seconds = get_if<uint32_t>(params, "Trail Seconds").value_or(0);
//
// Clip limit
res.clip_limit = get_if<uint32_t>(params, "Clip Size").value_or(0);
//
// scratch
auto enable_scratch = get_if<bool>(params, "Enable Scratch");
if (enable_scratch && enable_scratch.value()) {
auto overfill = get_if<uint32_t>(params, "Max Overfill");
if (!overfill) return bad_definition("Missing 'Max Overfill'");
res.scratch = { overfill.value() };
}
//
// profit orders
auto enable_profit_orders = get_if<bool>(params, "Profit Orders");
if (enable_profit_orders && enable_profit_orders.value()) {
auto ticks = get_if<uint32_t>(params, "Ticks Away");
if (!ticks) return bad_definition("Missing 'Ticks Away'");
res.profit_orders = { ticks.value() };
}
//
// trade accumulation
auto trade_acc = get_if<bool>(params, "Trade Accumulation").value_or(false);
if (trade_acc) {
TradeAccumulationParams tap;
auto contracts = get_if<uint32_t>(params, "Trade Contracts");
if (!contracts) return bad_definition("Missing 'Trade Accumulation # Contracts'");
tap.contracts = contracts.value();
auto interval = get_if<uint32_t>(params, "Trade Interval (seconds)");
if (!interval) return bad_definition("Missing 'Trade Accumulation Interval'");
tap.seconds = interval.value();
auto sleep = get_if<uint32_t>(params, "Trade Sleep (seconds)");
if (!sleep) return bad_definition("Missing 'Trade Accumulation Sleep'");
tap.sleep_seconds = sleep.value();
res.trade_accumulation = {tap};
}
return {res};
}
extern "C" void init_dorman_plugin(bts::SparkServices &srv) {
DynamicOrderDescriptor join_desc;
join_desc.set_dynamic_order_type("Dorman");
*join_desc.add_param_desc() = param_array("what", param_double("").param_type());
*join_desc.add_param_desc() = param_uint32("Market Quantity 1");
*join_desc.add_param_desc() = param_uint32("Order Quantity 1");
*join_desc.add_param_desc() = param_uint32("Market Quantity 2");
*join_desc.add_param_desc() = param_uint32("Order Quantity 2");
*join_desc.add_param_desc() = param_uint32("Market Quantity 3");
*join_desc.add_param_desc() = param_uint32("Order Quantity 3");
*join_desc.add_param_desc() = param_uint32("Market Quantity 4");
*join_desc.add_param_desc() = param_uint32("Order Quantity 4");
*join_desc.add_param_desc() = param_uint32("Market Quantity 5");
*join_desc.add_param_desc() = param_uint32("Order Quantity 5");
*join_desc.add_param_desc() = param_uint32("Max Size");
*join_desc.add_param_desc() = param_uint32("Trail Seconds");
*join_desc.add_param_desc() = param_uint32("Clip Size");
*join_desc.add_param_desc() = param_bool("Enable Scratch");
*join_desc.add_param_desc() = param_uint32("Max Overfill");
*join_desc.add_param_desc() = param_bool("Profit Orders");
*join_desc.add_param_desc() = param_uint32("Ticks Away");
*join_desc.add_param_desc() = param_bool("Trade Accumulation");
*join_desc.add_param_desc() = param_uint32("Trade Contracts");
*join_desc.add_param_desc() = param_uint32("Trade Interval (seconds)");
*join_desc.add_param_desc() = param_uint32("Trade Sleep (seconds)");
srv.register_dynamic_algo_order(join_desc, []() { return std::make_unique<DormanAlgo>(); });
}
extern "C" void init_pyramid_plugin(bts::SparkServices& srv) {
DynamicOrderDescriptor join_desc;
join_desc.set_dynamic_order_type("Pyramid");
*join_desc.add_param_desc() = param_security_key("Top Spread");
*join_desc.add_param_desc() = param_uint32("Delete");
*join_desc.add_param_desc() = param_security_key("Spread 1");
*join_desc.add_param_desc() = param_uint32("Spread 1 Payup");
*join_desc.add_param_desc() = param_order("Spread 1 Order");
*join_desc.add_param_desc() = param_security_key("Spread 2");
*join_desc.add_param_desc() = param_uint32("Spread 2 Payup");
*join_desc.add_param_desc() = param_order("Spread 2 Order");
*join_desc.add_param_desc() = param_security_key("Spread 3");
*join_desc.add_param_desc() = param_uint32("Spread 3 Payup");
*join_desc.add_param_desc() = param_order("Spread 3 Order");
*join_desc.add_param_desc() = param_security_key("Spread 4");
*join_desc.add_param_desc() = param_uint32("Spread 4 Payup");
*join_desc.add_param_desc() = param_order("Spread 4 Order");
*join_desc.add_param_desc() = param_security_key("Spread 5");
*join_desc.add_param_desc() = param_uint32("Spread 5 Payup");
*join_desc.add_param_desc() = param_order("Spread 5 Order");
srv.register_dynamic_algo_order(join_desc, []() { return std::make_unique<orderman::PyramidAlgo>(); });
}
extern "C" void init_tascounter_plugin(bts::SparkServices& srv) {
DynamicOrderDescriptor join_desc;
join_desc.set_dynamic_order_type("TASCounter");
// all 6 contracts. They can theoretically be inferred from the front month
// since T1 are calendars 1 month apart starting from the front month
// ex Mar-May, May-Jul, Jul-Sep being T1 front, second and third respectively
// (assuming Mar is the front month)
*join_desc.add_param_desc() = param_security_key("T1 Front");
*join_desc.add_param_desc() = param_security_key("T1 Second");
*join_desc.add_param_desc() = param_security_key("T1 Third");
*join_desc.add_param_desc() = param_security_key("T2 Front");
*join_desc.add_param_desc() = param_security_key("T2 Second");
*join_desc.add_param_desc() = param_security_key("T3 Front");
// tas contracts (could have been derived)
*join_desc.add_param_desc() = param_security_key("T1 Front TAS");
*join_desc.add_param_desc() = param_security_key("T1 Second TAS");
*join_desc.add_param_desc() = param_security_key("T1 Third TAS");
// automatic orders
*join_desc.add_param_desc() = param_uint32("T1 Front Time");
*join_desc.add_param_desc() = param_uint32("T1 Front Qty");
*join_desc.add_param_desc() = param_bool("T1 Front Order Enabled");
*join_desc.add_param_desc() = param_uint32("T1 Second Time");
*join_desc.add_param_desc() = param_uint32("T1 Second Qty");
*join_desc.add_param_desc() = param_bool("T1 Second Order Enabled");
*join_desc.add_param_desc() = param_uint32("T1 Third Time");
*join_desc.add_param_desc() = param_uint32("T1 Third Qty");
*join_desc.add_param_desc() = param_bool("T1 Third Order Enabled");
// settlement time
*join_desc.add_param_desc() = param_uint32("Settlement Start Hour");
*join_desc.add_param_desc() = param_uint32("Settlement Start Minutes");
*join_desc.add_param_desc() = param_uint32("Settlement Start Seconds");
*join_desc.add_param_desc() = param_uint32("Settlement Period (seconds)");
srv.register_dynamic_algo_order(join_desc, []() { return std::make_unique<orderman::TASCounterAlgo>(); });
}
extern "C" void init_tas_plugin(bts::SparkServices& srv) {
DynamicOrderDescriptor tas_desc;
tas_desc.set_dynamic_order_type("TAS");
size_t n_child_ords = 8;
for (size_t i=0; i< n_child_ords; i++){
auto idx = std::to_string(i+1);
*tas_desc.add_param_desc() = param_double("Order " + idx + " Price");
*tas_desc.add_param_desc() = param_uint32("Order " + idx + " Quantity");
*tas_desc.add_param_desc() = param_bool("Order " + idx + " Buy?");
}
srv.register_dynamic_algo_order(tas_desc, []() { return std::make_unique<orderman::TASAlgo>(); });
}
extern "C" void init_limit_cover(bts::SparkServices & srv) {
DynamicOrderDescriptor lc_desc;
lc_desc.set_dynamic_order_type("LimitCover");
LimitCoverAdapter::define_proto(lc_desc);
srv.register_dynamic_algo_order(lc_desc, []() { return std::make_unique<orderman::LimitCoverAlgo>(); });
}
extern "C" void init_on_signal_plugin(bts::SparkServices& srv) {
DynamicOrderDescriptor on_signal;
on_signal.set_dynamic_order_type("OnSignal");
*on_signal.add_param_desc() = param_uint32("Time Hours");
*on_signal.add_param_desc() = param_uint32("Time Minutes");
*on_signal.add_param_desc() = param_uint32("Time Seconds");
*on_signal.add_param_desc() = param_bool("Preopen");
*on_signal.add_param_desc() = param_bool("Open");
// contracts who's signals have to be received to send the algo
*on_signal.add_param_desc() = param_security_key("Signal Contract 1");
size_t n_child_ords = 10;
for (size_t i=0; i< n_child_ords; i++){
auto idx = std::to_string(i+1);
*on_signal.add_param_desc() = param_security_key("Order " + idx + " Contract");
*on_signal.add_param_desc() = param_order("Order " + idx);
*on_signal.add_param_desc() = param_double("Order " + idx + " Price");
*on_signal.add_param_desc() = param_int32("Order " + idx + " Quantity");
}
srv.register_dynamic_algo_order(on_signal, []() { return std::make_unique<orderman::OnSignalAlgo>(); });
}
extern "C" void init_spark_plugin(bts::SparkServices &srv) {
auto& dyn_algo_config = config::get<config::toggles::DynamicAlgos>();
if(dyn_algo_config.enable_dorman())
init_dorman_plugin(srv);
if(dyn_algo_config.enable_pyramid())
init_pyramid_plugin(srv);
if(dyn_algo_config.enable_tas())
init_tas_plugin(srv);
if(dyn_algo_config.enable_tascounter())
init_tascounter_plugin(srv);
if (dyn_algo_config.enable_limit_cover())
init_limit_cover(srv);
if (dyn_algo_config.enable_onsignal())
init_on_signal_plugin(srv);
}
}}}
@@ -1,222 +0,0 @@
#include "lib/orderman/orders/algo/algo_orders/TASAlgo.h"
#include "lib/domain_model/Security.h"
#include "lib/orderman/order_factory/IOrderFactory.h"
#include "lib/orderman/orderman_utils/Book.h"
#include "lib/orderman/orderman_utils/orderman_utils.h"
#include "lib/orderman/orders/algo/IAlgoServices.h"
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
#include "lib/os/os.h"
#include "lib/domain_model/Security.h"
#include "lib/utils/PBUtils.h"
#include "lib/utils/datetime.h"
#include <stdint.h>
namespace bts {
namespace orderman {
using namespace api::orderman;
enum class TASAlgo::Status { WAITING_FOR_SIGNAL, WORKING, DONE };
struct TASLegData{
api::Side side; //trading side
Price price;
Quantity quantity;
ChildTemplate* order_template = nullptr;
OrderKey order_key;
ChildState order_state;
TASLegData (api::Side side,
Price price,
Quantity quantity,
ChildTemplate* order_template)
:
side (side),
price(price),
quantity(quantity),
order_template (order_template),
order_key(null_order_key()),
order_state(){
order_state.status = ChildStatus::WORKING;
}
};
struct TASAlgo::PImpl {
Status state = Status::WAITING_FOR_SIGNAL;
IAlgoServices* algo_services = nullptr;
SecurityKey sec_key = SecurityKey(0);
TASAlgo::TASAlgoParams algo_params;
std::vector<TASLegData> legs;
bts::datetime::PTime start_time = bts::datetime::local_now();
PImpl(){
}
TASLegData* find_leg_from_ord_key (OrderKey ord_key){
for (auto& l : legs)
if(l.order_key == ord_key)
return &l;
return nullptr;
}
};
TASAlgo::TASAlgo() : me(new PImpl()) {}
TASAlgo::~TASAlgo() {}
// initialization /////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
OrderOpResult TASAlgo::do_before_launch(IBeforeLaunchAlgoServices& serv) {
auto& def = serv.definition();
if (def.has_custom_def() && def.custom_def().has_dynamic()){
const auto& sec = serv.security();
me->sec_key = SecurityKey(sec.id());
me->algo_params = _convert_params(def.custom_def());
if (me->algo_params.child_orders.size() > 0){
for (const auto& t : me->algo_params.child_orders){
Price price = std::get<0>(t);
Quantity quantity = std::get<1>(t);
api::Side side = std::get<2>(t);
auto* ordt = _create_order_template(
serv,
SecurityKey(sec.id()),
side);
me->legs.emplace_back(side,
price,
quantity,
ordt);
}
return {};
}
}
return {OrderError::ORDER_ERROR_INVALID_PARAMETER,
std::string("Parameters are not well formed")};
}
void TASAlgo::do_launch(IAlgoServices& algo_services) {
me->algo_services = &algo_services;
_algo().subscribe_status(me->sec_key);
//_algo().subscribe_timer();
}
void TASAlgo::do_launch_attached(IAlgoServices& algo_services,
OrderKey,
ChildState) {
me->algo_services = &algo_services;
_cxl_and_end(true, "TAS Algo can not be attached to working orders");
}
// updates ////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void TASAlgo::do_update(const api::orderman::Update&) {
LOG(OrderMan, Warn, "TASAlgo::do_update order:{} state:{} update not allowed ",
_algo().order_key().value(),
static_cast<int>(me->state));
}
// callbacks //////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void TASAlgo::on_book(SecurityKey, const Book&) {
}
void TASAlgo::on_child_change(OrderKey key,
ChildState const &st){
LOG(OrderMan, Info,
"TASAlgo::on_child_change key:{} child_key:{} state:{} status:{} "
"total_fills:{} last_price:{}",
_algo().order_key(),
key,
static_cast<int>(me->state),
static_cast<int>(st.status),
st.total_fills,
st.last_price);
TASLegData* ld_ptr = me->find_leg_from_ord_key(key);
if (ld_ptr != nullptr)
ld_ptr->order_state = st;
for (const auto& l : me->legs)
if(l.order_state.status == ChildStatus::WORKING)
return;
_cxl_and_end(false,"");
}
void TASAlgo::on_status(SecurityKey key, co2::TradingStatus status){
if(key == me->sec_key &&
status == co2::TradingStatus::TRADINGSTATUS_PRE_OPEN){
switch (me->state){
case TASAlgo::Status::WAITING_FOR_SIGNAL:
for (auto& l : me->legs){
l.order_key = _algo().launch_child(
*l.order_template,
l.price,
l.quantity);
LOG(OrderMan, Info,"TASAlgo::on_status launching order key:{} "
"child_key:{} price:{} qty:{}",
_algo().order_key(),
l.order_key,
l.price,
l.quantity);
}
_switch_state(TASAlgo::Status::WORKING);
break;
case TASAlgo::Status::WORKING:
case TASAlgo::Status::DONE:
break;
}
}
}
void TASAlgo::on_timer(){
if (bts::datetime::msecs_since(me->start_time) > 10000)
on_status(me->sec_key,co2::TradingStatus::TRADINGSTATUS_PRE_OPEN);
}
IAlgoServices& TASAlgo::_algo() const { return *me->algo_services; }
///////////////////////////////////////////////////////////////////////////////
// stateless conversion ///////////////////////////////////////////////////////
TASAlgo::TASAlgoParams TASAlgo::_convert_params (
const bts::api::orderman::CustomOrderDefinition& cod){
const DynamicOrderDefinition& def = cod.dynamic();
const auto& params = def.order_params();
TASAlgo::TASAlgoParams rv;
for (size_t i = 0; i < 1024; i++){
auto idx = std::to_string(i+1);
auto price = get_if<double>(params, "Order " + idx + " Price");
auto qty = get_if<uint32_t>(params, "Order " + idx + " Quantity");
auto is_buy = get_if<bool>(params, "Order " + idx + " Buy?");
if(price.has_value() && qty.has_value() && qty.value() != 0){
api::Side side = is_buy.has_value() ?
(is_buy.value() ? api::Side::SIDE_BUY : api::Side::SIDE_SELL) :
api::Side::SIDE_SELL;
rv.child_orders.emplace_back(Price(price.value()), Quantity(qty.value()), side);
}
}
return rv;
}
ChildTemplate* TASAlgo::_create_order_template (
IBeforeLaunchAlgoServices& serv,
SecurityKey key,
api::Side side){
OrderDefinition order_def = serv.definition();
order_def.set_security_key (key.value());
order_def.set_side(side);
order_def.mutable_custom_def()->mutable_limit()->MergeFrom (
api::orderman::LimitOrderDefinition());
return &(serv.make_child_template(order_def));
}
void TASAlgo::_switch_state(TASAlgo::Status new_state){
switch (new_state){
case (TASAlgo::Status::WAITING_FOR_SIGNAL):
bts_assert(false);
break;
case (TASAlgo::Status::WORKING):
bts_assert(me->state == TASAlgo::Status::WAITING_FOR_SIGNAL);
break;
case (TASAlgo::Status::DONE):
bts_assert(me->state != TASAlgo::Status::DONE);
break;
}
LOG(OrderMan, Info,"TASAlgo::_switch_state key:{} {}->{} ",
_algo().order_key(),
static_cast<int>(me->state),
static_cast<int>(new_state));
me->state = new_state;
}
void TASAlgo::_cxl_and_end (bool is_error, const std::string& err_msg){
if(is_error)
_algo().terminate_error(err_msg);
else
_algo().complete();
_switch_state(TASAlgo::Status::DONE);
}
} // namespace orderman
} // namespace bts
@@ -1,45 +0,0 @@
#pragma once
#include "lib/orderman/orders/algo/IAlgoOrder.h"
namespace bts {
namespace orderman {
class ChildTemplate;
struct LegData;
class TASAlgo : public IAlgoOrder {
public:
TASAlgo();
~TASAlgo();
struct TASAlgoParams{
std::vector<std::tuple<Price, Quantity, api::Side>> child_orders;
};
public:
OrderOpResult do_before_launch(IBeforeLaunchAlgoServices &) override;
void do_launch(IAlgoServices &) override;
void do_launch_attached(IAlgoServices &, OrderKey, ChildState) override;
void do_update(api::orderman::Update const &) override;
void on_book(SecurityKey, Book const &) override;
void on_child_change(OrderKey, ChildState const &) override;
void on_status(SecurityKey, co2::TradingStatus) override;
void on_timer() override;
private:
enum class Status;
struct PImpl;
std::unique_ptr<PImpl> me;
private:
IAlgoServices& _algo() const ;
static TASAlgoParams _convert_params (
const bts::api::orderman::CustomOrderDefinition&);
static ChildTemplate* _create_order_template (IBeforeLaunchAlgoServices&,
SecurityKey,
api::Side);
// acts on md, cognizant of the state
void _switch_state (Status new_status);
void _cxl_and_end (bool is_error, const std::string& err_msg);
};
} // namespace orderman
} // namespace bts
@@ -1,490 +0,0 @@
#include "lib/orderman/orders/algo/algo_orders/TASCounterAlgo.h"
#include "lib/domain_model/Security.h"
#include "lib/orderman/order_factory/IOrderFactory.h"
#include "lib/orderman/orderman_utils/Book.h"
#include "lib/orderman/orderman_utils/orderman_utils.h"
#include "lib/orderman/orders/algo/IAlgoServices.h"
#include "lib/orderman/orders/spreader_orders/spreader/SpreaderUtils.h"
#include "lib/os/os.h"
#include "lib/domain_model/Security.h"
#include "lib/utils/PBUtils.h"
#include "lib/utils/datetime.h"
#include <google/protobuf/timestamp.pb.h>
#include "lib/orderman/actors/SODPosition.h"
#include <google/protobuf/util/time_util.h>
#include <stdint.h>
namespace bts {
namespace orderman {
using namespace api::orderman;
using namespace google::protobuf;
enum class TASCounterAlgo::Status { WORKING, DONE };
// book and trade data for each of the 6 contracts as well as the TAS contracts
// (the vwap of the TAS contracts is not used, but for uniformity is kept in the
// the same structure)
struct ContractMarketData{
uint32_t tot_vol = 0;
double running_sum = 0;
Book book;
double estimated_settle = 0.0;
void on_trade (const TickerUpdateEvent::Trade& t){
tot_vol += t.quantity.value();
running_sum += t.price.value()*t.quantity.value();
}
const double vwap(){
return tot_vol == 0 ? os::nan() : running_sum/tot_vol;
}
};
// the input for the t1 front, second and third orders, as well as the template
// and working order key are kept here
struct ContractAutoOrder{
// inputs
uint32_t n_secs = 0;
uint32_t qty = 0;
bool enabled = false;
// dont know yet which side will be sent
ChildTemplate* buy_ord = nullptr;
ChildTemplate* sell_ord = nullptr;
// computed input
// the is AlgoData::settle_stop - n_secs
Timestamp algo_start;
// output
std::optional<OrderKey> tas_order = std::nullopt;
};
struct AlgoData{
double tick_size;
Timestamp settle_start;
Timestamp settle_stop;
ContractMarketData t1_front,
t1_second,
t1_third,
t2_front,
t2_second,
t3_front;
ContractMarketData t1_front_tas,
t1_second_tas,
t1_third_tas;
ContractAutoOrder t1_front_order,
t1_second_order,
t1_third_order;
DynamicOrderState out_state;
};
struct TASCounterAlgo::PImpl {
// reporting
uint16_t reporting_period_msecs = 500;
bts::datetime::PTime last_report_time = bts::datetime::now();
// immutable state
IAlgoServices* algo_services = nullptr;
// mutable state
AlgoData data;
// to avoid lookups on md and ticker callbacks
std::map<SecurityKey,ContractMarketData*> md_map;
Status state = Status::WORKING;
};
//fwd decls
void _copy_output(AlgoData&);
bool _copy_settle_times (AlgoData&,const Map<std::string,DynamicOrderParam>&);
void _copy_order_data (AlgoData&,const Map<std::string,DynamicOrderParam>&);
bool _setup_data(IBeforeLaunchAlgoServices&, AlgoData&,
std::map<SecurityKey,ContractMarketData*>&);
double round_to_nearest(double price, double tick_size);
long long t1_minus_t2_usecs (const Timestamp&, const Timestamp&);
long long t_minus_now_usecs (const google::protobuf::Timestamp&);
bool trade_within_time_win (const Timestamp&, const Timestamp&,
const TickerUpdateEvent::Trade& t);
bool now_within_time_win (const Timestamp&, const Timestamp&);
TASCounterAlgo::TASCounterAlgo() : me(new PImpl()) {}
TASCounterAlgo::~TASCounterAlgo() {}
// initialization /////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
OrderOpResult TASCounterAlgo::do_before_launch(IBeforeLaunchAlgoServices& serv) {
if(_setup_data(serv,me->data,me->md_map))
return {};
return {OrderError::ORDER_ERROR_INVALID_PARAMETER,
std::string("Parameters are not well formed")};
}
void TASCounterAlgo::do_launch(IAlgoServices& algo_services) {
me->algo_services = &algo_services;
algo_services.subscribe_timer();
for (const auto& kp : me->md_map){
algo_services.subscribe_book(kp.first);
algo_services.subscribe_ticker(kp.first);
}
}
void TASCounterAlgo::do_launch_attached(
IAlgoServices& algo_services,
OrderKey,
ChildState) {
// not allowed
me->algo_services = &algo_services;
}
// updates ////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void TASCounterAlgo::do_update(const api::orderman::Update& u) {
if(me->state == Status::DONE)
return;
const auto& p = u.custom().dynamic().order_params();
// only order data change is allowed
_copy_order_data(me->data,p);
_check_and_send_order();
}
// callbacks //////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void TASCounterAlgo::on_book(SecurityKey k, const Book& b) {
if(me->state == Status::DONE)
return;
const auto& it = me->md_map.find(k);
if(it != me->md_map.end()){
it->second->book = b;
_check_and_send_order();
}
}
void TASCounterAlgo::on_ticker(SecurityKey k, const TradeVector& v){
if(me->state == Status::DONE)
return;
const auto& it = me->md_map.find(k);
if(it != me->md_map.end()){
auto contract_md = it->second;
for (const auto& t : v)
if (_within_settle()){
contract_md->on_trade(t);
}
_check_and_send_order();
}
}
// this only gets called on an explicit algo cancel
// from the outside
TASCounterAlgo::OnCancelResponse TASCounterAlgo::on_cancel(){
return IAlgoOrder::OnCancelResponse::HONOR;
}
void TASCounterAlgo::on_timer(){
if(me->state == Status::DONE)
return;
_check_and_send_order();
if(bts::datetime::msecs_since(me->last_report_time) >=
me->reporting_period_msecs){
me->last_report_time = bts::datetime::now();
_report_state();
}
// check for end and exit
if (t1_minus_t2_usecs(util::TimeUtil::GetCurrentTime(),
me->data.settle_stop) > 0){
std::string msg = "session over";
_cxl_and_end(false,msg);
}
}
IAlgoServices& TASCounterAlgo::_algo() const { return *me->algo_services; }
void TASCounterAlgo::_switch_state(TASCounterAlgo::Status new_state){
switch (new_state){
case (TASCounterAlgo::Status::WORKING):
bts_assert(false);
break;
case (TASCounterAlgo::Status::DONE):
bts_assert(me->state == TASCounterAlgo::Status::WORKING);
break;
}
LOG(OrderMan, Info,"TASCounterAlgo::_switch_state key:{} {}->{} ",
_algo().order_key(),
static_cast<int>(me->state),
static_cast<int>(new_state));
me->state = new_state;
}
void TASCounterAlgo::_cxl_and_end (bool is_error, const std::string& err_msg){
if(me->state == Status::DONE)
return;
if(is_error)
_algo().terminate_error(err_msg);
else
_algo().complete();
_switch_state(TASCounterAlgo::Status::DONE);
}
void TASCounterAlgo::_compute_settles(){
AlgoData& d = me->data;
d.t1_front.estimated_settle = d.t1_front.vwap();
d.t1_second.estimated_settle = d.t2_front.vwap() - d.t1_front.vwap();
d.t1_third.estimated_settle = d.t3_front.vwap() - d.t1_front.vwap() -
d.t1_second.vwap();
// round to closest value
d.t1_front.estimated_settle = round_to_nearest(
d.t1_front.estimated_settle,me->data.tick_size);
d.t1_second.estimated_settle = round_to_nearest(
d.t1_second.estimated_settle,me->data.tick_size);
d.t1_third.estimated_settle = round_to_nearest(
d.t1_third.estimated_settle,me->data.tick_size);
}
// the decision to send an order can be caused by
// 1. change in settings (=> time window, enabling orders etc)
// 2. book update (=> TAS book can result in order)
// 3. ticker (=> new estimated settlement)
// 4. time passing (=> in the window now)
void TASCounterAlgo::_check_and_send_order(){
_compute_settles();
auto should_send_tas_order =
[](const ContractMarketData& c,
const ContractAutoOrder& o,
const ContractMarketData& tas_c,
bool is_buy,
double& out_price,
uint32_t& out_qty) -> bool {
// buying the tas at the offer or selling it at the bid
const auto& tas_opp_top = is_buy ? tas_c.book.ask()[0] : tas_c.book.bid()[0];
const auto& c_same_top = is_buy ? c.book.bid()[0] : c.book.ask()[0];
if(tas_opp_top.size() > 0 && c_same_top.size() > 0){
// delivery price as defined by where the TAS order is traded
double tas_delv_price = c.estimated_settle + tas_opp_top.price();
// if the delv price for the buy order is <= contract bid or
// or the delv price for the sell order is >= contract offer
// then we are buying at the bid or selling at the offer
double c_price = c_same_top.price();
if((is_buy && tas_delv_price <= c_price) ||
(!is_buy && tas_delv_price >= c_price)){
out_qty = std::min(o.qty,tas_opp_top.size());
out_price = tas_opp_top.price();
return true;
}
}
return false;
};
auto _send_order_tn = [&](
const ContractMarketData& c,
ContractAutoOrder& o,
const ContractMarketData& tas_c) -> void {
if(o.enabled && o.n_secs > 0 && o.qty > 0 &&
!o.tas_order.has_value() &&
now_within_time_win(o.algo_start,me->data.settle_stop)){
double price;
uint32_t qty;
if(should_send_tas_order(c,o,tas_c,true,price,qty)){
o.tas_order = _algo().launch_child(*o.buy_ord,
Price(price),
Quantity(qty));
}
else if(should_send_tas_order(c,o,tas_c,false,price,qty)){
o.tas_order = _algo().launch_child(*o.sell_ord,
Price(price),
Quantity(qty));
}
}
};
_send_order_tn(me->data.t1_front,me->data.t1_front_order,me->data.t1_front_tas);
_send_order_tn(me->data.t1_second,me->data.t1_second_order,me->data.t1_second_tas);
_send_order_tn(me->data.t1_third,me->data.t1_third_order,me->data.t1_third_tas);
}
void TASCounterAlgo::_report_state(){
_compute_settles();
_copy_output(me->data);
_algo().update_custom_state(me->data.out_state);
}
bool TASCounterAlgo::_within_settle() const{
return now_within_time_win(me->data.settle_start,me->data.settle_stop);
}
///////////////////////////////////////////////////////////////////////////////
// stateless conversion ///////////////////////////////////////////////////////
// stateless helpers
ChildTemplate* _create_order_template (IBeforeLaunchAlgoServices& serv,
SecurityKey key,
api::Side side){
OrderDefinition order_def = serv.definition();
order_def.set_security_key (key.value());
order_def.set_side(side);
order_def.mutable_custom_def()->mutable_limit()->MergeFrom (
api::orderman::LimitOrderDefinition());
return &(serv.make_child_template(order_def));
}
// copies output into the dynamic state for publishing
void _copy_output(AlgoData& d){
auto& m = *(d.out_state.mutable_custom_state());
// we can safely assume its within int32
auto secs_to_settle = static_cast<int>(t_minus_now_usecs(d.settle_start)/1000000);
// if its in settle (-ve value), its set to 0
secs_to_settle = std::max(secs_to_settle,0);
m["Seconds To Settle"].set_as_int32(secs_to_settle);
m["VWAP T1-Front"].set_as_double(d.t1_front.vwap());
m["VWAP T1-Second"].set_as_double(d.t1_second.vwap());
m["VWAP T1-Third"].set_as_double(d.t1_third.vwap());
m["VWAP T2-Front"].set_as_double(d.t2_front.vwap());
m["VWAP T2-Second"].set_as_double(d.t2_second.vwap());
m["VWAP T3-Front"].set_as_double(d.t3_front.vwap());
m["T1-Front Projected Settle"].set_as_double(d.t1_front.estimated_settle);
m["T1-Second Projected Settle"].set_as_double(d.t1_second.estimated_settle);
m["T1-Third Projected Settle"].set_as_double(d.t1_third.estimated_settle);
}
// copies the settle time/period part of the input data
bool _copy_settle_times (AlgoData& d,
const Map<std::string,DynamicOrderParam>& params){
auto hh = get_if<uint32_t>(params, "Settlement Start Hour");
auto mm = get_if<uint32_t>(params, "Settlement Start Minutes");
auto ss = get_if<uint32_t>(params, "Settlement Start Seconds");
auto settle_period_secs = get_if<uint32_t>(params, "Settlement Period (seconds)");
if (hh.has_value() && mm.has_value() &&
ss.has_value() && settle_period_secs.has_value() &&
hh.value() <= 23 && mm.value() <= 59 && ss.value() <= 59){
d.settle_start = SODPosition::today_local_time_to_utc_timestamp(
hh.value(),
mm.value(),
ss.value(),
true,
false);
d.settle_stop = SODPosition::add_seconds(d.settle_start,
settle_period_secs.value());
auto settle_start_txt = util::TimeUtil::ToString(d.settle_start);
auto settle_stop_txt = util::TimeUtil::ToString(d.settle_stop);
LOG(OrderMan, Info, "TASCounterAlgo::_copy_settle_times "
"settle_start:{} settle_stop:{} ",
settle_start_txt,
settle_stop_txt);
return true;
}
return false;
}
// copies the order execution part of the input data
void _copy_order_data (AlgoData& out_d,
const Map<std::string,DynamicOrderParam>& params){
auto copy_o = [&](ContractAutoOrder& out_order,
std::string time_name,
std::string qty_name,
std::string enabled_name
) -> bool {
out_order.enabled = false;
auto time = get_if<uint32_t>(params, time_name);
auto qty = get_if<uint32_t>(params, qty_name);
auto enabled = get_if<bool>(params, enabled_name);
if(time.has_value() && qty.has_value() && enabled.has_value()){
out_order.n_secs = time.value();
out_order.qty = qty.value();
out_order.enabled = enabled.value();
out_order.algo_start = SODPosition::add_seconds(out_d.settle_stop,
-1 * out_order.n_secs);
return true;
}
return false;
};
copy_o(out_d.t1_front_order,
"T1 Front Time",
"T1 Front Qty",
"T1 Front Order Enabled");
copy_o(out_d.t1_second_order,
"T1 Second Time",
"T1 Second Qty",
"T1 Second Order Enabled");
copy_o(out_d.t1_third_order,
"T1 Third Time",
"T1 Third Qty",
"T1 Third Order Enabled");
}
// copies all of the input params (in the algo) into proper structures
bool _setup_data(IBeforeLaunchAlgoServices& serv,
AlgoData& out_d,
std::map<SecurityKey,ContractMarketData*>& out_md_map){
auto& def = serv.definition();
// [ captures ] (parameters) -> returnTypesDeclaration { lambdaStatements; }
auto init_contract_bk = [&out_md_map](auto& out_contract_md,
const auto& params,
auto param_name) -> void {
auto k = get_if<uint32_t>(params, param_name);
if(k.has_value()){
out_contract_md.book = Book(SecurityKey(k.value()));
out_md_map[out_contract_md.book.security_key()] = &out_contract_md;
}
};
if (def.has_custom_def() && def.custom_def().has_dynamic()){
out_d.tick_size = serv.security().contract_spec().low_tick();
const auto& p = def.custom_def().dynamic().order_params();
// settlement time
if(!_copy_settle_times(out_d,p))
return false;
// main contracts
init_contract_bk(out_d.t1_front, p,"T1 Front");
init_contract_bk(out_d.t1_second, p,"T1 Second");
init_contract_bk(out_d.t1_third, p,"T1 Third");
init_contract_bk(out_d.t2_front, p,"T2 Front");
init_contract_bk(out_d.t2_second, p,"T2 Second");
init_contract_bk(out_d.t3_front, p,"T3 Front");
// TAS contracts
init_contract_bk(out_d.t1_front_tas, p,"T1 Front TAS");
init_contract_bk(out_d.t1_second_tas, p,"T1 Second TAS");
init_contract_bk(out_d.t1_third_tas, p,"T1 Third TAS");
// auto orders
_copy_order_data(out_d,p);
// order template
out_d.t1_front_order.buy_ord = _create_order_template(serv,
out_d.t1_front_tas.book.security_key(),api::Side::SIDE_BUY);
out_d.t1_front_order.sell_ord = _create_order_template(serv,
out_d.t1_front_tas.book.security_key(),api::Side::SIDE_SELL);
out_d.t1_second_order.buy_ord = _create_order_template(serv,
out_d.t1_second_tas.book.security_key(),api::Side::SIDE_BUY);
out_d.t1_second_order.sell_ord = _create_order_template(serv,
out_d.t1_second_tas.book.security_key(),api::Side::SIDE_SELL);
out_d.t1_third_order.buy_ord = _create_order_template(serv,
out_d.t1_third_tas.book.security_key(),api::Side::SIDE_BUY);
out_d.t1_third_order.sell_ord = _create_order_template(serv,
out_d.t1_third_tas.book.security_key(),api::Side::SIDE_SELL);
return true;
}
return false;
}
double round_to_nearest(double price, double tick_size){
if(os::is_nan(price))
return price;
auto buy_price = bts::securities::raw_round_to_quote_price(
price,
tick_size,
api::Side::SIDE_BUY);
auto sell_price = buy_price + tick_size;
return std::abs(price-buy_price) < std::abs(sell_price-price) ? buy_price :
sell_price;
}
// time helpers
// converts std::chrono::system_clock::time_point to google timestamp
google::protobuf::Timestamp to_pf_ts (const bts::TimeStamp& ts){
auto ts_us = std::chrono::time_point_cast<std::chrono::microseconds>(ts);
auto ts_us_val = ts_us.time_since_epoch();
auto usecs = ts_us_val.count();
return google::protobuf::util::TimeUtil::MicrosecondsToTimestamp(usecs);
}
long long t1_minus_t2_usecs (const Timestamp& t1,const Timestamp& t2){
return util::TimeUtil::TimestampToMicroseconds(t1) -
util::TimeUtil::TimestampToMicroseconds(t2);
}
long long t_minus_now_usecs (const Timestamp& t){
auto now = util::TimeUtil::GetCurrentTime();
return t1_minus_t2_usecs(t,now);
}
bool within_time_win (const Timestamp& beg, const Timestamp& end,
const Timestamp& ts){
return t1_minus_t2_usecs(ts,beg)>=0 &&
t1_minus_t2_usecs(ts,end)<=0;
}
// if current time is within time window
bool now_within_time_win (const Timestamp& beg,
const Timestamp& end){
return within_time_win(beg,end,util::TimeUtil::GetCurrentTime());
}
bool trade_within_time_win (const Timestamp& beg, const Timestamp& end,
const TickerUpdateEvent::Trade& t){
auto ts = to_pf_ts(t.ts);
return within_time_win(beg,end,ts);
}
} // namespace orderman
} // namespace bts
@@ -1,41 +0,0 @@
#pragma once
#include "lib/orderman/orders/algo/IAlgoOrder.h"
namespace bts {
namespace orderman {
class ChildTemplate;
class TASCounterAlgo : public IAlgoOrder {
public:
TASCounterAlgo();
~TASCounterAlgo();
struct TASCounterAlgoParams{
};
public:
OrderOpResult do_before_launch(IBeforeLaunchAlgoServices &) override;
void do_launch(IAlgoServices &) override;
void do_launch_attached(IAlgoServices &, OrderKey, ChildState) override;
void do_update(api::orderman::Update const &) override;
void on_book(SecurityKey, Book const &) override;
void on_ticker(SecurityKey, TradeVector const&) override;
IAlgoOrder::OnCancelResponse on_cancel() override;
void on_timer() override;
private:
enum class Status;
struct PImpl;
std::unique_ptr<PImpl> me;
private:
IAlgoServices& _algo() const ;
void _switch_state (Status new_status);
void _cxl_and_end (bool is_error, const std::string& err_msg);
void _check_and_send_order();
void _compute_settles ();
void _report_state();
bool _within_settle() const;
};
} // namespace orderman
} // namespace bts
@@ -1,152 +0,0 @@
#include "lib/orderman/orders/algo/algo_orders/limit_cover/LimitCoverAdapter.h"
#include "lib/orderman/orders/OrderOpResult.h"
#include "lib/orderman/orders/algo/utils/DynamicOrderAdapter.h"
#include <utility>
namespace bts {
namespace orderman {
template<typename T>
using Param = bts::orderman::dynamic_adapter::ParamKey<bts::orderman::LimitCoverDefinition, T>;
using DynamicOrderEnumerated = bts::api::orderman::DynamicOrderEnumerated;
using OnToward = bts::api::orderman::LeanOnToward;
using LimitCoverDefinition = bts::orderman::LimitCoverDefinition;
using namespace bts::api::orderman;
#define ON_TOWARD_NAME_PAIR(x) std::make_pair(x, #x)
template<uint32_t gate_num>
std::string gate_param_name(std::string name) {
return Formatter::fmt("Gate ", gate_num, " ", name);
}
template<>
std::string gate_param_name<0>(std::string name) {
return Formatter::fmt("Initial ", name);
}
struct PriceOffset : public Param<double> {
PriceOffset() : Param<double>(std::string("Limit"),
[](const LimitCoverDefinition& def) { return def.price_offset(); },
[](LimitCoverDefinition& def, double v) { def.price_offset(v); }) {}
};
template<uint32_t gate_num>
struct ActivationThreshold : public Param<uint32_t> {
ActivationThreshold() : Param<uint32_t>(gate_param_name<gate_num>("Activation Threshold"),
[](const LimitCoverDefinition& def) { return def.gate(gate_num).activation_threshold(); },
[](LimitCoverDefinition& def, uint32_t v) { def.mgate(gate_num).activation_threshold(v); }) { }
};
template<uint32_t gate_num>
struct CoverThreshold : public Param<uint32_t> {
CoverThreshold() : Param<uint32_t>(gate_param_name<gate_num>("Cover Threshold"),
[](const LimitCoverDefinition& def) { return def.gate(gate_num).cover_threshold(); },
[](LimitCoverDefinition& def, uint32_t v) { def.mgate(gate_num).cover_threshold(v); }) { }
};
template<uint32_t gate_num>
struct DeleteThreshold : public Param<uint32_t> {
DeleteThreshold() : Param<uint32_t>(gate_param_name<gate_num>("Delete Threshold"),
[](const LimitCoverDefinition& def) { return def.gate(gate_num).delete_threshold(); },
[](LimitCoverDefinition& def, uint32_t v) { def.mgate(gate_num).delete_threshold(v); }) { }
};
template<uint32_t gate_num>
struct HedgeTicks : public Param<uint32_t> {
HedgeTicks() : Param<uint32_t>(gate_param_name<gate_num>("Hedge Ticks"),
[](const LimitCoverDefinition& def) { return def.gate(gate_num).hedge_ticks(); },
[](LimitCoverDefinition& def, uint32_t v) { def.mgate(gate_num).hedge_ticks(v); }) { }
};
template<uint32_t gate_num>
struct TopTicksOff : public Param<uint32_t> {
TopTicksOff() : Param<uint32_t>(gate_param_name<gate_num>("Top Ticks Offset"),
[](const LimitCoverDefinition& def) { return def.gate(gate_num).top_ticks_offset(); },
[](LimitCoverDefinition& def, uint32_t v) { def.mgate(gate_num).top_ticks_offset(v); }) { }
};
template<uint32_t gate_num>
struct MaxChaseTicks : public Param<uint32_t> {
MaxChaseTicks() : Param<uint32_t>(gate_param_name<gate_num>("Max Chase Ticks"),
[](const LimitCoverDefinition& def) { return def.gate(gate_num).max_chase_ticks(); },
[](LimitCoverDefinition& def, uint32_t v) { def.mgate(gate_num).max_chase_ticks(v); }) { }
};
template<uint32_t gate_num>
struct TradeTowardBehavior : public dynamic_adapter::EnumParamKey<LimitCoverDefinition, OnToward> {
TradeTowardBehavior() : EnumParamKey<LimitCoverDefinition, OnToward>(
gate_param_name<gate_num>("Trade Toward Behavior"), {
ON_TOWARD_NAME_PAIR(NO_CHANGE),
ON_TOWARD_NAME_PAIR(CANCEL),
ON_TOWARD_NAME_PAIR(DETACH),
ON_TOWARD_NAME_PAIR(REPRICE)
},
[](const LimitCoverDefinition& def) { return def.gate(gate_num).on_toward(); },
[](LimitCoverDefinition& def, OnToward v) { def.mgate(gate_num).on_toward(v); })
{}
};
template<>
struct ActivationThreshold<0> : public Param<uint32_t> {
ActivationThreshold() : Param<uint32_t>(std::string("Entry Threshold"),
[](const LimitCoverDefinition& def) { return def.gate(0).activation_threshold(); },
[](LimitCoverDefinition& def, uint32_t v) {
auto& g = def.mgate(0);
g.activation_threshold(v);
g.cover_threshold(v);
g.delete_threshold(v);
}) {}
};
using Adapter = dynamic_adapter::DynamicOrderAdapter<LimitCoverDefinition,
PriceOffset,
// [gate 0]
ActivationThreshold<0>,
HedgeTicks<0>,
TopTicksOff<0>,
MaxChaseTicks<0>,
TradeTowardBehavior<0>,
// gate 1
ActivationThreshold<1>,
CoverThreshold<1>,
DeleteThreshold<1>,
HedgeTicks<1>,
TopTicksOff<1>,
MaxChaseTicks<1>,
TradeTowardBehavior<1>,
// gate 2
ActivationThreshold<2>,
CoverThreshold<2>,
DeleteThreshold<2>,
HedgeTicks<2>,
TopTicksOff<2>,
MaxChaseTicks<2>,
TradeTowardBehavior<2>>;
LimitCoverDefinition LimitCoverAdapter::from_proto(const api::orderman::OrderDefinition& order) {
if (order.has_custom_def())
return from_proto(order.custom_def());
return LimitCoverDefinition();
}
LimitCoverDefinition LimitCoverAdapter::from_proto(const api::orderman::CustomOrderDefinition& custom_def) {
LimitCoverDefinition rv;
if (custom_def.has_dynamic())
Adapter().from_proto(custom_def.dynamic(), rv);
return rv;
}
#define INVALID_DEF(x) OrderOpResult(api::orderman::ORDER_ERROR_INVALID_ORDER_DEFINITON, x)
OrderOpResult LimitCoverAdapter::validate_proto(const api::orderman::DynamicOrderDefinition& dyn) {
return Adapter().validate_proto(dyn) ?
OrderOpResult() :
INVALID_DEF("One or more dynamic parameters are missing or invalid.");
}
void LimitCoverAdapter::init_proto(const LimitCoverDefinition& def, api::orderman::DynamicOrderDefinition& dyn) {
Adapter().to_proto(dyn, def);
}
void LimitCoverAdapter::define_proto(api::orderman::DynamicOrderDescriptor& desc) {
Adapter().define_proto(desc);
}
} // namespace orderman
} // namespace bts
@@ -1,15 +0,0 @@
#pragma once
#include "lib/api/services/OrderService.pb.h"
#include "lib/orderman/orders/algo/algo_orders/limit_cover/LimitCoverDefinition.h"
namespace bts {
namespace orderman {
struct LimitCoverAdapter {
static LimitCoverDefinition from_proto(const api::orderman::OrderDefinition& order);
static LimitCoverDefinition from_proto(const api::orderman::CustomOrderDefinition& custom_def);
static OrderOpResult validate_proto(const api::orderman::DynamicOrderDefinition& order);
static void init_proto(const LimitCoverDefinition& def, api::orderman::DynamicOrderDefinition& dyn);
static void define_proto(api::orderman::DynamicOrderDescriptor& desc);
};
} // namespace orderman
} // namespace bts
@@ -1,71 +0,0 @@
#pragma once
#include "lib/api/services/OrderService.pb.h"
#include "lib/orderman/orders/algo/algo_orders/limit_cover/LimitCoverGate.h"
#include "lib/orderman/orderman_utils/Formatter.h"
#include <ostream>
#include <map>
#include <vector>
namespace bts {
namespace orderman {
namespace limit_cover {
// The exclusive maximum number of gates.
// Note: the limit cover spec called for 3 gates (2 gates explicitly,
// plus an initial activation threshold, which is treated as another gate).
const uint32_t max_num_gates = 4;
}
struct LimitCoverDefinition {
// price offset
double price_offset() const {
return _price_offset;
}
void price_offset(double value) {
_price_offset = value;
}
LimitCoverGate gate(uint32_t index) const {
return _gate_or_default(index);
}
LimitCoverGate& mgate(uint32_t index) {
return _ensure_gate(index);
}
void gate(uint32_t index, LimitCoverGate value) {
_ensure_gate(index) = value;
}
// The original LimitAlgo spec called for an initial activation thresh, and 2 gates
// (fyi a gate has 3 members: activation thresh, cover thresh, and delete thresh).
// The initial activation thresh serves as the initial cover, and delete threshes as well.
// In this sense, the activation threshold can be considered as an 'initial gate' itself.
// 'normal_gates' does just that: returns a map of both gates plus the 'initial gate.'
std::map<uint32_t, LimitCoverGate> normal_gates() const {
std::map<uint32_t, LimitCoverGate> m;
for (auto g : _gates)
m.insert(std::make_pair(g.activation_threshold(), g));
return m;
}
private:
double _price_offset;
std::vector<LimitCoverGate> _gates;
LimitCoverGate& _ensure_gate(uint32_t index) {
bts_assert(index < limit_cover::max_num_gates);
while (_gates.size() <= index)
_gates.push_back(LimitCoverGate());
return _gates[index];
}
LimitCoverGate _gate_or_default(uint32_t index) const {
return _gates.size() > index ? _gates[index] : LimitCoverGate();
}
};
inline std::ostream& operator<<(std::ostream& ostr, const LimitCoverDefinition& lcd) {
auto ngates = lcd.normal_gates();
ostr << "Price Offset: " << lcd.price_offset()
<< ", Activation Thresh: " << lcd.gate(0).activation_threshold()
<< ", Gates: " << Formatter::fmt_values(ngates);
return ostr;
}
} // namespace orderman
} // namespace bts
@@ -1,87 +0,0 @@
#pragma once
#include "lib/api/services/OrderService.pb.h"
#include "lib/sparkproto/SparkProtos.pb.h"
#include "lib/utils/PBUtils.h"
#include <ostream>
namespace bts {
namespace orderman {
struct LimitCoverGate {
LimitCoverGate() : LimitCoverGate(0, 0, 0) {}
LimitCoverGate(const LimitCoverGate& other)
: _activation_threshold(other._activation_threshold), _definition(other._definition) {}
LimitCoverGate(uint32_t activation_thresh, uint32_t cover_thresh, uint32_t delete_thresh)
: _activation_threshold(activation_thresh), _definition() {
cover_threshold(cover_thresh);
delete_threshold(delete_thresh);
}
// activation threshold
uint32_t activation_threshold() const { return _activation_threshold; }
void activation_threshold(uint32_t value) { _activation_threshold = value; }
// cover threshold
uint32_t cover_threshold() const {
return _definition.has_cross_threshold() ? _get_absolute(_definition.cross_threshold()) : 0;
}
void cover_threshold(uint32_t value) {
if (!_definition.has_cross_threshold()) {
*_definition.mutable_cross_threshold() = bts::spark::QuantityMeasure();
}
_definition.mutable_cross_threshold()->set_absolute(value);
}
// delete threshold
uint32_t delete_threshold() const {
return _definition.has_top_threshold() ? _get_absolute(_definition.top_threshold()) : 0;
}
void delete_threshold(uint32_t value) {
if (!_definition.has_top_threshold()) {
*_definition.mutable_top_threshold() = bts::spark::QuantityMeasure();
}
_definition.mutable_top_threshold()->set_absolute(value);
}
// hedge ticks
uint32_t hedge_ticks() const { return _definition.hedge_ticks(); }
void hedge_ticks(uint32_t value) { _definition.set_hedge_ticks(value); }
// top ticks offset
uint32_t top_ticks_offset() const { return _definition.ticks_off(); }
void top_ticks_offset(uint32_t value) { _definition.set_ticks_off(value); }
// max chase ticks
uint32_t max_chase_ticks() const { return _definition.max_chase_ticks(); }
void max_chase_ticks(uint32_t value) { _definition.set_max_chase_ticks(value); }
// on toward
api::orderman::LeanOnToward on_toward() const { return _definition.trade_toward_behavior(); }
void on_toward(api::orderman::LeanOnToward value) { _definition.set_trade_toward_behavior(value); }
// definition
const api::orderman::DeleteAndCoverDefinition& definition() const { return _definition; }
api::orderman::DeleteAndCoverDefinition& mdefinition() { return _definition; }
void definition(api::orderman::DeleteAndCoverDefinition value) { _definition = value; }
api::orderman::CustomOrderDefinition custom_def() const {
api::orderman::CustomOrderDefinition cod;
*(cod.mutable_delete_and_cover()) = definition();
return cod;
}
void custom_def(const api::orderman::CustomOrderDefinition &cod) {
if (cod.has_delete_and_cover())
definition(cod.delete_and_cover());
}
private:
uint32_t _activation_threshold;
api::orderman::DeleteAndCoverDefinition _definition;
static inline uint32_t _get_absolute(spark::QuantityMeasure qty_measure, uint32_t fallback_value = 0) {
return qty_measure.quantity_case() == spark::QuantityMeasure::kAbsolute ? qty_measure.absolute() : fallback_value;
}
};
inline std::ostream& operator<<(std::ostream& ostr, const LimitCoverGate& g) {
ostr << "Activation Thresh: " << g.activation_threshold() << ", Definition: " << utils::pb::to_string(g.custom_def());
return ostr;
}
} // namespace orderman
} // namespace bts
@@ -1,196 +0,0 @@
#include "lib/orderman/orders/algo/algo_orders/LimitCoverAlgo.h"
#include "lib/orderman/orders/algo/algo_orders/tests/AlgoTestDriver.h"
#include "catch/catch.hpp"
#include "lib/api/services/OrderService.pb.h"
#include "lib/domain_model/Security.h"
#include "lib/orderman/orderman_utils/Book.h"
#include "lib/orderman/orderman_utils/BookUtils.h"
#include "lib/orderman/orderman_utils/Formatter.h"
#include "lib/orderman/orderman_utils/PriceComp.h"
#include "lib/orderman/orderman_utils/orderman_utils.h"
#include "lib/orderman/orders/algo/algo_orders/limit_cover/LimitCoverAdapter.h"
#include "lib/orderman/orders/algo/algo_orders/tests/limit_cover/LimitCoverState.h"
#include "lib/orderman/orders/algo/algo_orders/tests/limit_cover/LimitCoverTestUtils.h"
#include "lib/orderman/orders/algo/algo_orders/tests/limit_cover/TestSteps.h"
#include "lib/sparkproto/SparkProtos.pb.h"
#include "lib/utils/PBUtils.h"
#include <iostream>
#include <functional>
#include <optional>
#include <array>
#include <random>
#include <variant>
#include <cmath>
// for some reason, intellisense poops its pants without 'using namespace std.'
// std::optional<T>, and std::unordered_map<T>, in particular, break intellisense for the whole document.
using namespace std;
using namespace bts::api::orderman;
using namespace bts::orderman::limit_cover::utils;
//#define PRINT_SUMMARIES
namespace bts {
namespace orderman {
namespace test {
namespace limit_cover {
// Glossary:
// * limit-price:
// The price at which the main child is deployed (computed as a tick offset from the settlement).
// * limit-volume:
// The same-side market volume at or better than the limit price.
// This is recomputed whenever the book changes (obviously).
// * volume-gate:
// * volume-gate: a simple struct with 3 fields:
// 1) activation_threshold (uint)
// 2) cover_threshold (uint) must be <= activation_thresh
// 3) delete_threshold (uint) must be <= activation_thresh
// * current-volume-gate:
// The volume gate with the highest activation threshold that is still
// <= the limit-volume. This is recomputed whenever the book changes
// (obviously).
// * volume-gates:
// A series of volume gates, sorted by 'activation_threshold.'
// Initially, the current-volume-gate is one with the lowest activation threshold.
// The main child is not deployed until the limit-volume reaches that threshold.
// After that, the algo continues to observe the limit-volume, removing gates with lower
// thresholds when the volume breeches the next gate's thresh.
// Test Assertions:
// * child is not launched until the limit-volume reaches the initial activation threshold.
// * limit-volume is always correct (verify whenever the book changes).
// * current-volume-gate is always correct (verify whenever the book changes).
// Test Design:
// * expectations of the limit cover algo's state are stored in an instance of 'LimitCoverState.'
// The actual LimitCoverAlgo does not use this class; the tests just use it as a means
// to validate the actual LimitCoverAlgo's state, and to wrap calls to the LimitCoverAlgo
// with validation checks.
// * each test implementation should be executed 6 times:
// 2 x 3 = test both sides, with each of the following termination steps:
// 1) Fill to completion
// 2) Cancel the algo
// 3) Cancel the child
// * Restrictions on the parameters:
// - the spec explicitly called for 3 volume gates, and specified that the 3 thresholds
// (activation, cover, and delete) be the same for the first gate
// (technically, the spec described 2 gates and an 'entry threshold').
// - the algo should immediately cancel itself if these parameters are not the case.
// while it would most likely not cause a problem, these assumptions allow the tests to focus
// on a narrow range of inputs (and of course, such restrictions naturally decrease the
// chance of a bug slipping through).
LimitCoverState init_state(
OrderDefinition& mdef,
Side side,
uint32_t quantity,
double price,
double price_offset,
std::vector<LimitCoverGate> gates,
bool cancel_hedges_on_cancel = true,
bool cancel_on_external_hedge_cancel = false) {
//
REQUIRE(!gates.empty());
for (auto& g : gates) {
g.mdefinition().set_cancel_hedges_on_cancel(cancel_hedges_on_cancel);
g.mdefinition().set_cancel_on_external_hedge_cancel(cancel_on_external_hedge_cancel);
}
LimitCoverDefinition lc_def;
lc_def.price_offset(price_offset);
uint32_t gate_pos = 0;
for (auto g : gates) {
lc_def.gate(gate_pos++, g);
}
DynamicOrderDefinition dyn_def;
LimitCoverAdapter::init_proto(lc_def, dyn_def);
*(mdef.mutable_custom_def()->mutable_dynamic()) = dyn_def;
mdef.set_side(side);
return LimitCoverState(mdef, quantity, price);
}
template<typename... Steps>
inline void test_impl(Side side, uint32_t qty, double price_offset, double settle, std::vector<LimitCoverGate> gates, Steps... steps) {
std::cout << std::endl << std::endl;
std::cout << "*************************************************************************************************************************" << std::endl;
std::cout << "=========================================================================================================================" << std::endl;
int step_count = 1;
std::cout << "Test " << "[" << Formatter::to_string(side) << " Order]" << std::endl << "\t1. "
<< Formatter::join([&]() {
return Formatter::fmt("\n\t", ++step_count, ". ");
}, steps...)
<< std::endl;
std::cout << "=========================================================================================================================" << std::endl;
std::cout << "*************************************************************************************************************************" << std::endl;
std::cout << std::endl;
OrderDefinition def;
// price is irrelevant
auto state = init_state(def, side, qty, -99999, price_offset, gates);
state.settlement(settle);
(steps.execute(state), ...);
}
template<typename... Steps>
inline void test_permutations(
uint32_t qty,
double settle,
std::vector<LimitCoverGate> gates,
Steps... steps) {
std::vector<double> price_offsets { 0.0, 0.75, 1.25, -0.75, -1.25 };
for (auto po : price_offsets) {
// complete
test_impl(api::SIDE_BUY, qty, po, settle, gates, steps..., test_steps::Complete());
test_impl(api::SIDE_SELL, qty, po, settle, gates, steps..., test_steps::Complete());
// cancel child
test_impl(api::SIDE_BUY, qty, po, settle, gates, steps..., test_steps::CancelChild());
test_impl(api::SIDE_SELL, qty, po, settle, gates, steps..., test_steps::CancelChild());
// cancel algo
test_impl(api::SIDE_BUY, qty, po, settle, gates, steps..., test_steps::CancelAlgo());
test_impl(api::SIDE_SELL, qty, po, settle, gates, steps..., test_steps::CancelAlgo());
}
}
TEST_CASE("test_activation_thresholds.", "[algo][limit_cover]") {
SECTION("Activate 1st gate.") {
test_permutations(25, 100, {
LimitCoverGate(4, 4, 4),
LimitCoverGate(10, 7, 5),
LimitCoverGate(15, 12, 11),
},
// test steps
test_steps::BeginLaunch(),
test_steps::Launch(),
test_steps::BreechActivationThresh());
}
SECTION("Activate 1st then 2nd gate.") {
test_permutations(25, 100, {
LimitCoverGate(4, 4, 4),
LimitCoverGate(10, 7, 5),
LimitCoverGate(15, 12, 11),
},
// test steps
test_steps::BeginLaunch(),
test_steps::Launch(),
test_steps::BreechActivationThresh(),
test_steps::Fill([](const auto& state) { return test_params::fills::child(state, 8); }),
test_steps::BreechActivationThresh(),
test_steps::Fill([](const auto& state) { return test_params::fills::child(state, 2); }),
test_steps::BreechActivationThresh());
}
SECTION("Activate 2nd gate.") {
test_permutations(25, 100, {
LimitCoverGate(4, 4, 4),
LimitCoverGate(10, 7, 5),
LimitCoverGate(15, 12, 11),
},
// test steps
test_steps::BeginLaunch(),
test_steps::Launch(),
test_steps::BreechActivationThresh(1, 1),
test_steps::Fill([](const auto& state) { return test_params::fills::child(state, 8); }));
}
}
} // namespace limit_cover
} // namespace test
} // namespace orderman
} // namespace bts
@@ -1,743 +0,0 @@
#include "catch/catch.hpp"
#include "../DormanAlgo.h"
#include "AlgoTestDriver.h"
#include "lib/orderman/orderman_utils/Book.h"
#include "lib/domain_model/Security.h"
#include "lib/orderman/orderman_utils/orderman_utils.h"
#include <optional>
#include <variant>
#include <random>
using namespace std;
using namespace bts::orderman::dorman;
using namespace bts::api::orderman;
namespace bts {
namespace orderman {
namespace test {
/* STATE
struct OrderState {
Price desired_price;
Quantity exposed_qty;
}
*/
/* TEST ASPECTS
order_qty vs market quantity
order_qty reduce when market changes
order_qty increase (w/ delay) when market changes
order_qty maximum
overfill [under/over] max with auto-scratch [on/off]
Profit orders
- test that orders are sent
- test that away order are at the right price
Trade Accumulation
- accumulator goes [on/off]
- Dorman goes to sleep when it goes 'on' and wakes up when it goes 'off'
Market Moves
- Available size increases
- Available size decreases
clip size pseudo-order
- change clip size
- immidiate effect?
- don't have to cancel if clip size goes down?
- change order size [up/down]
- suspend/resume
- cancels all
*/
api::orderman::DynamicOrderDefinition to_dynamic_order_params(const AlgoParams& input) {
api::orderman::DynamicOrderDefinition result;
result.set_dynamic_order_type("Dorman");
auto& map = *result.mutable_order_params();
for (size_t x = 0; x < input.steps.step_table.size(); ++x) {
std::string xs = std::to_string(x+1);
map["Market Quantity " + xs] = dynamic_parameter( std::get<0>(input.steps.step_table[x]));
map["Order Quantity " + xs] = dynamic_parameter(std::get<1>(input.steps.step_table[x]));
}
map["Max Size"] = dynamic_parameter(input.steps.maximum);
map["Trail Seconds"] = dynamic_parameter(input.steps.trail_seconds);
map["Clip Size"] = dynamic_parameter(input.clip_limit);
// scratch
map["Enable Scratch"] = dynamic_parameter((bool)(input.scratch));
if (input.scratch) {
map["Max Overfill"] = dynamic_parameter(input.scratch.value().max_overfill);
}
//
// profit orders
map["Profit Orders"] = dynamic_parameter((bool)input.profit_orders);
if (input.profit_orders) {
map["Ticks Away"] = dynamic_parameter(input.profit_orders.value().ticks_away);
}
//
// trade accumulator
map["Trade Accumulation"] = dynamic_parameter((bool)input.trade_accumulation);
if (input.trade_accumulation) {
auto& a = input.trade_accumulation.value();
map[("Trade Contracts")] = dynamic_parameter(a.contracts);
map["Trade Interval (seconds)"] = dynamic_parameter(a.seconds);
map["Trade Sleep (seconds)"] = dynamic_parameter(a.sleep_seconds);
}
return result;
}
void check_round_trip(const AlgoParams& input) {
auto d1 = to_dynamic_order_params(input);
auto ap1 = to_dorman_params(d1);
if (std::holds_alternative<OrderOpResult>(ap1)) {
std::cout << std::get<OrderOpResult>(ap1).error_msg;
}
REQUIRE(std::holds_alternative<AlgoParams>(ap1));
auto d2 = to_dynamic_order_params(std::get<AlgoParams>(ap1));
REQUIRE(d2.DebugString() == d1.DebugString());
}
TEST_CASE("dorman_round_trip_params", "[algo][dorman]") {
SECTION("a") {
AlgoParams input;
input.steps = {
{ {500, 250},
{1000, 400} },
1024, 5
};
check_round_trip(input);
}
SECTION("b") {
AlgoParams input;
input.steps = {
{ {500, 250},
{1000, 400}
},
1024, 5
};
input.scratch = { 500 };
input.profit_orders = { 42 };
input.clip_limit = 220;
check_round_trip(input);
}
SECTION("c") {
AlgoParams input;
input.steps = {
{ {500, 250},
{1000, 400}
},
1024, 5
};
input.profit_orders = { 42 };
input.trade_accumulation = {
100, 200, 300
};
check_round_trip(input);
}
}
struct ExpectedSize {
uint32_t input;
uint32_t expected;
};
constexpr auto some_price = md::IntPrice { 128000, -3 };
template <class CB>
size_t count_x(const std::vector<ChildOrder>& child_orders, CB fn) {
return std::accumulate(
child_orders.begin(),
child_orders.end(), 0,
[&](uint32_t acc, const auto& child) {
return acc + fn(child);
});
}
size_t count_exposed(const std::vector<ChildOrder>& child_orders) {
return count_x(child_orders, [](const ChildOrder& child) {
REQUIRE(child.def);
if (child.cstate.status == ChildStatus::CANCELED) return 0u;
else return child.def.value().custom_def().splitter().exposed_qty() + child.cstate.total_fills.value();
});
}
size_t count_fills(const std::vector<ChildOrder>& child_orders) {
return count_x(child_orders, [](const ChildOrder& child) {
return child.def.value().custom_def().splitter().exposed_qty() + child.cstate.total_fills.value();
});
}
size_t count_status(const std::vector<ChildOrder>& child_orders, ChildStatus status) {
size_t match = 0;
for (const auto& child : child_orders) {
if (child.cstate.status == status) match += 1;
}
return match;
}
TEST_CASE("dorman_order_size", "[algo][dorman]") {
// create a table of various sizes
// send market state to the algo
AlgoParams input;
input.steps.step_table = {
{500, 250},
{1000, 400},
{2000, 600},
{3500, 750},
{10000, 999}
};
input.steps.maximum = 800;
input.steps.trail_seconds = 5;
input.clip_limit = 100;
api::orderman::OrderDefinition def;
def.set_side(api::SIDE_BUY);
def.mutable_custom_def()->mutable_dynamic()->CopyFrom(to_dynamic_order_params(input));
SECTION("initial size vs market") {
std::vector<ExpectedSize> test_sizes {
{ 10, 0 },
{ 200, 0 },
{ 250, 0 },
{ 500, 250 },
{ 999, 250 },
{ 2500, 600 },
{ 9999, 750 },
{ 20002, 800 },
};
for (auto& s : test_sizes)
{
AlgoTestDriver<DormanAlgo> state(def, some_price, Quantity {10});
auto secid = SecurityKey(state.security().id());
Book book(secid);
// order size is driven by the available market size
book.bid()[0] = { some_price, s.input };
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty().value() == s.expected);
REQUIRE(s.expected == count_exposed(state.child_orders()));
}
}
SECTION("Reduce qty on market shrink (immidiate)") {
AlgoTestDriver<DormanAlgo> state(def, some_price, Quantity {10});
auto secid = SecurityKey(state.security().id());
Book book(secid);
book.bid()[0] = { some_price, 505 };
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(250));
// Check that orders were created
REQUIRE(250 == count_exposed(state.child_orders()));
for(const auto& ch : state.child_orders()) {
REQUIRE(ch.cstate.quantity == state.quantity());
}
// Reduce market
book.bid()[0] = { some_price, 405 };
state.update_book(book);
REQUIRE(state.algo().exposed_qty() == Quantity(0));
REQUIRE(
0 == count_exposed(state.child_orders()));
}
SECTION("Increase qty w/ delay when market grows") {
AlgoTestDriver<DormanAlgo> state(def, some_price, Quantity {10});
auto secid = SecurityKey(state.security().id());
Book book(secid);
book.bid()[0] = { some_price, 505 };
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(250));
// Check that orders were created
REQUIRE(
250 == count_exposed(state.child_orders()));
// INCREASE market
book.bid()[0] = { some_price, 1001 };
state.update_book(book);
// NOTE: that the orders do not follow the market instantly
// so this is still 250
REQUIRE(
250 == count_exposed(state.child_orders()));
// Still 250 after the timer ticks but not enough time has passed
state.advance_time(std::chrono::seconds());
REQUIRE(
250 == count_exposed(state.child_orders()));
state.advance_time(std::chrono::seconds(input.steps.trail_seconds));
REQUIRE(
400 == count_exposed(state.child_orders()));
}
SECTION("Respect maximum") {
AlgoTestDriver<DormanAlgo> state(def, some_price, Quantity {10});
auto secid = SecurityKey(state.security().id());
Book book(secid);
book.bid()[0] = { some_price, 10505 };
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(input.steps.maximum));
// Check that orders were created
REQUIRE(
input.steps.maximum == count_exposed(state.child_orders()));
}
}
TEST_CASE("Dorman fills", "[algo][dorman]") {
AlgoParams input;
input.steps.step_table = {
{500, 250},
{1000, 450},
{2000, 650},
{3500, 750},
};
input.steps.maximum = 750;
input.steps.trail_seconds = 2;
input.clip_limit = 100;
api::orderman::OrderDefinition def;
def.set_side(api::SIDE_BUY);
def.mutable_custom_def()->mutable_dynamic()->CopyFrom(to_dynamic_order_params(input));
auto price = Price { some_price.price() };
SECTION("complete when filled") {
// Send out some orders
// Fill them
// Expect order state to become finished
AlgoTestDriver<DormanAlgo> state(def, some_price, Quantity {10});
auto secid = SecurityKey(state.security().id());
Book book(secid);
book.bid()[0] = { some_price, 501 };
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(250));
for (const auto& order : state.child_orders()) {
state.fill(order.key, price, order.cstate.quantity);
}
REQUIRE(state.state() == AlgoState::COMPLETED);
}
// Test cases for transitions w/ fills
//
SECTION("Complete by update") {
// target = 500, exposed = 650
// Fill 400
// Change target to 350
// expect completion
AlgoTestDriver<DormanAlgo> state(def, some_price, Quantity {500});
auto secid = SecurityKey(state.security().id());
Book book(secid);
book.bid()[0] = { some_price, 1999 };
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(450));
REQUIRE(state.quantity() == Quantity {500});
// Fill 400
state.fill(price, Quantity { 400 });
Update update;
update.set_quantity(350);
state.do_update(update);
REQUIRE(state.state() == AlgoState::COMPLETED);
}
}
TEST_CASE("Dorman overfill", "[algo][dorman]") {
AlgoParams input;
input.steps.step_table = {
{500, 250},
{1000, 450},
{2000, 650},
{3500, 750},
};
input.steps.maximum = 750;
input.steps.trail_seconds = 2;
input.clip_limit = 100;
SECTION("auto-scratch ON") {
input.scratch = {{ 500 }};
}
SECTION("auto-scratch OFF") {
// both sections will run
input.scratch = std::nullopt;
}
api::orderman::OrderDefinition def;
def.set_side(api::SIDE_BUY);
def.mutable_custom_def()->mutable_dynamic()->CopyFrom(to_dynamic_order_params(input));
auto price = Price { some_price.price() };
AlgoTestDriver<DormanAlgo> state(def, some_price, Quantity {100});
state.allow_overfill();
auto secid = SecurityKey(state.security().id());
Book book(secid);
book.bid()[0] = { some_price, 1999 };
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(450));
REQUIRE(state.quantity() == Quantity {100});
REQUIRE(state.child_orders().size() == 1);
state.fill(state.child_orders().begin()->key, price, Quantity {500});
REQUIRE(state.state() == AlgoState::COMPLETED);
if (input.scratch) {
// check that we scratched
REQUIRE(state.detached_orders().size() > 0);
}
else {
// check that we *did not* scratch
REQUIRE(state.detached_orders().size() == 0);
}
}
TEST_CASE("Dorman profit-orders", "[algo][dorman]") {
AlgoParams input;
input.steps.step_table = {
{500, 250},
{1000, 450},
{2000, 650},
{3500, 750},
};
input.steps.maximum = 750;
input.steps.trail_seconds = 2;
input.clip_limit = 100;
bool test_cancel = true;
SECTION("Profit Orders ON - Cancel") {
// Send profit orders 3 ticks away
input.profit_orders = {{ 3 }};
}
SECTION("Profit Orders ON - Complete") {
// Send profit orders 3 ticks away
input.profit_orders = {{ 3 }};
test_cancel = false;
}
SECTION("Profit Orders OFF") {
input.profit_orders = std::nullopt;
}
SECTION("Profit Orders OFF - complete") {
input.profit_orders = std::nullopt;
test_cancel = false;
}
api::orderman::OrderDefinition def;
def.set_side(api::SIDE_BUY);
def.mutable_custom_def()->mutable_dynamic()->CopyFrom(to_dynamic_order_params(input));
auto price = Price { some_price.price() };
AlgoTestDriver<DormanAlgo> state(def, some_price, Quantity {100});
auto secid = SecurityKey(state.security().id());
auto tick = state.security().contract_spec().low_tick();
Book book(secid);
book.bid()[0] = { some_price, 1999 };
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(450));
REQUIRE(state.quantity() == Quantity {100});
REQUIRE(state.child_orders().size() == 1);
state.fill(state.child_orders().begin()->key, price, Quantity {20});
if (input.profit_orders) {
// We're testing the bid side so we expect 3 ticks up
auto expected_price = Price {
price.value() + (tick * input.profit_orders.value().ticks_away) };
REQUIRE(state.child_orders().size() > 1);
REQUIRE(state.detached_orders().empty());
size_t profit_order_count = 0;
for (const auto& order : state.child_orders()) {
if (order.def.value().side() == api::SIDE_SELL) {
profit_order_count += 1;
REQUIRE(order.cstate.quantity.value() == 20);
REQUIRE(securities::is_same(order.cstate.price, expected_price));
}
}
REQUIRE(profit_order_count == 1);
}
else {
REQUIRE(state.child_orders().size() == 1);
REQUIRE(state.detached_orders().empty());
}
state.fill(state.child_orders().begin()->key, price, Quantity {42});
if (input.profit_orders) {
auto expected_price = Price {
price.value() + (tick * input.profit_orders.value().ticks_away) };
REQUIRE(state.child_orders().size() > 1);
REQUIRE(state.detached_orders().empty());
bool got_20 = false;
bool got_42 = false;
for (const auto& order : state.child_orders()) {
if (order.def.value().side() == api::SIDE_SELL) {
if (order.cstate.quantity.value() == 20) got_20 = true;
if (order.cstate.quantity.value() == 42) got_42 = true;
REQUIRE(securities::is_same(order.cstate.price, expected_price));
}
}
REQUIRE(got_42);
REQUIRE(got_20);
}
else {
REQUIRE(state.child_orders().size() == 1);
REQUIRE(state.detached_orders().empty());
}
if (test_cancel) {
// Profit orders should detach on cancel
state.cancel();
REQUIRE(state.state() == AlgoState::CANCELED);
if (input.profit_orders) {
REQUIRE(state.detached_orders().size() > 0);
}
}
else {
state.fill(state.child_orders().begin()->key, price, Quantity {38});
REQUIRE(state.state() == AlgoState::COMPLETED);
if (input.profit_orders) {
REQUIRE(state.detached_orders().size() > 0);
}
}
}
// TEST_CASE("Dorman detaches profit orders when completed by scratch", "[algo][dorman][!hide]") {
// Idea for future test
// }
TickerUpdateEvent::Trade mkTrade(Price p, Quantity q) {
return {
Timer::now(),
p,
q,
Quantity { q.value() + 9999 },
co2::AGGRESSOR_SIDE_NONE
};
}
TradeVector mkTrades(Price p, Quantity total) {
std::random_device rd;
std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
uint32_t remaining = total.value();
TradeVector result;
while(remaining > 0) {
std::uniform_real_distribution<> dis(1, remaining);
auto qty = (uint32_t)dis(gen);
remaining -= qty;
result.push_back(mkTrade(p, Quantity {qty}));
}
return result;
}
TEST_CASE("Dorman trade accumulation", "[algo][dorman]") {
// Start algo with trade accumulation enabled
// If 100 trades in 5 seconds pause for 6 seconds
// Exceed Limits
// Check that child was canceled and re-created
// Disable accumulator
// attempt to exceed limits
// Check that algo does not turn off
// re-enable accumulator
// Check that algo turns off
// Change parameters
// Check that the algo turns off based on the *new* params
AlgoParams input;
input.steps.step_table = {
{225, 32},
{362, 64},
{589, 128},
{697, 5000},
};
input.steps.maximum = 9999;
input.clip_limit = 8;
// If 100 trades in 5 seconds pause for 6 seconds
input.trade_accumulation = {TradeAccumulationParams { 100, 5, 6 } };
api::orderman::OrderDefinition def;
def.set_side(api::SIDE_BUY);
def.mutable_custom_def()->mutable_dynamic()->CopyFrom(to_dynamic_order_params(input));
auto price = Price { some_price.price() };
AlgoTestDriver<DormanAlgo> state(def, some_price, Quantity {2500});
auto secid = SecurityKey(state.security().id());
Book book(secid);
book.bid()[0] = { some_price, 1999 };
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(5000));
REQUIRE(state.child_orders().size() == 1);
state.advance_time(std::chrono::seconds(1));
// Need 100 trades in 5 seconds,
// The algorithm we're using has a margin of error so
// lets do 25 trades per second for 5 seconds which should be comfortably over
// send_trades(state, Quantity { 120 }, std::chrono::seconds(5));
for (auto t = 0; t < 5; ++t) {
state.update_ticker(secid, mkTrades(price, Quantity { 25 }));
state.advance_time(std::chrono::milliseconds(1001), 3);
}
REQUIRE(count_exposed(state.child_orders()) == 0);
state.advance_time(std::chrono::seconds(4));
// Check that it hasn't jumped the gun
REQUIRE(count_exposed(state.child_orders()) == 0);
state.advance_time(std::chrono::seconds(3));
// Sleep time has expired so we should re-join the market
REQUIRE(count_exposed(state.child_orders()) == 5000);
// Disable the accumulator
Update update;
input.trade_accumulation = std::nullopt;
update.mutable_custom()->mutable_dynamic()->CopyFrom(to_dynamic_order_params(input));
update.set_quantity(5000);
state.do_update(update);
// Attempt to exceed again
for (auto t = 0; t < 5; ++t) {
state.update_ticker(secid, mkTrades(price, Quantity { 25 }));
state.advance_time(std::chrono::milliseconds(1001), 9);
}
// Still working
REQUIRE(count_exposed(state.child_orders()) == 5000);
// re-enable accumulator
input.trade_accumulation = {TradeAccumulationParams { 100, 5, 6 } };
update.mutable_custom()->mutable_dynamic()->CopyFrom(to_dynamic_order_params(input));
state.do_update(update);
for (auto t = 0; t < 5; ++t) {
state.update_ticker(secid, mkTrades(price, Quantity { 25 }));
state.advance_time(std::chrono::milliseconds(1001), 4);
}
// turned off?
REQUIRE(count_exposed(state.child_orders()) == 0);
state.advance_time(std::chrono::seconds(10));
// back on!
REQUIRE(count_exposed(state.child_orders()) == 5000);
// Change the accumulator params without disabling it
input.trade_accumulation = {TradeAccumulationParams { 1000, 5, 6 } };
update.mutable_custom()->mutable_dynamic()->CopyFrom(to_dynamic_order_params(input));
state.do_update(update);
// Attempt to trigger based on the old settings.
for (auto t = 0; t < 5; ++t) {
state.update_ticker(secid, mkTrades(price, Quantity { 35 }));
state.advance_time(std::chrono::milliseconds(1001), 7);
}
// Still working?
REQUIRE(count_exposed(state.child_orders()) == 5000);
// Attempt to trigger based on new settings
for (auto t = 0; t < 5; ++t) {
state.update_ticker(secid, mkTrades(price, Quantity { 500 }));
state.advance_time(std::chrono::milliseconds(1001), 5);
}
REQUIRE(count_exposed(state.child_orders()) == 0);
// complete while paused (fills can arrive after requested cancel)
ChildOrder latest_order = {};
for (auto& order : state.child_orders()) {
if (order.key > latest_order.key) latest_order = order;
}
state.fill(latest_order.key, price, latest_order.cstate.quantity);
REQUIRE(state.state() == AlgoState::COMPLETED);
}
TEST_CASE("Dorman updates child", "[algo][dorman]") {
// When updating the Dorman price the price of the child should also update
}
TEST_CASE("Dorman market move up then back down", "[algo][dorman]") {
// Start dorman algo
// Move market up so we plan to increase the exposed qty after trail_seconds
// Move market back down before trail_seconds elapses
// check that algo does *not* increase exposure
AlgoParams input;
input.steps.step_table = {
{500, 250},
{1000, 450},
{2000, 650},
{3500, 750},
};
input.steps.maximum = 750;
input.steps.trail_seconds = 30;
input.clip_limit = 100;
api::orderman::OrderDefinition def;
def.set_side(api::SIDE_BUY);
def.mutable_custom_def()->mutable_dynamic()->CopyFrom(to_dynamic_order_params(input));
// auto price = Price { some_price.price() };
AlgoTestDriver<DormanAlgo> state(def, some_price, Quantity {1337});
auto secid = SecurityKey(state.security().id());
Book book(secid);
book.bid()[0] = { some_price, 1350 };
state.update_book(book);
REQUIRE(state.before_launch().ok());
state.launch();
REQUIRE(state.algo().exposed_qty() == Quantity(450));
REQUIRE(state.child_orders().size() == 1);
state.advance_time(std::chrono::seconds(1));
// Update book sets future quantity = 650
book.bid()[0] = { some_price, 2219 };
state.update_book(book);
state.advance_time(std::chrono::seconds(10));
// Algo does not increase exposure after 10 second
REQUIRE(state.algo().exposed_qty() == Quantity(450));
book.bid()[0] = { some_price, 1425 };
state.update_book(book);
state.advance_time(std::chrono::seconds(40));
// Algo does not increase exposure after trail_seconds
REQUIRE(state.algo().exposed_qty() == Quantity(450));
}
}}}//namespace
@@ -1,199 +0,0 @@
#include "lib/orderman/orders/algo/algo_orders/tests/limit_cover/LimitCoverState.h"
#include "catch/catch.hpp"
#include "lib/domain_model/Security.h"
#include "lib/md/IntPrice.h"
#include "lib/orderman/order_factory/IOrderFactory.h"
#include "lib/orderman/orderman_utils/BookUtils.h"
#include "lib/orderman/orderman_utils/Formatter.h"
#include "lib/orderman/orders/algo/algo_orders/limit_cover/LimitCoverAdapter.h"
#include "lib/orderman/orders/algo/algo_orders/tests/limit_cover/LimitCoverTestUtils.h"
#define VALIDATE Validation __VALIDATION(this)
namespace bts {
namespace orderman {
namespace test {
namespace limit_cover {
using namespace std;
using namespace bts::api::orderman;
using namespace bts::orderman::limit_cover::utils;
using Size = bts::md::Size;
using Side = bts::api::Side;
LimitCoverState::LimitCoverState(
const OrderDefinition& def,
uint32_t quantity,
double price)
: driver(def, int_price(price), Quantity(quantity)), _definition(def), _gates(), _book(SecurityKey(security().id())) {
auto ngs = limit_cover().normal_gates();
_gates.insert(ngs.begin(), ngs.end());
// attach callbacks
driver.on_child_launching([&](OrderKey key, Quantity child_qty, Price child_price) {
// should never deploy twice
REQUIRE(_child == null_order_key());
REQUIRE(key != null_order_key());
_child = key;
// qty should match the algo's, but price must be the limit price
// (the algo's price is irrelevant)
REQUIRE(child_qty.value() == driver.quantity().value());
REQUIRE(child_price.value() == limit_price());
// todo: verify delete and cover def matches the current gate
//REQUIRE(child_def.custom_def().delete_and_cover())
REQUIRE(limit_volume() >= activation_threshold());
});
driver.on_child_changed([&](const ChildOrder&, const ChildOrder& new_state) {
REQUIRE(new_state.key == _child);
REQUIRE(new_state.def.has_value());
REQUIRE(new_state.def.value().has_custom_def());
REQUIRE(new_state.def.value().custom_def().has_delete_and_cover());
});
driver.after_child_changed([&](const ChildOrder&, const ChildOrder& new_state) {
REQUIRE(driver.total_fills().value() == new_state.cstate.total_fills.value());
});
}
uint32_t LimitCoverState::quantity() const {
return driver.quantity().value();
}
double LimitCoverState::price() const {
return driver.price().value();
}
const api::Security& LimitCoverState::security() const {
return driver.security();
}
const bts::api::orderman::OrderDefinition& LimitCoverState::def() const {
return _definition;
}
LimitCoverDefinition LimitCoverState::limit_cover() const {
return LimitCoverAdapter::from_proto(def());
}
uint32_t LimitCoverState::limit_volume() const {
return _limit_volume;
}
double LimitCoverState::limit_price() const {
return _limit_price;
}
OrderKey LimitCoverState::child() const {
return _child;
}
optional<ChildOrder> LimitCoverState::child_state() const {
if (has_been_deployed()) {
return ChildOrder(*driver.child_orders().begin());
}
return {};
}
void LimitCoverState::update_child(const Update& u) {
driver.update_child(child(), u);
}
bool LimitCoverState::has_been_deployed() const {
return _child != null_order_key();
}
bool LimitCoverState::is_terminated() const {
switch (driver.state()) {
case AlgoState::CANCELED:
case AlgoState::TERMINATED:
return true;
default:
return false;
}
}
const std::map<uint32_t, LimitCoverGate>& LimitCoverState::gates() const {
return _gates;
}
const LimitCoverGate& LimitCoverState::curr_gate() const {
REQUIRE(!gates().empty());
return gates().begin()->second;
}
uint32_t LimitCoverState::activation_threshold() const {
return gates().empty() ? std::numeric_limits<uint32_t>::max() : gates().begin()->first;
}
// settlement
double LimitCoverState::settlement() const { return _settlement; }
void LimitCoverState::settlement(double value) {
VALIDATE;
// the algo is not supposed to disregard settlement changes
// after the child has been deployed
if (!has_been_deployed()) {
_settlement = value;
recompute_all();
}
driver.update_settlement(SecurityKey(security().id()), Price(value));
}
// book
const Book& LimitCoverState::book() const { return _book; }
void LimitCoverState::book(Book value) {
VALIDATE;
_book = value;
recompute_all();
driver.update_book(value);
}
OrderOpResult LimitCoverState::before_launch() {
_gates.clear();
auto ngs = limit_cover().normal_gates();
_gates.insert(ngs.begin(), ngs.end());
return driver.before_launch();
}
void LimitCoverState::launch() {
VALIDATE;
_is_initialized = true;
recompute_all();
driver.launch();
}
void LimitCoverState::do_update(const Update& upd) {
REQUIRE(!is_terminated());
// updates should not affect the child's price (after it has been launched).
// this is bc the literal 'price' parameter is irrelevant to this algo,
// for all intents and purposes, its price is the tick offset from settlement.
auto upd_valid = validate_update(upd);
// keep definition in sync with update
if (upd.has_custom() && upd_valid.ok()) {
*(_definition.mutable_custom_def()) = upd.custom();
}
driver.do_update(upd);
if (upd_valid.ok()) {
recompute_all();
} else {
REQUIRE(driver.state() == AlgoState::TERMINATED);
}
}
void LimitCoverState::recompute_limit_price() {
_limit_price = os::is_nan(settlement()) ? os::nan() :
securities::improve_price(side(), Price(settlement()), Price(limit_cover().price_offset()))
.value();
}
void LimitCoverState::recompute_limit_volume() {
_limit_volume = os::is_nan(settlement()) ? os::nan() :
BookUtils::volume_at_or_better(_book, side(), limit_price());
}
void LimitCoverState::recompute_all() {
recompute_limit_price();
recompute_limit_volume();
if (_is_initialized)
recompute_gate();
}
void LimitCoverState::recompute_gate() {
if (gates().empty())
return;
auto it = _gates.lower_bound(limit_volume());
if (it->first > limit_volume() && it != _gates.begin())
it--;
_gates.erase(_gates.begin(), it);
}
LimitCoverState::ValidateDeployment::ValidateDeployment(LimitCoverState* state) :
_state(state), _had_been_deployed(state->has_been_deployed()) { }
LimitCoverState::ValidateDeployment::~ValidateDeployment() {
if (!_had_been_deployed && _state->limit_volume() >= _state->activation_threshold())
REQUIRE(_state->has_been_deployed());
}
} // namespace limit_cover
} // namespace test
} // namespace orderman
} // namespace bts
@@ -1,121 +0,0 @@
#pragma once
#include "lib/api/services/OrderService.pb.h"
#include "lib/domain_model/Security.h"
#include "lib/orderman/orderman_utils/Book.h"
#include "lib/orderman/orders/algo/algo_orders/LimitCoverAlgo.h"
#include "lib/orderman/orders/algo/algo_orders/limit_cover/LimitCoverDefinition.h"
#include "lib/orderman/orders/algo/algo_orders/tests/AlgoTestDriver.h"
#include "lib/sparkproto/SparkProtos.pb.h"
#include <iostream>
#include <map>
#include <optional>
namespace bts {
namespace orderman {
namespace test {
namespace limit_cover {
struct LimitCoverState {
AlgoTestDriver<LimitCoverAlgo> driver;
LimitCoverState(
const api::orderman::OrderDefinition& def,
uint32_t quantity,
double price);
const api::orderman::OrderDefinition& def() const;
uint32_t quantity() const;
double price() const;
const api::Security& security() const;
LimitCoverDefinition limit_cover() const;
api::Side side() const { return def().side(); }
uint32_t activation_threshold() const;
// main child
OrderKey child() const;
std::optional<ChildOrder> child_state() const;
// gates/curr gate
const std::map<uint32_t, LimitCoverGate>& gates() const;
const LimitCoverGate& curr_gate() const;
// book
const Book& book() const;
void book(Book new_book);
//
bool has_been_deployed() const;
// settle
double settlement() const;
void settlement(double value);
// limit price
double limit_price() const;
// limit volume
uint32_t limit_volume() const;
bool is_terminated() const;
OrderOpResult before_launch();
void launch();
void do_update(const api::orderman::Update&);
void update_child(const api::orderman::Update&);
private:
api::orderman::OrderDefinition _definition;
uint32_t _limit_volume = 0;
OrderKey _child;
double _limit_price = os::nan();
double _settlement = os::nan();
bool _is_initialized = false;
std::map<uint32_t, LimitCoverGate> _gates;
Book _book;
void recompute_limit_price();
void recompute_limit_volume();
void recompute_all();
void recompute_gate();
struct ValidateDeployment {
ValidateDeployment(LimitCoverState* state);
~ValidateDeployment();
private:
LimitCoverState* _state;
bool _had_been_deployed;
};
struct Validation : public ValidateDeployment {
Validation(LimitCoverState* state)
: ValidateDeployment(state) {}
~Validation() {}
};
};
// custom formatting uses 1 line (unlike pb::to_string).
inline std::ostream& operator<<(std::ostream& ostr, const bts::spark::QuantityMeasure& qm) {
switch (qm.quantity_case()) {
case bts::spark::QuantityMeasure::kAbsolute:
ostr << "[absolute] " << qm.absolute();
break;
case bts::spark::QuantityMeasure::kRatio:
ostr << "[ratio] " << qm.ratio();
break;
default:
ostr << "[quantity_case_" << static_cast<int>(qm.quantity_case()) << "]";
break;
}
return ostr;
}
inline std::ostream& operator<<(std::ostream& ostr, const LimitCoverState& lcs) {
ostr << "qty: " << lcs.quantity() << std::endl;
ostr << "limit price: " << lcs.limit_price() << std::endl;
ostr << "limit volume: " << lcs.limit_volume() << std::endl;
ostr << "activation/curr gate thresh: " << lcs.activation_threshold() << std::endl;
ostr << "settlement: " << lcs.settlement() << std::endl;
ostr << "bbo: " << Formatter::to_string(lcs.book()) << std::endl;
ostr << "has been deployed: " << lcs.has_been_deployed() << std::endl;
ostr << "status: " << lcs.driver.state() << std::endl;
ostr << "child: " << lcs.child() << std::endl;
ostr << "child qty: " << (lcs.child_state().has_value() ? lcs.child_state().value().cstate.quantity.value() : 0) << std::endl;
ostr << "filled qty: " << lcs.driver.total_fills().value() << std::endl;
return ostr;
}
} // namespace limit_cover
} // namespace test
} // namespace orderman
} // namespace bts
@@ -1,44 +0,0 @@
#pragma once
#include "lib/api/services/OrderService.pb.h"
#include "lib/md/IntPrice.h"
#include "lib/orderman/orderman_utils/Formatter.h"
#include "lib/sparkproto/SparkProtos.pb.h"
#include <iostream>
#define SUMMARIZE(...) Summary __summary__ (Formatter::fmt(__VA_ARGS__))
using Side = bts::api::Side;
namespace bts {
namespace orderman {
namespace test {
namespace limit_cover {
using namespace std;
inline bts::md::IntPrice int_price(double value) {
return bts::md::IntPrice_from_double<8>(value);
}
inline bts::md::PriceSize price_size(double price, uint32_t size) {
return bts::md::PriceSize(int_price(price), size);
}
inline bts::spark::QuantityMeasure qty_measure(uint32_t abs) {
bts::spark::QuantityMeasure qm;
qm.set_absolute(abs);
return qm;
}
struct Summary {
Summary(std::string header)
: _header(header) {
std::cout << "Begin " << header << std::endl;
}
~Summary() {
std::cout << "End " << _header << std::endl;
}
private:
std::string _header;
};
} // namespace limit_cover
} // namespace test
} // namespace orderman
} // namespace bts
@@ -1,221 +0,0 @@
#include "lib/orderman/orders/algo/algo_orders/tests/limit_cover/TestSteps.h"
#include "catch/catch.hpp"
#include "lib/api/services/OrderService.pb.h"
#include "lib/orderman/order_factory/IOrderFactory.h"
#include "lib/orderman/orders/algo/algo_orders/tests/limit_cover/LimitCoverTestUtils.h"
#include <functional>
#include <iostream>
#include <optional>
#include <string>
#include <vector>
namespace bts {
namespace orderman {
namespace test {
namespace limit_cover {
std::string ITestStep::name() const { return "step with no name"; }
void ITestStep::execute(LimitCoverState &state) const {
SUMMARIZE(name());
assert_pre_conditions(state);
_execute(state);
assert_post_conditions(state);
}
void ITestStep::assert_pre_conditions_core(const LimitCoverState &) const {}
void ITestStep::execute_core(LimitCoverState &) const { bts_assert(false); }
void ITestStep::assert_post_conditions_core(const LimitCoverState &) const {}
void ITestStep::assert_pre_conditions(const LimitCoverState &state) const {
// SUMMARIZE("Asserting Pre-conditions (", name(), ")...");
assert_pre_conditions_core(state);
}
void ITestStep::assert_post_conditions(const LimitCoverState &state) const {
// SUMMARIZE("Asserting Post-conditions (", name(), ")...");
assert_post_conditions_core(state);
}
void ITestStep::_execute(LimitCoverState &state) const {
// SUMMARIZE("Executing (", name(), ")...");
execute_core(state);
}
std::ostream& operator<<(std::ostream& ostr, const ITestStep& ts) {
ostr << ts.name();
return ostr;
}
LimitCoverState& operator<<(LimitCoverState& state, const ITestStep& ts) {
SUMMARIZE(ts.name());
ts.execute(state);
return state;
}
/////////////////////
// Test Params
/////////////////////
namespace test_params {
namespace fills {
Fill child(const LimitCoverState& state, std::optional<uint32_t> qty, std::optional<double> price) {
if (!qty.has_value()) {
REQUIRE(state.child_state().value().active_qty() > 0);
}
if (!price.has_value()) {
REQUIRE(state.child_state().has_value());
}
return test_params::Fill(
qty.has_value() ? qty.value() : state.child_state().value().active_qty(),
price.has_value() ? price.value() : state.child_state().value().cstate.price.value());
}
} // namespace fills
} // namespace test_params
/////////////////////
// Order Selectors
/////////////////////
namespace order_selectors {
std::vector<OrderKey> child(const LimitCoverState& state) {
std::vector<OrderKey> rv;
if (state.has_been_deployed()) {
rv.push_back(state.child());
}
return rv;
}
std::vector<OrderKey> self(const LimitCoverState&) {
std::vector<OrderKey> rv;
rv.push_back(null_order_key());
return rv;
}
} // namespace order_selectors
/////////////////////////
// Order Ops (step impls)
/////////////////////////
namespace ops {
void begin_launch(LimitCoverState& state) {
REQUIRE(state.driver.before_launch().ok());
}
void launch(LimitCoverState& state) {
state.driver.launch();
}
void breech_activation_thresh(LimitCoverState& state, uint32_t thresh_count, int offset) {
auto book = state.book();
REQUIRE(!os::is_nan(state.limit_price()));
auto gate_it = state.gates().upper_bound(state.limit_volume());
REQUIRE(gate_it != state.gates().end());
while (thresh_count-- > 0 && gate_it != state.gates().end())
gate_it++;
auto thresh = gate_it->first + offset;
int gi = 1;
auto& bs = book.side(state.side());
if (bs[0].size() == 0) {
bs[0] = price_size(state.limit_price(), thresh);
} else if (BookUtils::price_comp(state.side())(state.limit_price(), bs[0].price())) {
// shift existing levels down 1 index,
// put the limit volume at the top
for (int i = bs.size() - 1; i > 0; i--) {
bs[i] = bs[i - 1];
}
bs[0] = price_size(state.limit_price(), thresh);
} else {
// add the difference to the qty for the best price
bs[0] = price_size(bs[0].price(), bs[0].size() + thresh - state.limit_volume());
}
state.book(book);
}
void fill_child(LimitCoverState& state, uint32_t qty, double price, bool allow_overfill) {
SUMMARIZE("filling child: ", Formatter::fmt_order(state.side(), qty, price));
bts_assert(os::is_finite(price));
bts_assert(qty > 0);
REQUIRE(state.has_been_deployed());
REQUIRE(!state.is_terminated());
uint32_t orig_filled_qty = state.driver.total_fills().value();
if (state.child_state().has_value()) {
auto cs = state.child_state().value();
REQUIRE(((cs.cstate.total_fills.value() - cs.cstate.fills_at_attach_time.value()) == orig_filled_qty));
if (!allow_overfill) {
REQUIRE(cs.active_qty() >= qty);
}
} else {
REQUIRE(orig_filled_qty == 0);
}
state.driver.fill(state.child(), Price(price), Quantity(qty));
}
void fill_child(LimitCoverState& lcs, uint32_t qty, bool allow_overfill) {
fill_child(lcs, qty, lcs.limit_price(), allow_overfill);
}
void cancel_child(LimitCoverState& state) {
REQUIRE(state.has_been_deployed());
REQUIRE(!state.is_terminated());
state.driver.cancel_child(state.child());
REQUIRE(state.driver.state() == AlgoState::TERMINATED);
}
void complete(LimitCoverState& state) {
REQUIRE(state.has_been_deployed());
REQUIRE(!state.is_terminated());
REQUIRE(state.driver.quantity().value() > state.driver.total_fills().value());
fill_child(state, state.driver.quantity().value() - state.driver.total_fills().value());
REQUIRE(state.driver.state() == AlgoState::COMPLETED);
}
} // namespace ops
/////////////////////
// Test Steps
/////////////////////
namespace test_steps {
// Begin Launch
std::string BeginLaunch::name() const { return "Begin Launch"; }
void BeginLaunch::execute_core(LimitCoverState &state) const { ops::begin_launch(state); }
// Launch
std::string Launch::name() const { return "Launch"; }
void Launch::execute_core(LimitCoverState &state) const { ops::launch(state); }
// Breech Activation Threshold
std::string BreechActivationThresh::name() const {
std::stringstream title;
title << "Breech Activation Threshold " << (thresh_count + 1);
if (offset > 0) {
title << " (+" << offset << ")";
} else if (offset < 0) {
title << " (" << offset << ")";
}
return title.str();
}
void BreechActivationThresh::execute_core(LimitCoverState &state) const {
ops::breech_activation_thresh(state, thresh_count, offset);
}
// Fill
std::string Fill::name() const { return "Fill"; }
void Fill::execute_core(LimitCoverState &state) const {
auto p = get_params(state);
ops::fill_child(state, p.quantity, p.price);
}
// Complete
std::string Complete::name() const { return "Complete"; }
void Complete::execute_core(LimitCoverState &state) const {
ops::complete(state);
}
// Cancel Child
std::string CancelChild::name() const { return "Cancel Child"; }
void CancelChild::execute_core(LimitCoverState& state) const {
ops::cancel_child(state);
}
// Cancel Algo
std::string CancelAlgo::name() const { return "Cancel Algo"; }
void CancelAlgo::execute_core(LimitCoverState& state) const {
state.driver.cancel();
REQUIRE(state.driver.state() == AlgoState::CANCELED);
}
} // namespace test_steps
} // namespace limit_cover
} // namespace test
} // namespace orderman
} // namespace bts
@@ -1,126 +0,0 @@
#pragma once
#include "catch/catch.hpp"
#include "lib/api/services/OrderService.pb.h"
#include "lib/orderman/orders/algo/algo_orders/tests/limit_cover/LimitCoverState.h"
#include <functional>
#include <iostream>
#include <optional>
#include <string>
#include <vector>
namespace bts {
namespace orderman {
namespace test {
namespace limit_cover {
// In Visual Studio, intellisense and syntax highlighting don't work (at all)
// when <optional> is included, unless 'using namespace std;' is specified.
using namespace std;
struct ITestStep {
virtual std::string name() const;
void execute(LimitCoverState& state) const;
protected:
virtual void assert_pre_conditions_core(const LimitCoverState&) const;
virtual void execute_core(LimitCoverState&) const;
virtual void assert_post_conditions_core(const LimitCoverState&) const;
private:
void assert_pre_conditions(const LimitCoverState& state) const;
void assert_post_conditions(const LimitCoverState& state) const;
void _execute(LimitCoverState& state) const;
};
std::ostream& operator<<(std::ostream& ostr, const ITestStep& ts);
LimitCoverState& operator<<(LimitCoverState& state, const ITestStep& ts);
namespace order_selectors {
std::vector<OrderKey> child(const LimitCoverState &lcs);
std::vector<OrderKey> self(const LimitCoverState &);
} // namespace order_selectors
namespace ops {
void begin_launch(LimitCoverState& lcs);
void launch(LimitCoverState& lcs);
void breech_activation_thresh(LimitCoverState& lcs, uint32_t thresh_count = 0, int offset = 0);
void fill_child(LimitCoverState& lcs, uint32_t qty, double price, bool allow_overfill = false);
void fill_child(LimitCoverState& lcs, uint32_t qty, bool allow_overfill = false);
void cancel_child(LimitCoverState& state);
void complete(LimitCoverState& lcs);
}
namespace test_params {
struct Fill {
uint32_t quantity;
double price;
Fill(uint32_t quantity, double price)
: quantity(quantity), price(price) {}
};
namespace fills {
Fill child(const LimitCoverState& state, optional<uint32_t> qty = {}, optional<double> price = {});
} // namespace fills
} // namespace test_params
namespace test_steps {
struct BeginLaunch : public ITestStep {
std::string name() const override;
void execute_core(LimitCoverState& state) const override;
};
struct Launch : public ITestStep {
std::string name() const override;
void execute_core(LimitCoverState& state) const override;
};
struct BreechActivationThresh : public ITestStep {
uint32_t thresh_count;
int offset;
BreechActivationThresh(uint32_t thresh_count = 0, int offset = 0)
: thresh_count(thresh_count), offset(offset) { }
std::string name() const override;
void execute_core(LimitCoverState& state) const override;
};
struct Fill : public ITestStep {
std::function<test_params::Fill(const LimitCoverState&)> get_params;
Fill(std::function<test_params::Fill(const LimitCoverState&)> get_params)
: get_params(get_params) {}
std::string name() const override;
void execute_core(LimitCoverState& state) const override;
};
struct Complete : public ITestStep {
std::string name() const override;
void execute_core(LimitCoverState& state) const override;
};
struct CancelChild : public ITestStep {
std::string name() const override;
void execute_core(LimitCoverState& state) const override;
};
struct CancelAlgo : public ITestStep {
std::string name() const override;
void execute_core(LimitCoverState& state) const override;
};
struct Custom : public ITestStep {
Custom(std::string name, std::function<void(LimitCoverState&)> impl)
: _name(name), _impl(impl) { }
std::string name() const override { return _name; }
void execute_core(LimitCoverState& state) const override { _impl(state); }
private:
std::string _name;
std::function<void(LimitCoverState&)> _impl;
};
} // namespace test_steps
} // namespace limit_cover
} // namespace test
} // namespace orderman
} // namespace bts
@@ -1,7 +1,7 @@
#include "lib/orderman/orders/spreader_orders/tests/tests_common.h"
#include <time.h>
#include <stdio.h>
#include <boost/container/flat_set.hpp>
namespace bts {
namespace orderman {
@@ -4194,69 +4194,5 @@ TEST_CASE ("scratch_pad_2", "[spreader]"){
struct tm* ptm = gmtime (&rawtime);
LOG(OrderMan, Info, "hrs:{} mins:{} sec:{}", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
}
// vector insert //////////////////////////////////////
///////////////////////////////////////////////////////
class Elem{
public:
int i;
Elem()
:
i(-1)
{}
Elem (int i_arg)
:
i(i_arg)
{}
Elem(const Elem& other){
i = other.i;
}
Elem (Elem&& other){
i=other.i;
}
Elem& operator=(const Elem& other){
i=other.i;
return *this;
}
Elem& operator=(Elem &&src){
i = src.i;
return *this;
}
bool operator==(const Elem& e) const {return i == e.i;}
bool operator!=(const Elem& e) const {return i != e.i;}
bool operator<(const Elem& e) const {return i < e.i;}
bool operator>(const Elem& e) const {return i > e.i;}
};
TEST_CASE ("scratch_pad_3", "[spreader]"){
std::vector<Elem> v;
for(int i=1;i<10;i++)
v.emplace_back(i);
Elem e(0);
// move op= is called when inserting or erasing
v.insert(v.begin()+2,e);
v.erase(v.begin()+2);
std::random_shuffle(v.begin(),v.end());
// flat set
boost::container::flat_set<Elem> fs;
for(int i=0;i<20;i+=2){
Elem e(i);
fs.insert(e);
}
Elem e9(9);
// move op is called when inserting
fs.insert(e9);
for (const auto& e : fs)
std::cout << e.i << std::endl;
// vector assignment vs move assignment
std::vector<Elem> vs;
int n_elems = 10;
for(int i=1;i<n_elems;i++)
vs.emplace_back(i);
std::vector<Elem> vt;
// new elems are cresated in vt from the elem's in vs,
// with their copy cons
vt = vs;
std::vector<Elem> vt_2;
vt_2 = std::move(vs);
}
}}
-5
View File
@@ -9,8 +9,6 @@
#include <boost/dll.hpp>
#include <boost/filesystem.hpp>
extern "C" void init_spark_plugin(bts::SparkServices &serv);
namespace bts {
namespace plugin {
@@ -31,9 +29,6 @@ void init_plugins(SparkServices &services) {
return;
}
// initialize the plugins in libspark.so
init_spark_plugin(services);
boost::filesystem::directory_iterator end;
for (auto iter = boost::filesystem::directory_iterator(plugin_path);
iter != end; ++iter) {
-35
View File
@@ -9,41 +9,6 @@
namespace bts {
namespace meta {
// Instantiate a template with a list of types
template <class... Ts> struct meta_type_pack {
template<template <typename...> class T, class... T2s>
using type = T<T2s...,Ts...>;
};
// Type List Support
template <class... T> struct list;
template <typename Elem, typename List> struct cons;
template <typename Elem, typename... Ts> struct cons<Elem, list<Ts...>> {
using type = list<Elem, Ts...>;
};
template <template <typename> class Pred, typename List> struct filter;
template <template <typename> class Pred> struct filter<Pred, list<>> {
using type = list<>;
};
template <template <typename> class Pred, typename Head, typename... TailTs>
struct filter<Pred, list<Head, TailTs...>> {
using Tail = filter<Pred, list<TailTs...>>;
using type = typename std::conditional<
Pred<Head>::value, cons<Head, typename Tail::type>, Tail>::type::type;
};
template <template <typename...> class Elem, class List> struct with_type_list;
template <template <typename...> class T, typename... Ts>
struct with_type_list<T, list<Ts...>> {
using type = T<Ts...>;
};
// End Type List Support
template<typename T> constexpr size_t max(T v) {return v;}
-50
View File
@@ -11,56 +11,6 @@ double min(std::vector<double> const&v);
double max(std::vector<double> const&v);
double sum(std::vector<double> const&v);
double avg(std::vector<double> const&v);
inline double med(std::vector<double> const&v) {
return percentile(v,0.5);
}
template <class C, class E>
std::vector<double> extract(C const&ts, E const &e) {
std::vector<double> result;
result.reserve(ts.size());
for (auto const&t :ts)
result.push_back(e(t));
return result;
}
template <class C, class E>
double stdev(C const&ts, E const&e) {
return stddev(extract(ts,e));
}
template <class C, class E>
double percentile(C const&ts,E const&e,double p) {
return percentile(extract(ts,e),p);
}
template <class C, class E>
double med(C const&ts,E const&e) {
return med(extract(ts,e));
}
template <class C, class E>
double min(C const&ts, E const&e) {
return min(extract(ts,e));
}
template <class C, class E>
double max(C const&ts, E const&e) {
return max(extract(ts,e));
}
template <class C, class E>
double sum(C const&ts, E const&e) {
return sum(extract(ts,e));
}
template <class C, class E>
double avg(C const&ts, E const&e) {
return avg(extract(ts,e));
}
}}
+1 -1
View File
@@ -1 +1 @@
set(sources algo/AlgoDefinitionServiceServer.cpp;cmds/AdminReport.cpp;cmds/AutoCert.cpp;cmds/Benchmark.cpp;cmds/CMECertCmd.cpp;cmds/CmdRegistry.cpp;cmds/ConfigCheck.cpp;cmds/FIXSim.cpp;cmds/Help.cpp;cmds/KeyCode.cpp;cmds/Md.cpp;cmds/ParseHistoricalFIX.cpp;cmds/PrintHedgeOrders.cpp;cmds/QuickTest.cpp;cmds/Run.cpp;cmds/Span.cpp;cmds/Spartan.cpp;cmds/Test.cpp;cmds/Web.cpp;cmds/spartan/algo/RunTAS.cpp;cmds/spartan/algo/TASOrderReactor.cpp;cmds/spartan/algo/TASTriggerDef.cpp;cmds/spartan/md/mdp3/back_testing/FifoPriceLevelMatcher.cpp;cmds/spartan/md/mdp3/back_testing/FifoSecurityMatcher.cpp;cmds/spartan/md/mdp3/common/InstrumentSnapshot.cpp;cmds/spartan/md/mdp3/feed_control/IFeedController.cpp;cmds/spartan/md/mdp3/handler/ChannelHandler.cpp;cmds/spartan/md/mdp3/parsing/MDP3MsgBox.cpp;cmds/spartan/md/mdp3/realtime/RealTimeHandler.cpp;cmds/spartan/md/mdp3/recovery/BookSnapshot.cpp;cmds/spartan/md/mdp3/recovery/DefinitionSnapshot.cpp;cmds/spartan/md/mdp3/recovery/IncrementalQueue.cpp;cmds/spartan/md/mdp3/recovery/RecoveryHandler.cpp;cmds/spartan/md/mdp3/tests/spartan_md_tests.cpp;cmds/spartan/md/mdp3/utils/mdp3_utils.cpp;cmds/spartan/util/MCastReceiver.cpp;cmds/spartan/util/PCapReader.cpp;cmds/spartan/util/SecurityDB.cpp;dspark/mirage/quick_queue/quick_queue.cpp;exchange_sim/ExchangeSim.cpp;exchange_sim/ExchangeSimApplication.cpp;exchange_sim/book/Book.cpp;exchange_sim/book/ExchangeSim.proto;exchange_sim/book/Order.cpp;exchange_sim/book/OrderMatcher.cpp;exchange_sim/book/book_transform.cpp;exchange_sim/tests/test_book_transform.cpp;http/ApiGateway.cpp;http/MultipartFormDecoder.cpp;http/WebServer.cpp;http/tests/MultiPartFormTests.cpp;main.cpp;md/ChannelVolume.cpp;md/MarketDataAuxiliaryServiceServer.cpp;md/VolumeAtPriceState.cpp;md/platforms/IMDPlatform.cpp;md/platforms/ice_onixs/ICEListener.cpp;md/platforms/ice_onixs/ICEMain.cpp;md/platforms/ice_onixs/tests/ice_tests.cpp;md/platforms/mdp3_onixs/MDP3Listener.cpp;md/platforms/mdp3_onixs/MDP3Main.cpp;md/platforms/mdp3_onixs/tests/mdp3_tests.cpp;md/run_md.cpp;position/IPositionObserver.cpp;position/MarginServiceCore.cpp;position/MarginServiceServer.cpp;position/PositionAggregator.cpp;position/PositionMap.cpp;position/PositionServicePNLHelper.cpp;position/PositionServiceServer.cpp;position/import/BasePositionServiceServer.cpp;position/import/DownloadCommonStateMachine.cpp;position/import/DownloadWindow.cpp;position/import/MoneyFileServiceServer.cpp;position/import/parsing/gmi_parser.cpp;position/import/parsing/money_parser.cpp;position/import/parsing/parser_common.cpp;position/tests/PositionTests.cpp;position/tests/position_tests_internal.cpp;subprocess/SubProcessRunner.cpp;support/ErrorReportService.cpp;support/ShellLatencyServer.cpp;user/AdminServiceDB.cpp;user/AdminServiceServer.cpp;user/AuthServiceServer.cpp;user/tests/admin_service_tests.cpp)
set(sources algo/AlgoDefinitionServiceServer.cpp;cmds/AdminReport.cpp;cmds/AutoCert.cpp;cmds/Benchmark.cpp;cmds/CMECertCmd.cpp;cmds/CmdRegistry.cpp;cmds/ConfigCheck.cpp;cmds/FIXSim.cpp;cmds/Help.cpp;cmds/KeyCode.cpp;cmds/Md.cpp;cmds/ParseHistoricalFIX.cpp;cmds/PrintHedgeOrders.cpp;cmds/QuickTest.cpp;cmds/Run.cpp;cmds/RunSim.cpp;cmds/Span.cpp;cmds/Test.cpp;cmds/Web.cpp;dspark/mirage/quick_queue/quick_queue.cpp;exchange_sim/ExchangeSim.cpp;exchange_sim/ExchangeSimApplication.cpp;exchange_sim/book/Book.cpp;exchange_sim/book/ExchangeSim.proto;exchange_sim/book/Order.cpp;exchange_sim/book/OrderMatcher.cpp;exchange_sim/book/book_transform.cpp;exchange_sim/tests/test_book_transform.cpp;http/ApiGateway.cpp;http/MultipartFormDecoder.cpp;http/WebServer.cpp;http/tests/MultiPartFormTests.cpp;main.cpp;md/ChannelVolume.cpp;md/MarketDataAuxiliaryServiceServer.cpp;md/VolumeAtPriceState.cpp;md/platforms/IMDPlatform.cpp;md/platforms/ice_onixs/ICEListener.cpp;md/platforms/ice_onixs/ICEMain.cpp;md/platforms/ice_onixs/tests/ice_tests.cpp;md/platforms/mdp3_onixs/MDP3Listener.cpp;md/platforms/mdp3_onixs/MDP3Main.cpp;md/platforms/mdp3_onixs/tests/mdp3_tests.cpp;md/run_md.cpp;position/IPositionObserver.cpp;position/MarginServiceCore.cpp;position/MarginServiceServer.cpp;position/PositionAggregator.cpp;position/PositionMap.cpp;position/PositionServicePNLHelper.cpp;position/PositionServiceServer.cpp;position/import/BasePositionServiceServer.cpp;position/import/DownloadCommonStateMachine.cpp;position/import/DownloadWindow.cpp;position/import/MoneyFileServiceServer.cpp;position/import/parsing/gmi_parser.cpp;position/import/parsing/money_parser.cpp;position/import/parsing/parser_common.cpp;position/tests/PositionTests.cpp;position/tests/position_tests_internal.cpp;subprocess/SubProcessRunner.cpp;support/ErrorReportService.cpp;support/ShellLatencyServer.cpp;user/AdminServiceServer.cpp;user/AuthServiceServer.cpp;user/tests/admin_service_tests.cpp)
+7 -7
View File
@@ -19,22 +19,22 @@ target_include_directories( sparkd PUBLIC ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY
set_source_files_properties(exchange_sim/ExchangeSim.cpp PROPERTIES COMPILE_FLAGS --std=c++14)
set_source_files_properties(exchange_sim/ExchangeSimApplication.cpp PROPERTIES COMPILE_FLAGS --std=c++14)
if (${USE_ONIX})
set(ONIX_LIBS, "onixs-cmemdh-all-4.8.0 OnixS.IceImpactMulticastPriceFeedHandlerCpp ACE")
else()
set(ONIX_LIBS, "")
endif()
# linking
target_link_libraries( sparkd
libspark
ssl
cryptopp
tbb
onixs-cmemdh-all-4.8.0
OnixS.IceImpactMulticastPriceFeedHandlerCpp
ACE
quickfix
benchmark
Common++
Packet++
Pcap++
${ONIX_LIBS}
lttng-ust
-lpcap
-static-libgcc
-static-libstdc++
-pthread)
+1 -1
View File
@@ -5,7 +5,7 @@ namespace bts {
namespace cmd {
int FIXSim::execute(std::vector<std::string> const &) {
bts::sim::start_exchange_sim(bts::api::Venue::VENUE_SIM);
bts::sim::start_exchange_sim(bts::api::Venue::VENUE_GLBX);
return 0;
}
+14 -78
View File
@@ -6,20 +6,8 @@
#include "lib/tracing/PerfLog.h"
#include "lib/utils/datetime.h"
#include "lib/config/protos/logging.pb.h"
#include "lib/domain_model/sod.h"
#include "lib/logging/logging.h"
#include "lib/utils/datetime.h"
#include "server/sparkd/cmds/spartan/md/mdp3/common/InstrumentSnapshot.h"
#include "server/sparkd/cmds/spartan/md/mdp3/common/mdp3_common.h"
#include "server/sparkd/cmds/spartan/md/mdp3/feed_control/AB_Arbitrageur.h"
#include "server/sparkd/cmds/spartan/md/mdp3/feed_control/IFeedController.h"
#include "server/sparkd/cmds/spartan/md/mdp3/handler/ChannelHandler.h"
#include "server/sparkd/cmds/spartan/md/mdp3/handler/IChannelObserver.h"
#include "server/sparkd/cmds/spartan/md/mdp3/parsing/MDP3Parser.h"
#include "server/sparkd/cmds/spartan/md/mdp3/utils/mdp3_utils.h"
#include "server/sparkd/cmds/spartan/util/PCapReader.h"
#include <boost/algorithm/string.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
@@ -28,78 +16,26 @@
namespace bts {
namespace cmd {
using namespace bts::orderman;
int QuickTest::execute(std::vector<std::string> const &args) {
int QuickTest::execute(std::vector<std::string> const &) {
auto cfg = config::get<config::Logging>();
cfg.mutable_console()->set_default_level("Fatal");
log::configure_logging(cfg);
auto sftp_file_name = std::string("2019-08-05.adatmny.csv");
std::regex rx("(\\d\\d\\d\\d)");
std::smatch matches;
if (!std::regex_match(sftp_file_name, matches, rx))
return {};
auto y = std::stoi(matches[0]);
auto m = std::stoi(matches[1]);
auto d = std::stoi(matches[2]);
auto file = args[0];
using namespace bts::spartan::mdp3;
struct Obs : IChannelObserver {
Orders previous_orders;
size_t event_id = 0;
void on_recovery_complete(
std::vector<InstrumentSnapshot const *> const &secs) override {
previous_orders.clear();
for (auto s : secs)
for (auto const &o : s->orders())
previous_orders[o.first] = o.second;
}
void on_real_time_event(MDP3Event const &ev) override {
event_id++;
for (auto s : ev.affected_securities) {
if (s->trading_status() ==
::mdp3::SecurityTradingStatus::ReadyToTrade) {
for (auto f : s->fills()) {
if (f.aggressor != MDP3Fill::THIS_BUY &&
f.aggressor != MDP3Fill::THIS_SELL) {
auto it = previous_orders.find(f.key);
bts_assert(it != previous_orders.end());
it->second.quantity.value() -= f.quantity.value();
if (it->second.quantity.value() < 0) {
std::cout << " Hidden sizes in order. "
<< " eid: " << event_id
<< " Event: " << ev
<< " Order: " << it->first
<< " Fill tid: " << f.trade_entry_id
<< std::endl;
}
}
}
}
for (auto const &ch : s->order_changes()) {
switch (ch.change) {
case OrderChange::added:
case OrderChange::updated:
previous_orders[ch.order.key] = ch.order;
break;
case OrderChange::removed:
previous_orders.erase(ch.order.key);
break;
}
}
}
}
void on_real_time_channel_loss() override {
std::cout << "Observed loss, resetting\n";
}
} obs;
spartan::mdp3::observe_channel(file, obs);
return 0;
const auto &sod = config::get<config::SODTime>();
std::cout << datetime::make_ptime(y, m, d, sod.sod_hh(), sod.has_sod_mm(), 0, 0) << "\n";
return 1;
}
std::string QuickTest::help() {
return "This is a place holder to make it easy to quickly write "
"discardable "
return "This is a place holder to make it easy to quickly write discardable "
"test code";
}
} // namespace cmd
+15
View File
@@ -0,0 +1,15 @@
#include "RunSim.h"
#include "server/sparkd/exchange_sim/ExchangeSim.h"
namespace bts {
namespace cmd {
int RunSim::execute(std::vector<std::string> const &)
{
sim::start_exchange_sim(api::Venue::VENUE_SIM, nullptr);
return 0;
}
std::string RunSim::help () {return "\t run exchange simulator";}
}}
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include "ICmd.h"
namespace bts {
namespace cmd {
class RunSim : public ICmd
{
public:
int execute(std::vector<std::string> const &args);
std::string help ();
};
}}
-42
View File
@@ -1,42 +0,0 @@
#include "Spartan.h"
#include "server/sparkd/cmds/spartan/algo/RunTAS.h"
#include "server/sparkd/cmds/spartan/md/mdp3/common/InstrumentSnapshot.h"
#include "server/sparkd/cmds/spartan/md/mdp3/feed_control/AB_Arbitrageur.h"
#include "server/sparkd/cmds/spartan/md/mdp3/feed_control/IFeedController.h"
#include "server/sparkd/cmds/spartan/md/mdp3/feed_control/PickedFeed.h"
#include "server/sparkd/cmds/spartan/md/mdp3/handler/ChannelHandler.h"
#include "server/sparkd/cmds/spartan/md/mdp3/handler/IChannelObserver.h"
#include "server/sparkd/cmds/spartan/md/mdp3/utils/mdp3_utils.h"
#include "server/sparkd/cmds/spartan/util/PCapReader.h"
#include <Pcap++/PcapFileDevice.h>
#include <fmt/format.h>
#include <fstream>
#include <iostream>
namespace bts {
namespace cmd {
int Spartan::execute(std::vector<std::string> const &args) {
auto error = 1;
if (args.size() > 0) {
if (args[0] == "json" && args.size() == 2)
error = spartan::mdp3::to_json(args[1]);
else if (args[0] == "compress" && args.size() == 3)
error = spartan::mdp3::compress(args[1],args[2]);
else if (args[0] == "csv" && args.size() == 3)
error = spartan::mdp3::to_csv(args[1], args[2]);
}
if (error)
std::cout << help();
return error;
}
std::string Spartan::help() {
return fmt::format("\tjson <pcap>\n"
"\tcompress <pcap> <out-pcap>\n"
"\tcsv <pcap> <out-dir>\n");
}
} // namespace cmd
} // namespace bts
-23
View File
@@ -1,23 +0,0 @@
#pragma once
#include "ICmd.h"
namespace bts {
namespace cmd {
class Spartan : public ICmd
{
public:
int execute(std::vector<std::string> const &args);
std::string help ();
private:
int run_from_pcap(std::vector<std::string> const &);
int run_from_mcast(std::vector<std::string> const &);
int parse_pcap(std::vector<std::string> const &);
int analyze_pcap(std::vector<std::string> const &);
void run(std::vector<std::string> const &);
};
}}
@@ -1,243 +0,0 @@
// #include "RunTAS.h"
// #include "server/sparkd/cmds/Run.h"
// #include "../analysis/ActionableEventAnalyzer.h"
// #include "../md/mdp3/parsing/MDP3Parser.h"
// #include "../util/MCastReceiver.h"
// #include "../util/PCapReader.h"
// #include "../util/SecurityDB.h"
// #include "TASOrderReactor.h"
// #include "TASTriggerDef.h"
// #include "lib/api/service_helpers/AdminServiceUtils.h"
// #include "lib/config/config.h"
// #include "lib/config/protos/spartan.pb.h"
// #include "lib/logging/logging.h"
// #include "lib/md/cme/MDP3Utils.h"
// #include "lib/utils/bts_chrono.h"
// #include "server/sparkd/cmds/Run.h"
// #include "server/sparkd/user/AdminServiceDB.h"
// #include <boost/asio.hpp>
// #include <variant>
// namespace bts {
// namespace spartan {
// // Resolve securities and routing records to go from config to a set
// // of trigger definitions, one per security group needed.
// std::vector<TASTriggerDef>
// build_trigger_defs(SecurityDB &db, config::SpartanTASCfg const &cfg) {
// auto user_name = cfg.user();
// auto account = cfg.account();
// auto admin = admin::AdminServiceDB().retrieve();
// bts_assert(admin.has_value());
// std::vector<TASTriggerDef> result;
// auto get_or_make_group_trigger_def =
// [&result](std::string const &group_symbol) {
// for (auto &t : result)
// if (t.group_symbol == group_symbol)
// return &t;
// result.push_back(TASTriggerDef{group_symbol, {}});
// return &result.back();
// };
// for (auto const &t : cfg.tas_trigger()) {
// // Resolve symbol to security object
// auto sec = db.query_single([t](auto const &sec) {
// return sec.has_glbx() &&
// securities::security_type(sec) == t.security_type() &&
// securities::descriptor(sec) == t.security();
// });
// bts_assert(sec);
// // Get routing record for this user and account
// admin::AdminServiceOperationResult result;
// auto rr = admin::AdminServiceUtils::get_routing_record(
// admin.value(), account, user_name, *sec, result);
// bts_assert_msg(result.is_success(), result.error_text());
// // Build a trigger definition with the resolved information
// // (security and routing record)
// auto sec_trigger = TASTriggerDef::SecTrigger{*sec, rr, {}};
// sec_trigger.side.set(
// api::Side::SIDE_BUY,
// TASTriggerDef::Side{t.buy().quantity(), t.buy().ticks_away()});
// sec_trigger.side.set(
// api::Side::SIDE_SELL,
// TASTriggerDef::Side{t.sell().quantity(), t.sell().ticks_away()});
// auto trigger = get_or_make_group_trigger_def(sec->glbx().cme_symbol());
// trigger->sec_triggers.push_back(sec_trigger);
// }
// return result;
// }
// std::variant<bool, std::string>
// validate_trigger_defs(std::vector<TASTriggerDef> const &defs) {
// if (defs.empty())
// return fmt::format("No triggers defined");
// std::set<std::string> groups;
// std::set<SecurityKey> securities;
// for (auto const &td : defs) {
// if (!groups.insert(td.group_symbol).second)
// return fmt::format("Duplicate entry for security group: {}",
// td.group_symbol);
// else
// groups.insert(td.group_symbol);
// for (auto const &st : td.sec_triggers) {
// if (!securities.insert(SecurityKey(st.security.id())).second)
// return fmt::format("Duplicate entry for security: {}",
// securities::descriptor(st.security));
// if (st.side.get(api::Side::SIDE_BUY).quantity != 1 ||
// st.side.get(api::Side::SIDE_SELL).quantity != 1)
// return fmt::format("Quantities must be 1 in {}",
// securities::descriptor(st.security));
// if (st.side.get(api::Side::SIDE_BUY).ticks_away > 0)
// return fmt::format("Buy Price must be <= 0 in {}",
// securities::descriptor(st.security));
// if (st.side.get(api::Side::SIDE_SELL).ticks_away <= 0)
// return fmt::format("Sell Price must be > 0 in {}",
// securities::descriptor(st.security));
// }
// }
// return true;
// }
// std::vector<TASTriggerDef> build_and_validate_triggers(SecurityDB &db) {
// auto triggers = build_trigger_defs(db, config::get<config::SpartanTASCfg>());
// LOG(Spartan, Info,
// "TAS Trigger layout: \n"
// "-----------------------------------------------------------"
// "---------------------");
// for (auto const &t : triggers)
// LOG(Spartan, Info, "{}", t);
// LOG(Spartan, Info,
// "-----------------------------------------------------------"
// "---------------------");
// auto valid = validate_trigger_defs(triggers);
// if (std::holds_alternative<std::string>(valid)) {
// LOG(Spartan, Error, "Invalid TAS trigger definition in config: {}",
// std::get<std::string>(valid));
// std::exit(-1);
// }
// return triggers;
// }
// std::set<bts::md::UserSymbol> get_symbols(SecurityDB &db,
// config::SpartanTASCfg const &cfg) {
// std::set<bts::md::UserSymbol> result;
// for (auto const &t : cfg.tas_trigger()) {
// auto sec = db.query_single([&t](auto const &sec) {
// return sec.has_glbx() &&
// securities::security_type(sec) == t.security_type() &&
// securities::descriptor(sec) == t.security();
// });
// bts_assert(sec);
// result.insert({sec->symbol(), api::Venue::VENUE_GLBX,
// api::SecurityType::SECURITYTYPE_FUTURE});
// }
// return result;
// }
// std::vector<bts::md::CMEConnection> get_connections(SecurityDB &db) {
// auto cfg = config::get<config::SpartanTASCfg>();
// auto cme_symbols = get_symbols(db, cfg);
// std::vector<bts::md::CMEConnection> result;
// auto find_inc_feed_connection =
// [](std::map<std::string, bts::md::CMEConnection> const &m)
// -> bts::md::CMEConnection {
// for (auto const &p : m) {
// if (p.second.feed_type == "I" && p.second.feed == 'A')
// return p.second;
// }
// bts_assert(false);
// return {};
// };
// auto channels = bts::md::get_configured_cme_channels();
// for (auto const &c : channels) {
// for (auto const &sym : cme_symbols) {
// if (c.symbols.count(sym))
// result.push_back(find_inc_feed_connection(c.connections));
// }
// }
// return result;
// }
// int run_tas_from_mcast() {
// SecurityDB db;
// auto triggers = build_and_validate_triggers(db);
// auto connections = get_connections(db);
// if (connections.empty()) {
// LOG(Spartan, Error,
// "Could not find connections for selected TAS symbols");
// std::exit(1);
// }
// boost::asio::io_service io;
// mdp3::MDP3Parser parser;
// TASOrderReactor reactor(triggers);
// mdp3::bind<TASOrderReactor, ::mdp3::SecurityStatus30>(parser, reactor);
// std::vector<std::unique_ptr<MCastReceiver>> mc_receivers;
// for (auto const &c : connections) {
// auto receiver =
// std::make_unique<MCastReceiver>(io, "0.0.0.0", c.ip, c.port);
// receiver->on_receive() = [&parser](auto const &bytes) {
// parser.on_bytes(bytes);
// };
// mc_receivers.push_back(std::move(receiver));
// }
// LOG(Spartan, Warn, "Starting Spartan TAS Algo now");
// for (auto &c : connections) {
// LOG(Spartan, Info, "Listening on {}", c);
// }
// for (;;) {
// io.poll();
// if (!reactor.do_work())
// break;
// }
// LOG(Spartan, Warn, "Spartan TAS algo concluded. Starting normal system");
// return cmd::Run{}.execute({});
// }
// int run_tas_from_pcap(std::string const &pcap_path) {
// SecurityDB db;
// auto triggers = build_and_validate_triggers(db);
// TASOrderReactor reactor(triggers);
// PCapReader pcap_reader(pcap_path);
// mdp3::MDP3Parser parser;
// mdp3::bind<TASOrderReactor, ::mdp3::SecurityStatus30>(parser, reactor);
// pcap_reader.on_packet() = [&parser](auto const&, auto const &bytes) {
// parser.on_bytes(bytes);
// return true;
// };
// while (pcap_reader.read_next())
// if (!reactor.do_work())
// break;
// // this is to allow a little bit of time for FIX and other logs to
// // be written to disk
// std::this_thread::sleep_for(1s);
// return 0;
// }
// } // namespace spartan
// } // namespace bts
@@ -1,11 +0,0 @@
#pragma once
#include <string>
namespace bts {
namespace spartan {
inline int run_tas_from_pcap(std::string const&) {return -1;}
inline int run_tas_from_mcast() {return -1;}
}}
@@ -1,182 +0,0 @@
#include "TASOrderReactor.h"
#include "TASTriggerDef.h"
#include "lib/config/config.h"
#include "lib/domain_model/SecurityKey.h"
#include "lib/jetfix/common/OutFIX.h"
#include "lib/jetfix/common/OutFIXPtr.h"
#include "lib/jetfix/gateway/JetFIXGateway.h"
#include "lib/orderman/order_factory/OrderFactory.h"
#include "lib/orderman/orderman_utils/fix_order_codec.h"
#include "../md/mdp3/parsing/MDP3Parser.h"
#include "../md/mdp3/gen/SecurityStatus30.h"
#include <boost/container/small_vector.hpp>
namespace bts::spartan {
using JFGW = jetfix::JetFIXGateway<>;
struct TASOrderReactor::GatewayReactor {
jetfix::OutFIXPtr fix;
JFGW *gw;
};
struct TASOrderReactor::GroupReactor {
std::string group;
boost::container::small_vector<GatewayReactor, 4> gw_reactors;
};
struct TASOrderReactor::PImpl {
trace::PerfLog perf_log;
std::vector<std::unique_ptr<JFGW>> gw;
int pending_logins = 0;
int pending_reactions = 0;
int pending_logouts = 0;
std::vector<GroupReactor> group_reactors;
};
TASOrderReactor::TASOrderReactor(std::vector<TASTriggerDef> const &triggers)
: me(new PImpl()) {
// Organize our reactors by group->gw
for (auto &group_trigger : triggers) {
for (auto &sec_trigger : group_trigger.sec_triggers) {
auto &group_reactor = get_group_reactor(group_trigger.group_symbol);
auto &gw_reactor = get_gw_reactor(
group_reactor, sec_trigger.routing_record.session());
prepare_side(api::Side::SIDE_BUY, sec_trigger, &gw_reactor);
prepare_side(api::Side::SIDE_SELL, sec_trigger, &gw_reactor);
}
}
for (auto &group_r : me->group_reactors)
for (auto &gw_r : group_r.gw_reactors)
gw_r.fix->close_all();
me->pending_logins = me->gw.size();
me->pending_reactions = me->group_reactors.size();
for (auto &p : me->gw) {
p->on_ready() = [this] { me->pending_logins--; };
p->on_disconnect() = [] { bts_assert(false); };
p->start();
}
while (me->pending_logins)
do_work();
}
TASOrderReactor::~TASOrderReactor() {
me->pending_logouts = me->gw.size();
for (auto &p : me->gw) {
p->on_disconnect() = [this] { me->pending_logouts--; };
p->stop();
}
while (me->pending_logouts)
do_work();
}
bool TASOrderReactor::do_work() {
for (auto &p : me->gw)
p->dispatch_events();
return me->pending_reactions;
}
void TASOrderReactor::operator()(mdp3::MDP3PacketView const &,
::mdp3::SecurityStatus30 const &status) {
for (auto &r : me->group_reactors) {
if (status.getSecurityGroupAsStringView() == r.group) {
for (auto &gr : r.gw_reactors) {
gr.gw->send(gr.fix, {});
}
r.group.clear();
me->pending_reactions--;
}
}
}
JFGW &TASOrderReactor::get_gw(std::string const &session_name) {
for (auto &p : me->gw)
if (p->cfg().name() == session_name)
return *p;
me->gw.push_back(
std::make_unique<JFGW>(get_connection(session_name), me->perf_log));
return *me->gw.back();
}
TASOrderReactor::GroupReactor &
TASOrderReactor::get_group_reactor(std::string const &group) {
for (auto &group_r : me->group_reactors)
if (group_r.group == group)
return group_r;
me->group_reactors.push_back({group, {}});
return me->group_reactors.back();
}
TASOrderReactor::GatewayReactor &
TASOrderReactor::get_gw_reactor(GroupReactor &in_group,
std::string const &session_name) {
for (auto &gw_r : in_group.gw_reactors)
if (gw_r.gw->cfg().name() == session_name)
return gw_r;
auto &gw = get_gw(session_name);
auto fix = std::make_shared<jetfix::OutFIX>(gw.cfg());
in_group.gw_reactors.push_back({fix, &gw});
return in_group.gw_reactors.back();
}
void TASOrderReactor::prepare_side(api::Side side,
TASTriggerDef::SecTrigger const &sec_trigger,
GatewayReactor *out) {
auto &sec = sec_trigger.security;
auto &rr = sec_trigger.routing_record;
auto &fix =
out->fix->first_stream().new_msg(jetfix::MessageTypes::NewOrderSingle);
using namespace jetfix;
fix.add<fix::SenderSubID>(rr.operator_id());
fix.add<fix::SenderLocationID>(rr.location());
fix.add<fix::Account>(rr.account());
fix.add<fix::Side>(side);
fix.add<fix::TimeInForce>(api::orderman::TimeInForce::TIME_IN_FORCE_DAY);
fix.add<fix::ManualOrderIndicator>(false);
fix.add<fix::CustomerOrFirm>(
api::orderman::CustomerOrFirm::CUSTOMER_OR_FIRM_CUSTOMER);
fix.add<fix::CtiCode>(api::orderman::CTICode::CTI_CODE_CTI_CODE1);
fix.add<fix::SecurityDesc>(sec.glbx().security_desc());
auto k = orderman::gen_order_id();
std::string clordid(orderman::clordid_sz(), ' ');
orderman::encode_clorid(k, SecurityKey(sec.id()), &clordid);
fix.add<fix::ClOrdID>(clordid);
fix.add<fix::CustOrderHandlingInst>(std::string_view{"Y"});
if (rr.smp_id().size()) {
fix.add<fix::SelfMatchPreventionID>(rr.smp_id());
if (rr.smp_instruction() !=
api::orderman::SELF_MATCH_PREVENTION_INSTRUCTION_UNDEFINED)
fix.add<fix::SelfMatchPreventionInstruction>(rr.smp_instruction());
}
fix.add<fix::TransactTimeStr>(datetime::FIX_timestamp(datetime::now()));
fix.add<fix::OrderQty>(sec_trigger.side.get(side).quantity);
fix.add<fix::OrdType>(
api::orderman::NativeOrderType::NATIVE_ORDER_TYPE_LIMIT);
fix.add<fix::Price>(sec_trigger.side.get(side).ticks_away, 7, -1);
}
config::JetFIX::Connection
TASOrderReactor::get_connection(std::string const &session_name) {
for (auto const &cfg : config::get<config::JetFIX>().connection())
if (cfg.name() == session_name)
return cfg;
bts_assert(false);
return config::JetFIX::Connection{};
}
} // namespace bts::spartan
@@ -1,46 +0,0 @@
#pragma once
#include "lib/config/protos/jetfix.pb.h"
#include <memory>
#include <string>
#include <vector>
#include "TASTriggerDef.h"
namespace mdp3 {
class SecurityStatus30;
}
namespace bts {
namespace jetfix {
template <class...> class JetFIXGateway;
}
} // namespace bts
namespace bts::spartan {
namespace mdp3 {class MDP3PacketView;}
class TASOrderReactor {
public:
TASOrderReactor(std::vector<TASTriggerDef> const &);
~TASOrderReactor();
bool do_work();
void operator()(mdp3::MDP3PacketView const &packet,
::mdp3::SecurityStatus30 const &status);
private:
struct PImpl;
struct GatewayReactor;
struct GroupReactor;
using JFGW = jetfix::JetFIXGateway<>;
std::unique_ptr<PImpl> me;
GroupReactor &get_group_reactor(std::string const &group);
GatewayReactor &get_gw_reactor(GroupReactor &,
std::string const &session_name);
void prepare_side(api::Side side, TASTriggerDef::SecTrigger const &,
GatewayReactor *);
JFGW &get_gw(std::string const &);
config::JetFIX::Connection get_connection(std::string const &session_name);
};
}
@@ -1,18 +0,0 @@
#include "TASTriggerDef.h"
namespace bts {
namespace spartan {
std::ostream& operator<<(std::ostream&out, TASTriggerDef const&def) {
out << "group: " << def.group_symbol << "\n";
for (auto const &st : def.sec_triggers) {
out << "\tsec: " << securities::descriptor(st.security) << "\n"
<< "\tbuy: " << st.side.get(api::Side::SIDE_BUY).quantity << "@"
<< st.side.get(api::Side::SIDE_BUY).ticks_away << "\n"
<< "\tsell: " << st.side.get(api::Side::SIDE_SELL).quantity << "@"
<< st.side.get(api::Side::SIDE_SELL).ticks_away << "\n\n";
}
return out;
}
}}
@@ -1,27 +0,0 @@
#pragma once
#include <string>
#include "lib/domain_model/Security.pb.h"
#include "lib/api/services/OrderService.pb.h"
#include "lib/domain_model/Security.h"
namespace bts {
namespace spartan {
struct TASTriggerDef {
std::string group_symbol;
struct Side {
uint32_t quantity;
int32_t ticks_away;
};
struct SecTrigger {
api::Security security;
api::orderman::RoutingRecord routing_record;
securities::TwoSided<Side> side;
};
std::vector<SecTrigger> sec_triggers;
};
std::ostream& operator<<(std::ostream&, TASTriggerDef const&);
}}
@@ -1,135 +0,0 @@
#include "FifoPriceLevelMatcher.h"
#include "../common/InstrumentSnapshot.h"
namespace bts::spartan::mdp3 {
// private helpers ////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void FifoPriceLevelMatcher::_compress(){
_orders.erase(
std::remove_if(_orders.begin(),
_orders.end(),
[](const Order& o) { return !o.is_active; }),
_orders.end());
}
FifoPriceLevelMatcher::Order*
FifoPriceLevelMatcher::_find(MDP3OrderKey key){
for(auto& o : _orders)
if(o.key == key)
return &o;
return nullptr;
}
void FifoPriceLevelMatcher::_logically_delete(Order& o){
o.is_active = false;
}
void FifoPriceLevelMatcher::_add_order(MDP3OrderKey key,
MDP3OrderPriority priority,
MDP3Quantity quantity){
// assert for this priority to be higher than last element
//bts_assert(priority.value() > _lowest_priority.value());
_orders.emplace_back(key, priority, quantity);
_lowest_priority = priority;
}
FifoPriceLevelMatcher::FifoPriceLevelMatcher (
md::IntPrice price,
api::Side side)
:
_price(price),
_side(side),
_lowest_priority(0),
_orders()
{}
// constructors ///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
FifoPriceLevelMatcher::FifoPriceLevelMatcher (
const FifoPriceLevelMatcher& o){
*this = o;
}
FifoPriceLevelMatcher::FifoPriceLevelMatcher (FifoPriceLevelMatcher&& o){
*this = std::move(o);
}
// operator overloads /////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
FifoPriceLevelMatcher& FifoPriceLevelMatcher::operator=(
const FifoPriceLevelMatcher& o){
_price = o._price;
_side = o._side;
_lowest_priority = o._lowest_priority;
_orders = o._orders;
return *this;
}
FifoPriceLevelMatcher& FifoPriceLevelMatcher::operator=(
FifoPriceLevelMatcher&& o){
_price = std::move(o._price);
_side = std::move(o._side);
_lowest_priority = std::move(o._lowest_priority);
_orders = std::move(o._orders);
return *this;
}
bool FifoPriceLevelMatcher::operator<(const FifoPriceLevelMatcher& o) const {
bts_assert(_side == o._side);
// bid book is sorted high to low (since highest is the top of the book)
return _side == api::Side::SIDE_SELL ? _price < o._price :
o._price < _price;
}
// order interactions //////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
void FifoPriceLevelMatcher::on_new_same_side_order(const MDP3Order& new_ord){
bts_assert(new_ord.price == _price);
bts_assert(new_ord.side == _side);
_add_order(new_ord.key, new_ord.priority, new_ord.quantity);
}
void FifoPriceLevelMatcher::on_order_update(const MDP3Order& upd_ord){
bts_assert(upd_ord.side == _side);
bts_assert(upd_ord.price == _price);
FifoPriceLevelMatcher::Order* ord_p = _find(upd_ord.key);
bts_assert(ord_p != nullptr);
if(upd_ord.quantity.value() > ord_p->quantity.value()){
// remove it from the current location and add it to
// the end
_logically_delete(*ord_p);
_add_order(upd_ord.key, upd_ord.priority, upd_ord.quantity);
}
else
ord_p->quantity = upd_ord.quantity;
_compress();
}
void FifoPriceLevelMatcher::on_order_remove(MDP3OrderKey k){
FifoPriceLevelMatcher::Order* ord_p = _find(k);
bts_assert(ord_p != nullptr);
_logically_delete(*ord_p);
_compress();
}
MDP3Quantity FifoPriceLevelMatcher::on_new_opp_order(MDP3Quantity opp_ord_qty){
auto rem = opp_ord_qty.value();
// go through all the orders and see which ones get filled
// (orders are sorted by priority)
for(auto& o : _orders){
if(o.is_active){
if(rem >= o.quantity.value()){
// existing order gets completely crossed
_logically_delete(o);
rem -= o.quantity.value();
}
else{
// the remaining qty of the order
// gets completely crossed now
bts_assert(o.quantity.value() > rem);
o.quantity = MDP3Quantity(o.quantity.value() - rem);
rem = 0;
}
}
if(rem == 0)
break;
}
_compress();
bts_assert(rem <= opp_ord_qty.value());
return MDP3Quantity(rem);
}
}
@@ -1,101 +0,0 @@
#pragma once
// did not want to fwd decl everything specially
// the templated classes (will fix later)
#include "../common/InstrumentSnapshot.h"
namespace bts::spartan::mdp3 {
// Builds the order state for all orders correponding to one
// price level for one security
class FifoPriceLevelMatcher{
public:
struct Order{
MDP3OrderKey key;
MDP3OrderPriority priority;
MDP3Quantity quantity;
bool is_active=true;
Order (MDP3OrderKey key_arg,
MDP3OrderPriority priority_arg,
MDP3Quantity quantity_arg)
:
key(key_arg),
priority(priority_arg),
quantity(quantity_arg)
{}
};
private:
md::IntPrice _price;
api::Side _side;
MDP3OrderPriority _lowest_priority;
std::vector<FifoPriceLevelMatcher::Order> _orders;
private:
// helpers /////////////////////////////////////////////////////////////////
void _compress();
Order* _find(MDP3OrderKey key);
void _logically_delete(Order& o);
void _add_order(MDP3OrderKey key,
MDP3OrderPriority priority,
MDP3Quantity quantity);
public:
// constructors ////////////////////////////////////////////////////////////
FifoPriceLevelMatcher (md::IntPrice price,
api::Side side);
FifoPriceLevelMatcher (const FifoPriceLevelMatcher&);
FifoPriceLevelMatcher (FifoPriceLevelMatcher&&);
// operator overloads //////////////////////////////////////////////////////
FifoPriceLevelMatcher& operator=(const FifoPriceLevelMatcher& o);
FifoPriceLevelMatcher& operator=(FifoPriceLevelMatcher&& o);
bool operator==(const FifoPriceLevelMatcher& o) const {return _price == o._price;}
bool operator!=(const FifoPriceLevelMatcher& o) const {return _price != o._price;}
bool operator<(const FifoPriceLevelMatcher& o) const;
// simple accessors ////////////////////////////////////////////////////////
std::tuple<uint32_t,uint32_t> n_orders_qty() const{
uint32_t n_orders = 0, tot_qty = 0;
for(const auto& o : _orders)
if(o.is_active){
n_orders++;
tot_qty += o.quantity.value();
}
return std::make_tuple(n_orders,tot_qty);
}
MDP3Quantity quantity() const{
return MDP3Quantity(std::get<1>(n_orders_qty()));
}
uint32_t n_orders() const{
return std::get<0>(n_orders_qty());
}
bool populated() const{
return quantity().value()>0;
}
md::IntPrice price() const{
return _price;
}
api::Side side() const{
return _side;
}
Order* find_order (MDP3OrderKey key){
return _find(key);
}
BookLevel book_level() const{
return BookLevel{_price, quantity(), static_cast<int>(n_orders())};
}
// mutators (silly reason) /////////////////////////////////////////////////
void set_price(md::IntPrice p){
_price = p;
}
const std::vector<Order>& orders(){
return _orders;
}
// order interactions //////////////////////////////////////////////////////
// order with the same side and price as this price level
void on_new_same_side_order(const MDP3Order& new_ord);
// order update such that only the qty changed (other changes
// are handled at a higher level)
void on_order_update(const MDP3Order& upd_ord);
void on_order_remove(MDP3OrderKey k);
// new order such that it crosses this price level
MDP3Quantity on_new_opp_order(MDP3Quantity opp_ord_qty);
};
} // namespace bts::spartan::mdp3
@@ -1,159 +0,0 @@
#include "FifoSecurityMatcher.h"
#include "../common/InstrumentSnapshot.h"
namespace bts::spartan::mdp3 {
// helpers ////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
inline bool _is_cross (
const MDP3Order& ord,
const FifoPriceLevelMatcher& price_level){
return ord.side != price_level.side() &&
(
(
ord.side == api::Side::SIDE_BUY &&
ord.price >= price_level.price()
)
||
(
ord.side == api::Side::SIDE_SELL &&
ord.price <= price_level.price()
)
);
}
inline api::Side _opp_side(api::Side side){
return side == api::Side::SIDE_BUY ? api::Side::SIDE_SELL :
api::Side::SIDE_BUY;
}
inline FifoPriceLevelMatcher* FifoSecurityMatcher::_top(api::Side side){
auto& bk = _book(side);
auto it = bk.begin();
return it != bk.end() ? &*it : nullptr;
}
FifoPriceLevelMatcher* FifoSecurityMatcher::_find_price_level(
api::Side side,
md::IntPrice price){
auto& bk = _book(side);
_search_tok.set_price(price);
auto it = bk.find (_search_tok);
return it != bk.end() ? &*it : nullptr;
}
std::tuple<FifoPriceLevelMatcher*,FifoPriceLevelMatcher::Order*>
FifoSecurityMatcher::_find_order (MDP3OrderKey key){
for (auto& p_level : _bid_book){
auto o_ptr = p_level.find_order(key);
if (o_ptr != nullptr)
return std::make_tuple(&p_level,o_ptr);
}
for (auto& p_level : _ask_book){
auto o_ptr = p_level.find_order(key);
if (o_ptr != nullptr)
return std::make_tuple(&p_level,o_ptr);
}
return std::tuple<FifoPriceLevelMatcher*,FifoPriceLevelMatcher::Order*>
(nullptr,nullptr);
}
void FifoSecurityMatcher::_remove_empty_price_levels(){
auto rem_if = [](const auto& p_lev) { return !p_lev.populated(); };
_bid_book.erase(
std::remove_if(_bid_book.begin(),_bid_book.end(),rem_if),
_bid_book.end());
_bid_book.erase(
std::remove_if(_ask_book.begin(), _ask_book.end(), rem_if),
_ask_book.end());
}
// constructors ///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
FifoSecurityMatcher::FifoSecurityMatcher(const InstrumentSnapshot& snp)
:
_bid_book(),
_ask_book(),
_search_tok(md::IntPrice(),
api::Side::SIDE_BUY)
{
for (const auto& kv : snp.orders())
on_new_order(kv.second);
}
// accessors //////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
Book FifoSecurityMatcher::book(api::Side side) const{
auto i = 0;
Book rv;
for (const auto& p_level : _book(side)){
if(i < MDP3_MAX_BOOK_DEPTH)
rv[i++] = p_level.book_level();
else
break;
}
return rv;
}
// order interactions /////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void FifoSecurityMatcher::on_new_order(const MDP3Order& ord){
auto& opp_book = _book(_opp_side(ord.side));
uint32_t rem = ord.quantity.value();
for (FifoPriceLevelMatcher& pl : opp_book){
if(_is_cross(ord, pl))
rem = pl.on_new_opp_order(MDP3Quantity(rem)).value();
else
break;
if(rem == 0)
break;
bts_assert(pl.quantity().value()==0);
// stops crossing when the price level is not a cross or there
// no qty left
}
_remove_empty_price_levels();
if(rem != 0){
// either the price did not cross into the opp market
// or it cleared out the entire opposite side
// in either case, it becomes a resting order
FifoPriceLevelMatcher* price_level = _find_price_level(ord.side,ord.price);
if(price_level == nullptr){
auto& same_side_book = _book(ord.side);
auto p = same_side_book.emplace(ord.price,ord.side);
bts_assert(std::get<1>(p));
price_level = &*std::get<0>(p);
}
MDP3Order ord_corrected = ord;
ord_corrected.quantity = MDP3Quantity(rem);
price_level->on_new_same_side_order(ord);
}
}
void FifoSecurityMatcher::on_order_update(const MDP3Order& ord){
auto t = _find_order(ord.key);
FifoPriceLevelMatcher* price_level = std::get<0>(t);
FifoPriceLevelMatcher::Order* ex_ord = std::get<1>(t);
bts_assert(price_level != nullptr);
bts_assert(ex_ord != nullptr);
// side can not be changed (or can it?)
bts_assert(price_level->side() == ord.side);
// check for price change
if(price_level->price() != ord.price){
// remove from current level and add to another
on_order_remove(ord.key);
on_new_order(ord);
}
else{
// qty change - price_level will handle it
price_level->on_order_update(ord);
}
}
void FifoSecurityMatcher::on_order_remove(MDP3OrderKey key){
auto t = _find_order(key);
FifoPriceLevelMatcher* price_level = std::get<0>(t);
FifoPriceLevelMatcher::Order* ex_ord = std::get<1>(t);
bts_assert(price_level != nullptr);
bts_assert(ex_ord != nullptr);
bts_assert(key == ex_ord->key);
price_level->on_order_remove(key);
_remove_empty_price_levels();
}
}
@@ -1,53 +0,0 @@
#pragma once
// did not want to fwd decl everything specially
// the templated classes (will fix later)
#include "../common/InstrumentSnapshot.h"
#include "FifoPriceLevelMatcher.h"
#include <boost/container/flat_set.hpp>
namespace bts::spartan::mdp3 {
class FifoSecurityMatcher {
private:
// ask prices are sorted lowest to highets and and bid prices
// are sorted lowest to highest
boost::container::flat_set<FifoPriceLevelMatcher> _bid_book,
_ask_book;
FifoPriceLevelMatcher _search_tok;
private:
// helpers /////////////////////////////////////////////////////////////////
// returns the top of the side in the arg; nullptr
// if the side does not have any prices. complexity is
// O(1)
FifoPriceLevelMatcher* _top(api::Side);
// complexity: O(lg(n))
FifoPriceLevelMatcher* _find_price_level(api::Side, md::IntPrice price);
boost::container::flat_set<FifoPriceLevelMatcher>& _book(api::Side side){
return side == api::Side::SIDE_BUY ? _bid_book : _ask_book;
}
const boost::container::flat_set<FifoPriceLevelMatcher>& _book(
api::Side side) const{
return side == api::Side::SIDE_BUY ? _bid_book : _ask_book;
}
// returns the price level and the order within that level.
// complexity: O(n^2) (searching through each price level
// and within a price level searching through the orders)
// this could be improved to O(lg(n)), if order keys are stored
// in a boost::flat_set pointing to their PriceLevel
std::tuple<FifoPriceLevelMatcher*,FifoPriceLevelMatcher::Order*>
_find_order (MDP3OrderKey key);
// for performance reasons we should reuse empty price levels
// (right now, for simplcity, we just remove)
void _remove_empty_price_levels();
public:
// cons ////////////////////////////////////////////////////////////////////
FifoSecurityMatcher(const InstrumentSnapshot&);
// accessors ///////////////////////////////////////////////////////////////
Book book(api::Side) const;
// order interactions //////////////////////////////////////////////////////
void on_new_order(const MDP3Order&);
void on_order_update(const MDP3Order&);
void on_order_remove(MDP3OrderKey);
};
} // namespace bts::spartan::mdp3
@@ -1,83 +0,0 @@
#pragma once
#include "../gen/MDInstrumentDefinitionFuture54.h"
#include "../gen/MDInstrumentDefinitionOption55.h"
#include "../gen/MDInstrumentDefinitionSpread56.h"
#include "../parsing/MDP3MsgBox.h"
#include "mdp3_common.h"
namespace bts::spartan::mdp3 {
// A simple abstraction for a instrument definition, which can be one of:
// ::mdp3::MDInstrumentDefinitionFuture54
// ::mdp3::MDInstrumentDefinitionOption55
// ::mdp3::MDInstrumentDefinitionSpread56
// To get the actual definition type use the visit() method.
class InstrumentDefinition {
public:
InstrumentDefinition(InstrumentDefinition &&d) = default;
InstrumentDefinition(InstrumentDefinition const &d) = default;
InstrumentDefinition &operator=(InstrumentDefinition &&other) = default;
InstrumentDefinition &operator=(InstrumentDefinition const &other) = default;
template <class M>
InstrumentDefinition(M const &d) : _def(MDP3MsgBox<M>(d)) {}
// Visit specific type in this definition
template <class Visitor> void visit(Visitor v) const {
std::visit([&v](auto &m) { v(*m); }, _def);
}
// Query the specific type contained in this definition and return
// something about it
template <class Getter> auto get(Getter g) const {
return std::visit([g](auto &m) { return g(*m); }, _def);
}
// Helpers
MDP3TimeStamp last_update_time() const {
return MDP3TimeStamp{
get([](auto const &m) { return m.lastUpdateTime(); })};
}
size_t tot_num_reports() const {
return get([](auto const &m) { return m.totNumReports(); });
}
MDP3SecurityID security_id() const {
return MDP3SecurityID{get([](auto const &m) { return m.securityID(); })};
}
const char *symbol() const {
return get([](auto const &m) { return m.symbol(); });
}
::mdp3::MatchEventIndicator match_event_indicator() const {
// matchEventIndicator() is not marked as const so we cannot use
// the get() method
return std::visit([](auto &box) { return box->matchEventIndicator(); },
_def);
}
const char *security_group() const {
return get([](auto const &m) { return m.securityGroup(); });
}
const char *asset() const {
return get([](auto const &m) { return m.asset(); });
}
::mdp3::SecurityTradingStatus::Value trading_status() const {
return get([](auto const &m) { return m.mDSecurityTradingStatus(); });
}
private:
using DefVar =
std::variant<MDP3MsgBox<::mdp3::MDInstrumentDefinitionFuture54>,
MDP3MsgBox<::mdp3::MDInstrumentDefinitionOption55>,
MDP3MsgBox<::mdp3::MDInstrumentDefinitionSpread56>>;
mutable DefVar _def;
};
using MaybeInstrumentDefinition = std::optional<InstrumentDefinition>;
} // namespace bts::spartan::mdp3
@@ -1,418 +0,0 @@
#include "InstrumentSnapshot.h"
namespace bts::spartan::mdp3 {
struct InstrumentSnapshot::PImpl {
PImpl(InstrumentDefinition const &def)
: security_id(def.security_id()), books(), implied_books(), orders(),
order_changes(), last_processed_sn(0), fills(), high_limit_price(),
low_limit_price(), max_price_variation(), cleared_volume(),
electronic_volume(), fixing_price(), open_interest(), open_price(),
high_bid(), low_offer(), settlement_price(), high_trade_price(),
low_trade_price(), definition(def),
trading_status(definition.trading_status()) {}
PImpl(InstrumentDefinition &&def)
: security_id(def.security_id()), books(), implied_books(), orders(),
order_changes(), last_processed_sn(0), fills(), high_limit_price(),
low_limit_price(), max_price_variation(), cleared_volume(),
electronic_volume(), fixing_price(), open_interest(), open_price(),
high_bid(), low_offer(), settlement_price(), high_trade_price(),
low_trade_price(), definition(std::move(def)),
trading_status(definition.trading_status()) {}
// Books
const MDP3SecurityID security_id;
std::array<Book, 2> books;
std::array<ImpliedBook, 2> implied_books;
// Orders
Orders orders;
OrderChanges order_changes;
// Last packet that affected this security
size_t last_processed_sn;
// Fills
Fills fills;
// stats
md::IntPrice high_limit_price;
md::IntPrice low_limit_price;
md::IntPrice max_price_variation;
MDP3Quantity cleared_volume;
MDP3Quantity electronic_volume;
md::IntPrice fixing_price;
MDP3Quantity open_interest;
md::IntPrice open_price;
md::IntPrice high_bid;
md::IntPrice low_offer;
md::IntPrice settlement_price;
md::IntPrice high_trade_price;
md::IntPrice low_trade_price;
InstrumentDefinition definition;
::mdp3::SecurityTradingStatus::Value trading_status;
};
InstrumentSnapshot::InstrumentSnapshot(InstrumentDefinition const &def)
: me(new PImpl(def)) {}
InstrumentSnapshot::InstrumentSnapshot(InstrumentDefinition &&def)
: me(new PImpl(std::move(def))) {}
InstrumentSnapshot::~InstrumentSnapshot() {}
MDP3SecurityID InstrumentSnapshot::security_id() const {
return me->security_id;
}
InstrumentDefinition InstrumentSnapshot::definition() const {
return me->definition;
}
void InstrumentSnapshot::set_definition(InstrumentDefinition const &def) {
me->definition = def;
}
size_t InstrumentSnapshot::last_processed_sn() const {
return me->last_processed_sn;
}
void InstrumentSnapshot::set_last_msg_processed_sn(size_t n) {
me->last_processed_sn = n;
}
::mdp3::SecurityTradingStatus::Value
InstrumentSnapshot::trading_status() const {
return me->trading_status;
}
void InstrumentSnapshot::set_trading_status(
::mdp3::SecurityTradingStatus::Value t) const {
me->trading_status = t;
}
md::IntPrice InstrumentSnapshot::high_limit_price() const {
return me->high_limit_price;
}
void InstrumentSnapshot::set_high_limit_price(md::IntPrice v) {
me->high_limit_price = v;
}
md::IntPrice InstrumentSnapshot::low_limit_price() const {
return me->low_limit_price;
}
void InstrumentSnapshot::set_low_limit_price(md::IntPrice v) {
me->low_limit_price = v;
}
md::IntPrice InstrumentSnapshot::max_price_variation() const {
return me->max_price_variation;
}
void InstrumentSnapshot::set_max_price_variation(md::IntPrice v) {
me->max_price_variation = v;
}
MDP3Quantity InstrumentSnapshot::cleared_volume() const {
return me->cleared_volume;
}
void InstrumentSnapshot::set_cleared_volume(MDP3Quantity v) {
me->cleared_volume = v;
}
MDP3Quantity InstrumentSnapshot::electronic_volume() const {
return me->electronic_volume;
}
void InstrumentSnapshot::set_electronic_volume(MDP3Quantity v) {
me->electronic_volume = v;
}
md::IntPrice InstrumentSnapshot::fixing_price() const {
return me->fixing_price;
}
void InstrumentSnapshot::set_fixing_price(md::IntPrice v) {
me->fixing_price = v;
}
MDP3Quantity InstrumentSnapshot::open_interest() const {
return me->open_interest;
}
void InstrumentSnapshot::set_open_interest(MDP3Quantity v) {
me->open_interest = v;
}
md::IntPrice InstrumentSnapshot::open_price() const { return me->open_price; }
void InstrumentSnapshot::set_open_price(md::IntPrice v) { me->open_price = v; }
md::IntPrice InstrumentSnapshot::high_bid() const { return me->high_bid; }
void InstrumentSnapshot::set_high_bid(md::IntPrice v) { me->high_bid = v; }
md::IntPrice InstrumentSnapshot::low_offer() const { return me->low_offer; }
void InstrumentSnapshot::set_low_offer(md::IntPrice v) { me->low_offer = v; }
md::IntPrice InstrumentSnapshot::settlement_price() const {
return me->settlement_price;
}
void InstrumentSnapshot::set_settlement_price(md::IntPrice v) {
me->settlement_price = v;
}
md::IntPrice InstrumentSnapshot::high_trade_price() const {
return me->high_trade_price;
}
void InstrumentSnapshot::set_high_trade_price(md::IntPrice v) {
me->high_trade_price = v;
}
md::IntPrice InstrumentSnapshot::low_trade_price() const {
return me->low_trade_price;
}
void InstrumentSnapshot::set_low_trade_price(md::IntPrice v) {
me->low_trade_price = v;
}
Book const &InstrumentSnapshot::book(api::Side s) const {
return me->books[s - api::SIDE_BUY];
}
ImpliedBook const &InstrumentSnapshot::implied_book(api::Side s) const {
return me->implied_books[s - api::SIDE_BUY];
}
template <class A>
void InstrumentSnapshot::insert(api::Side s, std::array<A, 2> &books,
size_t idx, BookLevel const &level) {
auto &book = books[s - api::SIDE_BUY];
int zidx = (int)(idx - 1);
bts_assert_d(zidx < (int)book.size());
for (int i = book.size() - 2; i >= zidx; i--)
book[i + 1] = book[i];
book[zidx] = level;
}
template <class A>
void InstrumentSnapshot::update(api::Side s, std::array<A, 2> &books,
size_t idx, BookLevel const &level) {
auto &book = books[s - api::SIDE_BUY];
int zidx = (int)idx - 1;
bts_assert_d(zidx < (int)book.size());
book[zidx] = level;
}
template <class A>
void InstrumentSnapshot::remove(api::Side s, std::array<A, 2> &books,
size_t idx) {
auto &book = books[s - api::SIDE_BUY];
int zidx = (int)(idx - 1);
bts_assert_d(zidx < (int)book.size());
for (int i = zidx; i < (int)book.size() - 1; i++)
book[i] = book[i + 1];
book[book.size() - 1] = {};
}
void InstrumentSnapshot::insert_book_level(api::Side s, size_t idx,
BookLevel const &level) {
insert(s, me->books, idx, level);
}
void InstrumentSnapshot::update_book_level(api::Side s, size_t idx,
BookLevel const &level) {
update(s, me->books, idx, level);
}
void InstrumentSnapshot::remove_book_level(api::Side s, size_t idx) {
remove(s, me->books, idx);
}
void InstrumentSnapshot::insert_implied_book_level(api::Side s, size_t idx,
BookLevel const &level) {
insert(s, me->implied_books, idx, level);
}
void InstrumentSnapshot::update_implied_book_level(api::Side s, size_t idx,
BookLevel const &level) {
update(s, me->implied_books, idx, level);
}
void InstrumentSnapshot::remove_implied_book_level(api::Side s, size_t idx) {
remove(s, me->implied_books, idx);
}
Orders const &InstrumentSnapshot::orders() const { return me->orders; }
OrderChanges const &InstrumentSnapshot::order_changes() const {
return me->order_changes;
}
void InstrumentSnapshot::clear_order_changes() { me->order_changes.clear(); }
void InstrumentSnapshot::insert_order(MDP3Order const &order) {
bts_assert_d(me->orders.count(order.key) == 0);
me->orders.insert({order.key, order});
me->order_changes.emplace_back(OrderChange{order, OrderChange::added});
}
void InstrumentSnapshot::update_order(MDP3Order const &order) {
auto it = me->orders.find(order.key);
bts_assert_d(it != me->orders.end());
it->second = order;
me->order_changes.emplace_back(OrderChange{order, OrderChange::updated});
}
void InstrumentSnapshot::remove_order(MDP3OrderKey id) {
auto it = me->orders.find(id);
bts_assert(it != me->orders.end());
me->order_changes.emplace_back(
OrderChange{it->second, OrderChange::removed});
me->orders.erase(it);
}
Book InstrumentSnapshot::build_book_from_orders(api::Side side) const {
auto invert = side == api::SIDE_BUY ? -1 : 1;
auto book_idx = std::map<int64_t, BookLevel>();
for (auto &o : orders())
if (o.second.side == side) {
auto &order = o.second;
auto &level = book_idx[invert * order.price.mantissa()];
level.n_orders++;
level.price = order.price;
level.quantity.value() += order.quantity.value();
}
Book mbo_book;
size_t i = 0;
for (auto &p : book_idx)
if (i < mbo_book.size())
mbo_book[i++] = p.second;
return mbo_book;
}
void InstrumentSnapshot::set_books_from_orders() {
me->books[0] = build_book_from_orders(api::SIDE_BUY);
me->books[1] = build_book_from_orders(api::SIDE_SELL);
}
void InstrumentSnapshot::reset_books() {
for (auto &b : me->books)
for (auto &l : b)
l = {};
for (auto &b : me->implied_books)
for (auto &l : b)
l = {};
me->orders.clear();
me->fills.clear();
}
Fills const &InstrumentSnapshot::fills() const { return me->fills; }
void InstrumentSnapshot::add_fill(MDP3Fill const &f) {
me->fills.emplace_back(f);
}
void InstrumentSnapshot::update_fill(MDP3Fill const &f) {
for (auto &ff : me->fills)
if (ff.key == f.key && ff.trade_entry_id == f.trade_entry_id) {
ff = f;
break;
}
}
void InstrumentSnapshot::remove_fill(MDP3TradeEntryID tid, MDP3OrderKey oid) {
auto it = std::find_if(me->fills.begin(), me->fills.end(),
[tid, oid](auto const &f) {
return f.key == oid && f.trade_entry_id == tid;
});
if (it != me->fills.end())
me->fills.erase(it);
}
void InstrumentSnapshot::clear_fills() { me->fills.clear(); }
MaybeOrderChange InstrumentSnapshot::deduced_order_change() const {
if (fills().empty() || trading_status() != ::mdp3::SecurityTradingStatus::ReadyToTrade )
return {};
Fills aggressor_fills;
std::copy_if(fills().begin(), fills().end(),
std::back_inserter(aggressor_fills), [](auto const &f) {
return f.aggressor == MDP3Fill::THIS_BUY ||
f.aggressor == MDP3Fill::THIS_SELL;
});
if (aggressor_fills.empty())
return {};
OrderChange result;
result.order.key = aggressor_fills[0].key;
result.order.security = security_id();
result.order.side = aggressor_fills[0].aggressor == MDP3Fill::THIS_BUY
? api::SIDE_BUY
: api::SIDE_SELL;
result.order.priority = {};
result.order.price = aggressor_fills[0].price;
result.order.quantity = MDP3Quantity{0};
for (auto &f : aggressor_fills) {
if (securities::is_better(result.order.side,
Price(result.order.price.price()),
Price(f.price.price())))
result.order.price = f.price;
result.order.quantity.value() += f.quantity.value();
}
// Lets find out if this is a new or existing order. If it was an
// existing order then we must have a delete or replace in our list
// of order changes. If we do not then this must be a new order.
result.change = OrderChange::added;
for (auto &o : order_changes())
if (o.order.key == result.order.key) {
result.change = OrderChange::updated;
break;
}
// Now lets find out if this was a full fill or a partial fill. A
// partial fill would have left the order in the books. In that
// case we can use the information in the book to correct our
// estimated quantity and prices from above.
auto it = orders().find(result.order.key);
if (it != orders().end()) {
result.order.quantity.value() += it->second.quantity.value();
result.order.price = it->second.price;
}
return {result};
}
std::ostream &operator<<(std::ostream &out, InstrumentSnapshot const &snap) {
out << "Snapshot --------------------------------------\n"
<< "Symbol: " << snap.definition().symbol() << "\n"
<< "Security ID: " << snap.security_id().value() << "\n"
<< "Trading Status: " << snap.trading_status() << "\n"
<< "Seq Number: " << snap.last_processed_sn() << "\n"
<< "MBP Bid ---------------------------------------\n"
<< snap.book(api::SIDE_BUY)
<< "MBP Ask ---------------------------------------\n"
<< snap.book(api::SIDE_SELL)
<< "Implied Bid -----------------------------------\n"
<< snap.implied_book(api::SIDE_BUY)
<< "Implied Ask -----------------------------------\n"
<< snap.implied_book(api::SIDE_SELL);
out << "Order Changes -----------------------------------\n";
for (auto &change : snap.order_changes())
out << change << "\n";
auto orders = sort_orders(snap.orders(), api::SIDE_BUY);
out << "Buy Orders -----------------------------------\n";
for (auto &order : orders)
out << order << "\n";
orders = sort_orders(snap.orders(), api::SIDE_SELL);
out << "Sell Orders ----------------------------------\n";
for (auto &order : orders)
out << order << "\n";
out << "Fills ----------------------------------------\n";
for (auto &f : snap.fills())
out << f << "\n";
return out;
}
} // namespace bts::spartan::mdp3
@@ -1,104 +0,0 @@
#pragma once
#include "InstrumentDefinition.h"
#include "mdp3_common.h"
#include "lib/domain_model/Security.pb.h"
#include <memory>
namespace mdp3 {
class SnapshotFullRefresh52;
}
namespace bts::spartan::mdp3 {
// Describes the state of the exchange at a specific time with respect
// to a single instrument. Several kinds of information are available:
// - The instrument's definition
// - Price books (implied and customer)
// - Resting orders
// - Fills generated by the last event
// - Order changes generated in the last event
// - The deduced order for the last event
// - Market statistics
class InstrumentSnapshot {
public:
InstrumentSnapshot(InstrumentDefinition const &);
InstrumentSnapshot(InstrumentDefinition &&);
~InstrumentSnapshot();
// Queries ------------------------------------------------------------
MDP3SecurityID security_id() const;
InstrumentDefinition definition() const;
const char *symbol() const { return definition().symbol(); }
::mdp3::SecurityTradingStatus::Value trading_status() const;
size_t last_processed_sn() const;
Book const &book(api::Side) const;
ImpliedBook const &implied_book(api::Side) const;
Orders const &orders() const;
OrderChanges const &order_changes() const;
MaybeOrderChange deduced_order_change() const;
Fills const &fills() const;
md::IntPrice high_limit_price() const;
md::IntPrice low_limit_price() const;
md::IntPrice max_price_variation() const;
MDP3Quantity electronic_volume() const;
MDP3Quantity cleared_volume() const;
md::IntPrice fixing_price() const;
MDP3Quantity open_interest() const;
md::IntPrice open_price() const;
md::IntPrice high_bid() const;
md::IntPrice low_offer() const;
md::IntPrice settlement_price() const;
md::IntPrice high_trade_price() const;
md::IntPrice low_trade_price() const;
// Mutators ------------------------------------------------------------
void set_definition(InstrumentDefinition const &);
void set_last_msg_processed_sn(size_t);
void set_trading_status(::mdp3::SecurityTradingStatus::Value) const;
void insert_book_level(api::Side, size_t idx, BookLevel const &);
void update_book_level(api::Side, size_t idx, BookLevel const &);
void remove_book_level(api::Side, size_t idx);
void insert_implied_book_level(api::Side, size_t idx, BookLevel const &);
void update_implied_book_level(api::Side, size_t idx, BookLevel const &);
void remove_implied_book_level(api::Side, size_t idx);
void clear_order_changes();
void insert_order(MDP3Order const &);
void update_order(MDP3Order const &);
void remove_order(MDP3OrderKey);
Book build_book_from_orders(api::Side) const;
void set_books_from_orders();
void reset_books();
void add_fill(MDP3Fill const &);
void update_fill(MDP3Fill const &);
void remove_fill(MDP3TradeEntryID, MDP3OrderKey);
void clear_fills();
void set_high_limit_price(md::IntPrice);
void set_low_limit_price(md::IntPrice);
void set_max_price_variation(md::IntPrice);
void set_cleared_volume(MDP3Quantity);
void set_electronic_volume(MDP3Quantity);
void set_fixing_price(md::IntPrice);
void set_open_interest(MDP3Quantity);
void set_open_price(md::IntPrice);
void set_high_bid(md::IntPrice);
void set_low_offer(md::IntPrice);
void set_settlement_price(md::IntPrice);
void set_high_trade_price(md::IntPrice);
void set_low_trade_price(md::IntPrice);
private:
template <class A>
void insert(api::Side, std::array<A, 2> &, size_t idx, BookLevel const &);
template <class A>
void update(api::Side, std::array<A, 2> &, size_t idx, BookLevel const &);
template <class A> void remove(api::Side, std::array<A, 2> &, size_t idx);
struct PImpl;
std::unique_ptr<PImpl> me;
};
std::ostream &operator<<(std::ostream &, InstrumentSnapshot const &);
} // namespace bts::spartan::mdp3
@@ -1,211 +0,0 @@
#pragma once
#include "lib/domain_model/Security.h"
#include "lib/domain_model/Security.pb.h"
#include "lib/md/IntPrice.h"
#include "lib/utils/ValueWrapper.h"
#include "lib/utils/overloaded.h"
#include <boost/container/small_vector.hpp>
#include <variant>
namespace bts::spartan::mdp3 {
using MDP3TimeStamp = utils::ValueWrapper<struct MDP3TimeStampTag, uint64_t>;
using MDP3OrderKey = utils::ValueWrapper<struct ExchangeOrderKeyTag, uint64_t>;
using MDP3SecurityID =
utils::ValueWrapper<struct ExchangeSecurityIDTag, int32_t>;
class InstrumentSnapshot;
using InstrumentSnapshotPtr = std::unique_ptr<InstrumentSnapshot>;
class MDP3Event {
public:
MDP3TimeStamp transact_time = MDP3TimeStamp{0};
MDP3TimeStamp first_packet_send_time;
MDP3TimeStamp last_packet_send_time;
uint32_t first_packet_sn;
uint32_t last_packet_sn;
std::vector<InstrumentSnapshot const *> affected_securities;
void reset() {
transact_time = MDP3TimeStamp{0};
affected_securities.clear();
}
};
inline std::ostream &operator<<(std::ostream &s, MDP3Event const &ev) {
s << " transact_time: " << ev.transact_time.value()
<< " packets: " << ev.first_packet_sn
<< " to " << ev.last_packet_sn;
return s;
}
using MDP3Quantity = utils::ValueWrapper<struct MDP3QuantityTag, int32_t>;
using MDP3OrderPriority =
utils::ValueWrapper<struct MDP3OrderPriorityTag, uint64_t>;
class BookLevel {
public:
md::IntPrice price;
MDP3Quantity quantity = MDP3Quantity{0};
int32_t n_orders = 0;
bool operator==(BookLevel const &other) const {
return price == other.price &&
quantity.value() == other.quantity.value() &&
n_orders == other.n_orders;
}
};
inline std::ostream &operator<<(std::ostream &s, BookLevel const &l) {
s << " " << l.quantity.value() << " @ " << l.price.price() << " ("
<< l.n_orders << " orders)";
return s;
}
struct MDP3Order {
public:
MDP3OrderKey key;
MDP3SecurityID security;
api::Side side;
MDP3OrderPriority priority;
md::IntPrice price;
MDP3Quantity quantity;
};
struct OrderChange {
MDP3Order order;
enum ChangeType { added, removed, updated } change;
};
using MaybeOrderChange = std::optional<OrderChange>;
inline const char*change_name (OrderChange::ChangeType ct) {
switch(ct) {
case OrderChange::added:
return "added";
case OrderChange::removed:
return "removed";
case OrderChange::updated:
return "updated";
}
return "";
}
using OrderChanges = std::vector<OrderChange>;
inline std::ostream &operator<<(std::ostream &s, MDP3Order const &order) {
s << " price: " << order.price.price() << " "
<< "k: " << order.key.value() << " "
<< "sk: " << order.security.value() << " "
<< "side: " << securities::side_name(order.side) << " "
<< "pri: " << order.priority.value() << " "
<< "qty: " << order.quantity.value();
return s;
}
inline std::ostream &operator<<(std::ostream &s, OrderChange const &ch) {
s << " "
<< (ch.change == OrderChange::added
? "create"
: (ch.change == OrderChange::updated ? "update" : "delete"))
<< ch.order;
return s;
}
inline std::ostream &operator<<(std::ostream &s, OrderChanges const &changes) {
for (auto c : changes)
s << " " << c << "\n";
return s;
}
using Orders = std::unordered_map<MDP3OrderKey, MDP3Order>;
using MDP3TradeEntryID =
utils::ValueWrapper<struct MDP3TradeEntryIDTag, uint32_t>;
struct MDP3Fill {
MDP3OrderKey key;
md::IntPrice price;
MDP3Quantity quantity;
MDP3Quantity summary_quantity;
MDP3TradeEntryID trade_entry_id;
enum Aggressor {THIS_BUY, THIS_SELL, OTHER, IMPLIED } aggressor;
};
inline const char*aggressor_name (MDP3Fill::Aggressor ag) {
switch(ag) {
case MDP3Fill::THIS_BUY:
return "yes_buy";
case MDP3Fill::THIS_SELL:
return "yes_sell";
case MDP3Fill::OTHER:
return "no";
case MDP3Fill::IMPLIED:
return "implied";
}
return "";
}
inline std::vector<MDP3Order> sort_orders(Orders const &orders, api::Side side) {
std::vector<MDP3Order> result;
for (auto &o : orders) {
auto &order = o.second;
if (order.side == side)
result.push_back(order);
}
std::sort(result.begin(), result.end(),
[side](auto const &o1, auto const &o2) {
if (o1.price.price() != o2.price.price()) {
if (side == api::SIDE_BUY)
return o2.price.price() < o1.price.price();
else
return o1.price.price() < o2.price.price();
} else
return o1.priority.value() < o2.priority.value();
});
return result;
}
inline std::ostream &operator<<(std::ostream &out, Orders const &orders) {
auto sorted = sort_orders(orders, api::SIDE_BUY);
for (auto &o : sorted)
out << o << std::endl;
return out;
}
inline std::ostream &operator<<(std::ostream &s, MDP3Fill const &fill) {
s << " ok: " << fill.key.value() << " "
<< "price: " << fill.price.price() << " "
<< "qty: " << fill.quantity.value() << " "
<< "tid: " << fill.trade_entry_id.value() << " "
<< "agg: " << (int)fill.aggressor;
return s;
}
using Fills = std::vector<MDP3Fill>;
inline std::ostream &operator<<(std::ostream &s, Fills const &fills) {
for (auto f : fills)
s << " " << f << "\n";
return s;
}
const auto MDP3_MAX_BOOK_DEPTH = 10;
const auto MDP3_MAX_IMPLIED_BOOK_DEPTH = 2;
using Book = std::array<BookLevel, MDP3_MAX_BOOK_DEPTH>;
inline std::ostream &operator<<(std::ostream &s, Book const &b) {
for (auto const &l : b)
s << l << "\n";
return s;
}
using ImpliedBook = std::array<BookLevel, MDP3_MAX_IMPLIED_BOOK_DEPTH>;
inline std::ostream &operator<<(std::ostream &s, ImpliedBook const &b) {
for (auto const &l : b)
s << l << "\n";
return s;
}
} // namespace bts::spartan::mdp3
@@ -1,93 +0,0 @@
#pragma once
#include "../parsing/MDP3Parser.h"
#include "../feed_control/PickedFeed.h"
#include "lib/utils/bts_assert.h"
namespace bts::spartan::mdp3 {
// Arbitrage between two identical MDP3 feeds, picking the next
// message from whatever feed sees it first. Additionally provide a
// small level of redundancy by using one feed to recover gaps from
// another one.
class AB_Arbitrageur {
public:
AB_Arbitrageur() : _last_seqn(0) {}
enum ActionCode { APPLY, IGNORE, RECOVER };
struct Action {
ActionCode action;
PickedFeed picked;
MDP3PacketView const packet;
};
size_t expected_next_sn() const { return _last_seqn + 1; }
Action operator()(MDP3PacketView const &a, MDP3PacketView const &b) {
bts_assert_d(!a.empty() || !b.empty());
auto action_a = try_one(a);
if (action_a == ActionCode::APPLY) {
_last_seqn = a.seq_num();
return {action_a, PickedFeed::A, a};
}
auto action_b = try_one(b);
if (action_b == ActionCode::APPLY) {
_last_seqn = b.seq_num();
return {action_b, PickedFeed::B, b};
}
// the first packet defines our starting sequence number, rather
// than continue from the previous one, so we handle that
// separately
if (_last_seqn == 0) {
if (!a.empty()) {
_last_seqn = a.seq_num();
return {ActionCode::APPLY, PickedFeed::A, a};
} else {
_last_seqn = b.seq_num();
return {ActionCode::APPLY, PickedFeed::B,b};
}
}
// Both feeds are either ahead or behind, if they are ahead we
// return RECOVER, otherwise we return IGNORE.
if (action_a == action_b)
return {action_a, PickedFeed::None, a};
// One of the feeds is ahead of us and the other is behind. Its
// possible that we will recover eventually, that is the feed
// that is behind might catch up, but its also possible that
// that feed died and it will never move forward. We could start
// a timer to limit how much we are willing to wait but its
// simpler to just cap how much ahead the advanced feed can be
// before we give up entirely.
auto how_far_ahead = 0;
if (action_a == ActionCode::RECOVER)
how_far_ahead = a.seq_num() - _last_seqn;
else
how_far_ahead = b.seq_num() - _last_seqn;
if (how_far_ahead > 10)
return {ActionCode::RECOVER, PickedFeed::None, a};
else
return {ActionCode::IGNORE, PickedFeed::None, a};
}
private:
size_t _last_seqn;
ActionCode try_one(MDP3PacketView const &packet) {
if (_last_seqn + 1 == packet.seq_num())
return ActionCode::APPLY;
else if (_last_seqn + 1 > packet.seq_num())
return ActionCode::IGNORE;
else
return ActionCode::RECOVER;
}
};
} // namespace bts::spartan::mdp3
@@ -1,7 +0,0 @@
#include "IFeedController.h"
namespace bts::spartan::mdp3 {
IFeedController::~IFeedController() {}
}
@@ -1,17 +0,0 @@
#pragma once
namespace bts::spartan::mdp3 {
class IFeedController {
public:
virtual ~IFeedController() ;
virtual void start_instrument_feed() = 0;
virtual void stop_instrument_feed() = 0;
virtual void start_snapshot_feed() = 0;
virtual void stop_snapshot_feed() = 0;
virtual void start_incremental_feed() = 0;
virtual void stop_incremental_feed() = 0;
};
}
@@ -1,5 +0,0 @@
#pragma once
namespace bts::spartan {
enum class PickedFeed { A, B, None };
}
@@ -1,312 +0,0 @@
/* Generated SBE (Simple Binary Encoding) message codec */
#ifndef _MDP3_ADMINHEARTBEAT12_H_
#define _MDP3_ADMINHEARTBEAT12_H_
#if defined(SBE_HAVE_CMATH)
/* cmath needed for std::numeric_limits<double>::quiet_NaN() */
# include <cmath>
# define SBE_FLOAT_NAN std::numeric_limits<float>::quiet_NaN()
# define SBE_DOUBLE_NAN std::numeric_limits<double>::quiet_NaN()
#else
/* math.h needed for NAN */
# include <math.h>
# define SBE_FLOAT_NAN NAN
# define SBE_DOUBLE_NAN NAN
#endif
#if __cplusplus >= 201103L
# include <cstdint>
# include <string>
# include <cstring>
#endif
#if __cplusplus >= 201103L
# define SBE_CONSTEXPR constexpr
# define SBE_NOEXCEPT noexcept
#else
# define SBE_CONSTEXPR
# define SBE_NOEXCEPT
#endif
#if __cplusplus >= 201703L
# define SBE_NODISCARD [[nodiscard]]
#else
# define SBE_NODISCARD
#endif
#if !defined(__STDC_LIMIT_MACROS)
# define __STDC_LIMIT_MACROS 1
#endif
#include <cstdint>
#include <cstring>
#include <limits>
#include <stdexcept>
#include <ostream>
#include <sstream>
#include <iomanip>
#if defined(WIN32) || defined(_WIN32)
# define SBE_BIG_ENDIAN_ENCODE_16(v) _byteswap_ushort(v)
# define SBE_BIG_ENDIAN_ENCODE_32(v) _byteswap_ulong(v)
# define SBE_BIG_ENDIAN_ENCODE_64(v) _byteswap_uint64(v)
# define SBE_LITTLE_ENDIAN_ENCODE_16(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_32(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_64(v) (v)
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define SBE_BIG_ENDIAN_ENCODE_16(v) __builtin_bswap16(v)
# define SBE_BIG_ENDIAN_ENCODE_32(v) __builtin_bswap32(v)
# define SBE_BIG_ENDIAN_ENCODE_64(v) __builtin_bswap64(v)
# define SBE_LITTLE_ENDIAN_ENCODE_16(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_32(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_64(v) (v)
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define SBE_LITTLE_ENDIAN_ENCODE_16(v) __builtin_bswap16(v)
# define SBE_LITTLE_ENDIAN_ENCODE_32(v) __builtin_bswap32(v)
# define SBE_LITTLE_ENDIAN_ENCODE_64(v) __builtin_bswap64(v)
# define SBE_BIG_ENDIAN_ENCODE_16(v) (v)
# define SBE_BIG_ENDIAN_ENCODE_32(v) (v)
# define SBE_BIG_ENDIAN_ENCODE_64(v) (v)
#else
# error "Byte Ordering of platform not determined. Set __BYTE_ORDER__ manually before including this file."
#endif
#if defined(SBE_NO_BOUNDS_CHECK)
# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (false)
#elif defined(_MSC_VER)
# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (exp)
#else
# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (__builtin_expect(exp,c))
#endif
#define SBE_NULLVALUE_INT8 (std::numeric_limits<std::int8_t>::min)()
#define SBE_NULLVALUE_INT16 (std::numeric_limits<std::int16_t>::min)()
#define SBE_NULLVALUE_INT32 (std::numeric_limits<std::int32_t>::min)()
#define SBE_NULLVALUE_INT64 (std::numeric_limits<std::int64_t>::min)()
#define SBE_NULLVALUE_UINT8 (std::numeric_limits<std::uint8_t>::max)()
#define SBE_NULLVALUE_UINT16 (std::numeric_limits<std::uint16_t>::max)()
#define SBE_NULLVALUE_UINT32 (std::numeric_limits<std::uint32_t>::max)()
#define SBE_NULLVALUE_UINT64 (std::numeric_limits<std::uint64_t>::max)()
#include "MDEntryTypeBook.h"
#include "OpenCloseSettlFlag.h"
#include "MatchEventIndicator.h"
#include "MaturityMonthYear.h"
#include "FLOAT.h"
#include "MDEntryTypeDailyStatistics.h"
#include "EventType.h"
#include "DecimalQty.h"
#include "MDUpdateAction.h"
#include "PRICENULL9.h"
#include "GroupSize8Byte.h"
#include "HaltReason.h"
#include "PRICE9.h"
#include "MDEntryType.h"
#include "PRICENULL.h"
#include "SecurityTradingStatus.h"
#include "LegSide.h"
#include "MessageHeader.h"
#include "PRICE.h"
#include "OrderUpdateAction.h"
#include "PutOrCall.h"
#include "SecurityUpdateAction.h"
#include "SecurityTradingEvent.h"
#include "Decimal9.h"
#include "MDEntryTypeStatistics.h"
#include "InstAttribValue.h"
#include "AggressorSide.h"
#include "GroupSize.h"
#include "SettlPriceType.h"
#include "Decimal9NULL.h"
namespace mdp3 {
class AdminHeartbeat12
{
private:
char *m_buffer = nullptr;
std::uint64_t m_bufferLength = 0;
std::uint64_t m_offset = 0;
std::uint64_t m_position = 0;
std::uint64_t m_actingVersion = 0;
inline std::uint64_t *sbePositionPtr() SBE_NOEXCEPT
{
return &m_position;
}
public:
enum MetaAttribute
{
EPOCH, TIME_UNIT, SEMANTIC_TYPE, PRESENCE
};
union sbe_float_as_uint_u
{
float fp_value;
std::uint32_t uint_value;
};
union sbe_double_as_uint_u
{
double fp_value;
std::uint64_t uint_value;
};
AdminHeartbeat12() = default;
AdminHeartbeat12(
char *buffer,
const std::uint64_t offset,
const std::uint64_t bufferLength,
const std::uint64_t actingBlockLength,
const std::uint64_t actingVersion) :
m_buffer(buffer),
m_bufferLength(bufferLength),
m_offset(offset),
m_position(sbeCheckPosition(offset + actingBlockLength)),
m_actingVersion(actingVersion)
{
}
AdminHeartbeat12(char *buffer, const std::uint64_t bufferLength) :
AdminHeartbeat12(buffer, 0, bufferLength, sbeBlockLength(), sbeSchemaVersion())
{
}
AdminHeartbeat12(
char *buffer,
const std::uint64_t bufferLength,
const std::uint64_t actingBlockLength,
const std::uint64_t actingVersion) :
AdminHeartbeat12(buffer, 0, bufferLength, actingBlockLength, actingVersion)
{
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeBlockLength() SBE_NOEXCEPT
{
return (std::uint16_t)0;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeTemplateId() SBE_NOEXCEPT
{
return (std::uint16_t)12;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeSchemaId() SBE_NOEXCEPT
{
return (std::uint16_t)1;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeSchemaVersion() SBE_NOEXCEPT
{
return (std::uint16_t)9;
}
SBE_NODISCARD static SBE_CONSTEXPR const char * sbeSemanticType() SBE_NOEXCEPT
{
return "0";
}
SBE_NODISCARD std::uint64_t offset() const SBE_NOEXCEPT
{
return m_offset;
}
AdminHeartbeat12 &wrapForEncode(char *buffer, const std::uint64_t offset, const std::uint64_t bufferLength)
{
return *this = AdminHeartbeat12(buffer, offset, bufferLength, sbeBlockLength(), sbeSchemaVersion());
}
AdminHeartbeat12 &wrapAndApplyHeader(char *buffer, const std::uint64_t offset, const std::uint64_t bufferLength)
{
MessageHeader hdr(buffer, offset, bufferLength, sbeSchemaVersion());
hdr
.blockLength(sbeBlockLength())
.templateId(sbeTemplateId())
.schemaId(sbeSchemaId())
.version(sbeSchemaVersion());
return *this = AdminHeartbeat12(
buffer,
offset + MessageHeader::encodedLength(),
bufferLength,
sbeBlockLength(),
sbeSchemaVersion());
}
AdminHeartbeat12 &wrapForDecode(
char *buffer,
const std::uint64_t offset,
const std::uint64_t actingBlockLength,
const std::uint64_t actingVersion,
const std::uint64_t bufferLength)
{
return *this = AdminHeartbeat12(buffer, offset, bufferLength, actingBlockLength, actingVersion);
}
SBE_NODISCARD std::uint64_t sbePosition() const SBE_NOEXCEPT
{
return m_position;
}
std::uint64_t sbeCheckPosition(const std::uint64_t position)
{
if (SBE_BOUNDS_CHECK_EXPECT((position > m_bufferLength), false))
{
throw std::runtime_error("buffer too short [E100]");
}
return position;
}
void sbePosition(const std::uint64_t position)
{
m_position = sbeCheckPosition(position);
}
SBE_NODISCARD std::uint64_t encodedLength() const SBE_NOEXCEPT
{
return sbePosition() - m_offset;
}
SBE_NODISCARD const char * buffer() const SBE_NOEXCEPT
{
return m_buffer;
}
SBE_NODISCARD char * buffer() SBE_NOEXCEPT
{
return m_buffer;
}
SBE_NODISCARD std::uint64_t bufferLength() const SBE_NOEXCEPT
{
return m_bufferLength;
}
SBE_NODISCARD std::uint64_t actingVersion() const SBE_NOEXCEPT
{
return m_actingVersion;
}
template<typename CharT, typename Traits>
friend std::basic_ostream<CharT, Traits>& operator<<(
std::basic_ostream<CharT, Traits>& builder, AdminHeartbeat12 _writer)
{
AdminHeartbeat12 writer(_writer.m_buffer, _writer.m_offset,
_writer.m_bufferLength, _writer.sbeBlockLength(), _writer.m_actingVersion);
builder << '{';
builder << R"("Name": "AdminHeartbeat12", )";
builder << R"("sbeTemplateId": )";
builder << writer.sbeTemplateId();
builder << ", ";
builder << '}';
return builder;
}
};
}
#endif
@@ -1,386 +0,0 @@
/* Generated SBE (Simple Binary Encoding) message codec */
#ifndef _MDP3_ADMINLOGIN15_H_
#define _MDP3_ADMINLOGIN15_H_
#if defined(SBE_HAVE_CMATH)
/* cmath needed for std::numeric_limits<double>::quiet_NaN() */
# include <cmath>
# define SBE_FLOAT_NAN std::numeric_limits<float>::quiet_NaN()
# define SBE_DOUBLE_NAN std::numeric_limits<double>::quiet_NaN()
#else
/* math.h needed for NAN */
# include <math.h>
# define SBE_FLOAT_NAN NAN
# define SBE_DOUBLE_NAN NAN
#endif
#if __cplusplus >= 201103L
# include <cstdint>
# include <string>
# include <cstring>
#endif
#if __cplusplus >= 201103L
# define SBE_CONSTEXPR constexpr
# define SBE_NOEXCEPT noexcept
#else
# define SBE_CONSTEXPR
# define SBE_NOEXCEPT
#endif
#if __cplusplus >= 201703L
# define SBE_NODISCARD [[nodiscard]]
#else
# define SBE_NODISCARD
#endif
#if !defined(__STDC_LIMIT_MACROS)
# define __STDC_LIMIT_MACROS 1
#endif
#include <cstdint>
#include <cstring>
#include <limits>
#include <stdexcept>
#include <ostream>
#include <sstream>
#include <iomanip>
#if defined(WIN32) || defined(_WIN32)
# define SBE_BIG_ENDIAN_ENCODE_16(v) _byteswap_ushort(v)
# define SBE_BIG_ENDIAN_ENCODE_32(v) _byteswap_ulong(v)
# define SBE_BIG_ENDIAN_ENCODE_64(v) _byteswap_uint64(v)
# define SBE_LITTLE_ENDIAN_ENCODE_16(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_32(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_64(v) (v)
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define SBE_BIG_ENDIAN_ENCODE_16(v) __builtin_bswap16(v)
# define SBE_BIG_ENDIAN_ENCODE_32(v) __builtin_bswap32(v)
# define SBE_BIG_ENDIAN_ENCODE_64(v) __builtin_bswap64(v)
# define SBE_LITTLE_ENDIAN_ENCODE_16(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_32(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_64(v) (v)
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define SBE_LITTLE_ENDIAN_ENCODE_16(v) __builtin_bswap16(v)
# define SBE_LITTLE_ENDIAN_ENCODE_32(v) __builtin_bswap32(v)
# define SBE_LITTLE_ENDIAN_ENCODE_64(v) __builtin_bswap64(v)
# define SBE_BIG_ENDIAN_ENCODE_16(v) (v)
# define SBE_BIG_ENDIAN_ENCODE_32(v) (v)
# define SBE_BIG_ENDIAN_ENCODE_64(v) (v)
#else
# error "Byte Ordering of platform not determined. Set __BYTE_ORDER__ manually before including this file."
#endif
#if defined(SBE_NO_BOUNDS_CHECK)
# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (false)
#elif defined(_MSC_VER)
# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (exp)
#else
# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (__builtin_expect(exp,c))
#endif
#define SBE_NULLVALUE_INT8 (std::numeric_limits<std::int8_t>::min)()
#define SBE_NULLVALUE_INT16 (std::numeric_limits<std::int16_t>::min)()
#define SBE_NULLVALUE_INT32 (std::numeric_limits<std::int32_t>::min)()
#define SBE_NULLVALUE_INT64 (std::numeric_limits<std::int64_t>::min)()
#define SBE_NULLVALUE_UINT8 (std::numeric_limits<std::uint8_t>::max)()
#define SBE_NULLVALUE_UINT16 (std::numeric_limits<std::uint16_t>::max)()
#define SBE_NULLVALUE_UINT32 (std::numeric_limits<std::uint32_t>::max)()
#define SBE_NULLVALUE_UINT64 (std::numeric_limits<std::uint64_t>::max)()
#include "MDEntryTypeBook.h"
#include "OpenCloseSettlFlag.h"
#include "MatchEventIndicator.h"
#include "MaturityMonthYear.h"
#include "FLOAT.h"
#include "MDEntryTypeDailyStatistics.h"
#include "EventType.h"
#include "DecimalQty.h"
#include "MDUpdateAction.h"
#include "PRICENULL9.h"
#include "GroupSize8Byte.h"
#include "HaltReason.h"
#include "PRICE9.h"
#include "MDEntryType.h"
#include "PRICENULL.h"
#include "SecurityTradingStatus.h"
#include "LegSide.h"
#include "MessageHeader.h"
#include "PRICE.h"
#include "OrderUpdateAction.h"
#include "PutOrCall.h"
#include "SecurityUpdateAction.h"
#include "SecurityTradingEvent.h"
#include "Decimal9.h"
#include "MDEntryTypeStatistics.h"
#include "InstAttribValue.h"
#include "AggressorSide.h"
#include "GroupSize.h"
#include "SettlPriceType.h"
#include "Decimal9NULL.h"
namespace mdp3 {
class AdminLogin15
{
private:
char *m_buffer = nullptr;
std::uint64_t m_bufferLength = 0;
std::uint64_t m_offset = 0;
std::uint64_t m_position = 0;
std::uint64_t m_actingVersion = 0;
inline std::uint64_t *sbePositionPtr() SBE_NOEXCEPT
{
return &m_position;
}
public:
enum MetaAttribute
{
EPOCH, TIME_UNIT, SEMANTIC_TYPE, PRESENCE
};
union sbe_float_as_uint_u
{
float fp_value;
std::uint32_t uint_value;
};
union sbe_double_as_uint_u
{
double fp_value;
std::uint64_t uint_value;
};
AdminLogin15() = default;
AdminLogin15(
char *buffer,
const std::uint64_t offset,
const std::uint64_t bufferLength,
const std::uint64_t actingBlockLength,
const std::uint64_t actingVersion) :
m_buffer(buffer),
m_bufferLength(bufferLength),
m_offset(offset),
m_position(sbeCheckPosition(offset + actingBlockLength)),
m_actingVersion(actingVersion)
{
}
AdminLogin15(char *buffer, const std::uint64_t bufferLength) :
AdminLogin15(buffer, 0, bufferLength, sbeBlockLength(), sbeSchemaVersion())
{
}
AdminLogin15(
char *buffer,
const std::uint64_t bufferLength,
const std::uint64_t actingBlockLength,
const std::uint64_t actingVersion) :
AdminLogin15(buffer, 0, bufferLength, actingBlockLength, actingVersion)
{
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeBlockLength() SBE_NOEXCEPT
{
return (std::uint16_t)1;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeTemplateId() SBE_NOEXCEPT
{
return (std::uint16_t)15;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeSchemaId() SBE_NOEXCEPT
{
return (std::uint16_t)1;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeSchemaVersion() SBE_NOEXCEPT
{
return (std::uint16_t)9;
}
SBE_NODISCARD static SBE_CONSTEXPR const char * sbeSemanticType() SBE_NOEXCEPT
{
return "A";
}
SBE_NODISCARD std::uint64_t offset() const SBE_NOEXCEPT
{
return m_offset;
}
AdminLogin15 &wrapForEncode(char *buffer, const std::uint64_t offset, const std::uint64_t bufferLength)
{
return *this = AdminLogin15(buffer, offset, bufferLength, sbeBlockLength(), sbeSchemaVersion());
}
AdminLogin15 &wrapAndApplyHeader(char *buffer, const std::uint64_t offset, const std::uint64_t bufferLength)
{
MessageHeader hdr(buffer, offset, bufferLength, sbeSchemaVersion());
hdr
.blockLength(sbeBlockLength())
.templateId(sbeTemplateId())
.schemaId(sbeSchemaId())
.version(sbeSchemaVersion());
return *this = AdminLogin15(
buffer,
offset + MessageHeader::encodedLength(),
bufferLength,
sbeBlockLength(),
sbeSchemaVersion());
}
AdminLogin15 &wrapForDecode(
char *buffer,
const std::uint64_t offset,
const std::uint64_t actingBlockLength,
const std::uint64_t actingVersion,
const std::uint64_t bufferLength)
{
return *this = AdminLogin15(buffer, offset, bufferLength, actingBlockLength, actingVersion);
}
SBE_NODISCARD std::uint64_t sbePosition() const SBE_NOEXCEPT
{
return m_position;
}
std::uint64_t sbeCheckPosition(const std::uint64_t position)
{
if (SBE_BOUNDS_CHECK_EXPECT((position > m_bufferLength), false))
{
throw std::runtime_error("buffer too short [E100]");
}
return position;
}
void sbePosition(const std::uint64_t position)
{
m_position = sbeCheckPosition(position);
}
SBE_NODISCARD std::uint64_t encodedLength() const SBE_NOEXCEPT
{
return sbePosition() - m_offset;
}
SBE_NODISCARD const char * buffer() const SBE_NOEXCEPT
{
return m_buffer;
}
SBE_NODISCARD char * buffer() SBE_NOEXCEPT
{
return m_buffer;
}
SBE_NODISCARD std::uint64_t bufferLength() const SBE_NOEXCEPT
{
return m_bufferLength;
}
SBE_NODISCARD std::uint64_t actingVersion() const SBE_NOEXCEPT
{
return m_actingVersion;
}
SBE_NODISCARD static const char * HeartBtIntMetaAttribute(const MetaAttribute metaAttribute) SBE_NOEXCEPT
{
switch (metaAttribute)
{
case MetaAttribute::SEMANTIC_TYPE: return "int";
case MetaAttribute::PRESENCE: return "required";
default: return "";
}
}
static SBE_CONSTEXPR std::uint16_t heartBtIntId() SBE_NOEXCEPT
{
return 108;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint64_t heartBtIntSinceVersion() SBE_NOEXCEPT
{
return 0;
}
SBE_NODISCARD bool heartBtIntInActingVersion() SBE_NOEXCEPT
{
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
return m_actingVersion >= heartBtIntSinceVersion();
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}
SBE_NODISCARD static SBE_CONSTEXPR std::size_t heartBtIntEncodingOffset() SBE_NOEXCEPT
{
return 0;
}
static SBE_CONSTEXPR std::int8_t heartBtIntNullValue() SBE_NOEXCEPT
{
return SBE_NULLVALUE_INT8;
}
static SBE_CONSTEXPR std::int8_t heartBtIntMinValue() SBE_NOEXCEPT
{
return (std::int8_t)-127;
}
static SBE_CONSTEXPR std::int8_t heartBtIntMaxValue() SBE_NOEXCEPT
{
return (std::int8_t)127;
}
static SBE_CONSTEXPR std::size_t heartBtIntEncodingLength() SBE_NOEXCEPT
{
return 1;
}
SBE_NODISCARD std::int8_t heartBtInt() const SBE_NOEXCEPT
{
std::int8_t val;
std::memcpy(&val, m_buffer + m_offset + 0, sizeof(std::int8_t));
return (val);
}
AdminLogin15 &heartBtInt(const std::int8_t value) SBE_NOEXCEPT
{
std::int8_t val = (value);
std::memcpy(m_buffer + m_offset + 0, &val, sizeof(std::int8_t));
return *this;
}
template<typename CharT, typename Traits>
friend std::basic_ostream<CharT, Traits>& operator<<(
std::basic_ostream<CharT, Traits>& builder, AdminLogin15 _writer)
{
AdminLogin15 writer(_writer.m_buffer, _writer.m_offset,
_writer.m_bufferLength, _writer.sbeBlockLength(), _writer.m_actingVersion);
builder << '{';
builder << R"("Name": "AdminLogin15", )";
builder << R"("sbeTemplateId": )";
builder << writer.sbeTemplateId();
builder << ", ";
builder << R"("HeartBtInt": )";
builder << +writer.heartBtInt();
builder << '}';
return builder;
}
};
}
#endif
@@ -1,522 +0,0 @@
/* Generated SBE (Simple Binary Encoding) message codec */
#ifndef _MDP3_ADMINLOGOUT16_H_
#define _MDP3_ADMINLOGOUT16_H_
#if defined(SBE_HAVE_CMATH)
/* cmath needed for std::numeric_limits<double>::quiet_NaN() */
# include <cmath>
# define SBE_FLOAT_NAN std::numeric_limits<float>::quiet_NaN()
# define SBE_DOUBLE_NAN std::numeric_limits<double>::quiet_NaN()
#else
/* math.h needed for NAN */
# include <math.h>
# define SBE_FLOAT_NAN NAN
# define SBE_DOUBLE_NAN NAN
#endif
#if __cplusplus >= 201103L
# include <cstdint>
# include <string>
# include <cstring>
#endif
#if __cplusplus >= 201103L
# define SBE_CONSTEXPR constexpr
# define SBE_NOEXCEPT noexcept
#else
# define SBE_CONSTEXPR
# define SBE_NOEXCEPT
#endif
#if __cplusplus >= 201703L
# define SBE_NODISCARD [[nodiscard]]
#else
# define SBE_NODISCARD
#endif
#if !defined(__STDC_LIMIT_MACROS)
# define __STDC_LIMIT_MACROS 1
#endif
#include <cstdint>
#include <cstring>
#include <limits>
#include <stdexcept>
#include <ostream>
#include <sstream>
#include <iomanip>
#if defined(WIN32) || defined(_WIN32)
# define SBE_BIG_ENDIAN_ENCODE_16(v) _byteswap_ushort(v)
# define SBE_BIG_ENDIAN_ENCODE_32(v) _byteswap_ulong(v)
# define SBE_BIG_ENDIAN_ENCODE_64(v) _byteswap_uint64(v)
# define SBE_LITTLE_ENDIAN_ENCODE_16(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_32(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_64(v) (v)
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define SBE_BIG_ENDIAN_ENCODE_16(v) __builtin_bswap16(v)
# define SBE_BIG_ENDIAN_ENCODE_32(v) __builtin_bswap32(v)
# define SBE_BIG_ENDIAN_ENCODE_64(v) __builtin_bswap64(v)
# define SBE_LITTLE_ENDIAN_ENCODE_16(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_32(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_64(v) (v)
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define SBE_LITTLE_ENDIAN_ENCODE_16(v) __builtin_bswap16(v)
# define SBE_LITTLE_ENDIAN_ENCODE_32(v) __builtin_bswap32(v)
# define SBE_LITTLE_ENDIAN_ENCODE_64(v) __builtin_bswap64(v)
# define SBE_BIG_ENDIAN_ENCODE_16(v) (v)
# define SBE_BIG_ENDIAN_ENCODE_32(v) (v)
# define SBE_BIG_ENDIAN_ENCODE_64(v) (v)
#else
# error "Byte Ordering of platform not determined. Set __BYTE_ORDER__ manually before including this file."
#endif
#if defined(SBE_NO_BOUNDS_CHECK)
# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (false)
#elif defined(_MSC_VER)
# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (exp)
#else
# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (__builtin_expect(exp,c))
#endif
#define SBE_NULLVALUE_INT8 (std::numeric_limits<std::int8_t>::min)()
#define SBE_NULLVALUE_INT16 (std::numeric_limits<std::int16_t>::min)()
#define SBE_NULLVALUE_INT32 (std::numeric_limits<std::int32_t>::min)()
#define SBE_NULLVALUE_INT64 (std::numeric_limits<std::int64_t>::min)()
#define SBE_NULLVALUE_UINT8 (std::numeric_limits<std::uint8_t>::max)()
#define SBE_NULLVALUE_UINT16 (std::numeric_limits<std::uint16_t>::max)()
#define SBE_NULLVALUE_UINT32 (std::numeric_limits<std::uint32_t>::max)()
#define SBE_NULLVALUE_UINT64 (std::numeric_limits<std::uint64_t>::max)()
#include "MDEntryTypeBook.h"
#include "OpenCloseSettlFlag.h"
#include "MatchEventIndicator.h"
#include "MaturityMonthYear.h"
#include "FLOAT.h"
#include "MDEntryTypeDailyStatistics.h"
#include "EventType.h"
#include "DecimalQty.h"
#include "MDUpdateAction.h"
#include "PRICENULL9.h"
#include "GroupSize8Byte.h"
#include "HaltReason.h"
#include "PRICE9.h"
#include "MDEntryType.h"
#include "PRICENULL.h"
#include "SecurityTradingStatus.h"
#include "LegSide.h"
#include "MessageHeader.h"
#include "PRICE.h"
#include "OrderUpdateAction.h"
#include "PutOrCall.h"
#include "SecurityUpdateAction.h"
#include "SecurityTradingEvent.h"
#include "Decimal9.h"
#include "MDEntryTypeStatistics.h"
#include "InstAttribValue.h"
#include "AggressorSide.h"
#include "GroupSize.h"
#include "SettlPriceType.h"
#include "Decimal9NULL.h"
namespace mdp3 {
class AdminLogout16
{
private:
char *m_buffer = nullptr;
std::uint64_t m_bufferLength = 0;
std::uint64_t m_offset = 0;
std::uint64_t m_position = 0;
std::uint64_t m_actingVersion = 0;
inline std::uint64_t *sbePositionPtr() SBE_NOEXCEPT
{
return &m_position;
}
public:
enum MetaAttribute
{
EPOCH, TIME_UNIT, SEMANTIC_TYPE, PRESENCE
};
union sbe_float_as_uint_u
{
float fp_value;
std::uint32_t uint_value;
};
union sbe_double_as_uint_u
{
double fp_value;
std::uint64_t uint_value;
};
AdminLogout16() = default;
AdminLogout16(
char *buffer,
const std::uint64_t offset,
const std::uint64_t bufferLength,
const std::uint64_t actingBlockLength,
const std::uint64_t actingVersion) :
m_buffer(buffer),
m_bufferLength(bufferLength),
m_offset(offset),
m_position(sbeCheckPosition(offset + actingBlockLength)),
m_actingVersion(actingVersion)
{
}
AdminLogout16(char *buffer, const std::uint64_t bufferLength) :
AdminLogout16(buffer, 0, bufferLength, sbeBlockLength(), sbeSchemaVersion())
{
}
AdminLogout16(
char *buffer,
const std::uint64_t bufferLength,
const std::uint64_t actingBlockLength,
const std::uint64_t actingVersion) :
AdminLogout16(buffer, 0, bufferLength, actingBlockLength, actingVersion)
{
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeBlockLength() SBE_NOEXCEPT
{
return (std::uint16_t)180;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeTemplateId() SBE_NOEXCEPT
{
return (std::uint16_t)16;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeSchemaId() SBE_NOEXCEPT
{
return (std::uint16_t)1;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeSchemaVersion() SBE_NOEXCEPT
{
return (std::uint16_t)9;
}
SBE_NODISCARD static SBE_CONSTEXPR const char * sbeSemanticType() SBE_NOEXCEPT
{
return "5";
}
SBE_NODISCARD std::uint64_t offset() const SBE_NOEXCEPT
{
return m_offset;
}
AdminLogout16 &wrapForEncode(char *buffer, const std::uint64_t offset, const std::uint64_t bufferLength)
{
return *this = AdminLogout16(buffer, offset, bufferLength, sbeBlockLength(), sbeSchemaVersion());
}
AdminLogout16 &wrapAndApplyHeader(char *buffer, const std::uint64_t offset, const std::uint64_t bufferLength)
{
MessageHeader hdr(buffer, offset, bufferLength, sbeSchemaVersion());
hdr
.blockLength(sbeBlockLength())
.templateId(sbeTemplateId())
.schemaId(sbeSchemaId())
.version(sbeSchemaVersion());
return *this = AdminLogout16(
buffer,
offset + MessageHeader::encodedLength(),
bufferLength,
sbeBlockLength(),
sbeSchemaVersion());
}
AdminLogout16 &wrapForDecode(
char *buffer,
const std::uint64_t offset,
const std::uint64_t actingBlockLength,
const std::uint64_t actingVersion,
const std::uint64_t bufferLength)
{
return *this = AdminLogout16(buffer, offset, bufferLength, actingBlockLength, actingVersion);
}
SBE_NODISCARD std::uint64_t sbePosition() const SBE_NOEXCEPT
{
return m_position;
}
std::uint64_t sbeCheckPosition(const std::uint64_t position)
{
if (SBE_BOUNDS_CHECK_EXPECT((position > m_bufferLength), false))
{
throw std::runtime_error("buffer too short [E100]");
}
return position;
}
void sbePosition(const std::uint64_t position)
{
m_position = sbeCheckPosition(position);
}
SBE_NODISCARD std::uint64_t encodedLength() const SBE_NOEXCEPT
{
return sbePosition() - m_offset;
}
SBE_NODISCARD const char * buffer() const SBE_NOEXCEPT
{
return m_buffer;
}
SBE_NODISCARD char * buffer() SBE_NOEXCEPT
{
return m_buffer;
}
SBE_NODISCARD std::uint64_t bufferLength() const SBE_NOEXCEPT
{
return m_bufferLength;
}
SBE_NODISCARD std::uint64_t actingVersion() const SBE_NOEXCEPT
{
return m_actingVersion;
}
SBE_NODISCARD static const char * TextMetaAttribute(const MetaAttribute metaAttribute) SBE_NOEXCEPT
{
switch (metaAttribute)
{
case MetaAttribute::SEMANTIC_TYPE: return "String";
case MetaAttribute::PRESENCE: return "required";
default: return "";
}
}
static SBE_CONSTEXPR std::uint16_t textId() SBE_NOEXCEPT
{
return 58;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint64_t textSinceVersion() SBE_NOEXCEPT
{
return 0;
}
SBE_NODISCARD bool textInActingVersion() SBE_NOEXCEPT
{
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
return m_actingVersion >= textSinceVersion();
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}
SBE_NODISCARD static SBE_CONSTEXPR std::size_t textEncodingOffset() SBE_NOEXCEPT
{
return 0;
}
static SBE_CONSTEXPR char textNullValue() SBE_NOEXCEPT
{
return (char)0;
}
static SBE_CONSTEXPR char textMinValue() SBE_NOEXCEPT
{
return (char)32;
}
static SBE_CONSTEXPR char textMaxValue() SBE_NOEXCEPT
{
return (char)126;
}
static SBE_CONSTEXPR std::size_t textEncodingLength() SBE_NOEXCEPT
{
return 180;
}
static SBE_CONSTEXPR std::uint64_t textLength() SBE_NOEXCEPT
{
return 180;
}
SBE_NODISCARD const char *text() const SBE_NOEXCEPT
{
return m_buffer + m_offset + 0;
}
SBE_NODISCARD char *text() SBE_NOEXCEPT
{
return m_buffer + m_offset + 0;
}
SBE_NODISCARD char text(const std::uint64_t index) const
{
if (index >= 180)
{
throw std::runtime_error("index out of range for text [E104]");
}
char val;
std::memcpy(&val, m_buffer + m_offset + 0 + (index * 1), sizeof(char));
return (val);
}
AdminLogout16 &text(const std::uint64_t index, const char value)
{
if (index >= 180)
{
throw std::runtime_error("index out of range for text [E105]");
}
char val = (value);
std::memcpy(m_buffer + m_offset + 0 + (index * 1), &val, sizeof(char));
return *this;
}
std::uint64_t getText(char *const dst, const std::uint64_t length) const
{
if (length > 180)
{
throw std::runtime_error("length too large for getText [E106]");
}
std::memcpy(dst, m_buffer + m_offset + 0, sizeof(char) * static_cast<size_t>(length));
return length;
}
AdminLogout16 &putText(const char *const src) SBE_NOEXCEPT
{
std::memcpy(m_buffer + m_offset + 0, src, sizeof(char) * 180);
return *this;
}
std::string getTextAsString() const
{
const char *buffer = m_buffer + m_offset + 0;
size_t length = 0;
for (; length < 180 && *(buffer + length) != '\0'; ++length);
std::string result(buffer, length);
return result;
}
std::string getTextAsJsonEscapedString()
{
std::ostringstream oss;
std::string s = getTextAsString();
for (auto c = s.cbegin(); c != s.cend(); c++)
{
switch (*c)
{
case '"': oss << "\\\""; break;
case '\\': oss << "\\\\"; break;
case '\b': oss << "\\b"; break;
case '\f': oss << "\\f"; break;
case '\n': oss << "\\n"; break;
case '\r': oss << "\\r"; break;
case '\t': oss << "\\t"; break;
default:
if ('\x00' <= *c && *c <= '\x1f')
{
oss << "\\u" << std::hex << std::setw(4)
<< std::setfill('0') << (int)(*c);
}
else
{
oss << *c;
}
}
}
return oss.str();
}
#if __cplusplus >= 201703L
std::string_view getTextAsStringView() const SBE_NOEXCEPT
{
const char *buffer = m_buffer + m_offset + 0;
size_t length = 0;
for (; length < 180 && *(buffer + length) != '\0'; ++length);
std::string_view result(buffer, length);
return result;
}
#endif
#if __cplusplus >= 201703L
AdminLogout16 &putText(const std::string_view str)
{
const size_t srcLength = str.length();
if (srcLength > 180)
{
throw std::runtime_error("string too large for putText [E106]");
}
std::memcpy(m_buffer + m_offset + 0, str.data(), srcLength);
for (size_t start = srcLength; start < 180; ++start)
{
m_buffer[m_offset + 0 + start] = 0;
}
return *this;
}
#else
AdminLogout16 &putText(const std::string& str)
{
const size_t srcLength = str.length();
if (srcLength > 180)
{
throw std::runtime_error("string too large for putText [E106]");
}
std::memcpy(m_buffer + m_offset + 0, str.c_str(), srcLength);
for (size_t start = srcLength; start < 180; ++start)
{
m_buffer[m_offset + 0 + start] = 0;
}
return *this;
}
#endif
template<typename CharT, typename Traits>
friend std::basic_ostream<CharT, Traits>& operator<<(
std::basic_ostream<CharT, Traits>& builder, AdminLogout16 _writer)
{
AdminLogout16 writer(_writer.m_buffer, _writer.m_offset,
_writer.m_bufferLength, _writer.sbeBlockLength(), _writer.m_actingVersion);
builder << '{';
builder << R"("Name": "AdminLogout16", )";
builder << R"("sbeTemplateId": )";
builder << writer.sbeTemplateId();
builder << ", ";
builder << R"("Text": )";
builder << '"' <<
writer.getTextAsJsonEscapedString().c_str() << '"';
builder << '}';
return builder;
}
};
}
#endif
@@ -1,141 +0,0 @@
/* Generated SBE (Simple Binary Encoding) message codec */
#ifndef _MDP3_AGGRESSORSIDE_H_
#define _MDP3_AGGRESSORSIDE_H_
#if defined(SBE_HAVE_CMATH)
/* cmath needed for std::numeric_limits<double>::quiet_NaN() */
# include <cmath>
# define SBE_FLOAT_NAN std::numeric_limits<float>::quiet_NaN()
# define SBE_DOUBLE_NAN std::numeric_limits<double>::quiet_NaN()
#else
/* math.h needed for NAN */
# include <math.h>
# define SBE_FLOAT_NAN NAN
# define SBE_DOUBLE_NAN NAN
#endif
#if __cplusplus >= 201103L
# include <cstdint>
# include <string>
# include <cstring>
#endif
#if __cplusplus >= 201103L
# define SBE_CONSTEXPR constexpr
# define SBE_NOEXCEPT noexcept
#else
# define SBE_CONSTEXPR
# define SBE_NOEXCEPT
#endif
#if __cplusplus >= 201703L
# define SBE_NODISCARD [[nodiscard]]
#else
# define SBE_NODISCARD
#endif
#if !defined(__STDC_LIMIT_MACROS)
# define __STDC_LIMIT_MACROS 1
#endif
#include <cstdint>
#include <cstring>
#include <limits>
#include <stdexcept>
#include <ostream>
#include <sstream>
#include <iomanip>
#if defined(WIN32) || defined(_WIN32)
# define SBE_BIG_ENDIAN_ENCODE_16(v) _byteswap_ushort(v)
# define SBE_BIG_ENDIAN_ENCODE_32(v) _byteswap_ulong(v)
# define SBE_BIG_ENDIAN_ENCODE_64(v) _byteswap_uint64(v)
# define SBE_LITTLE_ENDIAN_ENCODE_16(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_32(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_64(v) (v)
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define SBE_BIG_ENDIAN_ENCODE_16(v) __builtin_bswap16(v)
# define SBE_BIG_ENDIAN_ENCODE_32(v) __builtin_bswap32(v)
# define SBE_BIG_ENDIAN_ENCODE_64(v) __builtin_bswap64(v)
# define SBE_LITTLE_ENDIAN_ENCODE_16(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_32(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_64(v) (v)
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define SBE_LITTLE_ENDIAN_ENCODE_16(v) __builtin_bswap16(v)
# define SBE_LITTLE_ENDIAN_ENCODE_32(v) __builtin_bswap32(v)
# define SBE_LITTLE_ENDIAN_ENCODE_64(v) __builtin_bswap64(v)
# define SBE_BIG_ENDIAN_ENCODE_16(v) (v)
# define SBE_BIG_ENDIAN_ENCODE_32(v) (v)
# define SBE_BIG_ENDIAN_ENCODE_64(v) (v)
#else
# error "Byte Ordering of platform not determined. Set __BYTE_ORDER__ manually before including this file."
#endif
#if defined(SBE_NO_BOUNDS_CHECK)
# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (false)
#elif defined(_MSC_VER)
# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (exp)
#else
# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (__builtin_expect(exp,c))
#endif
#define SBE_NULLVALUE_INT8 (std::numeric_limits<std::int8_t>::min)()
#define SBE_NULLVALUE_INT16 (std::numeric_limits<std::int16_t>::min)()
#define SBE_NULLVALUE_INT32 (std::numeric_limits<std::int32_t>::min)()
#define SBE_NULLVALUE_INT64 (std::numeric_limits<std::int64_t>::min)()
#define SBE_NULLVALUE_UINT8 (std::numeric_limits<std::uint8_t>::max)()
#define SBE_NULLVALUE_UINT16 (std::numeric_limits<std::uint16_t>::max)()
#define SBE_NULLVALUE_UINT32 (std::numeric_limits<std::uint32_t>::max)()
#define SBE_NULLVALUE_UINT64 (std::numeric_limits<std::uint64_t>::max)()
namespace mdp3 {
class AggressorSide
{
public:
enum Value
{
NoAggressor = (std::uint8_t)0,
Buy = (std::uint8_t)1,
Sell = (std::uint8_t)2,
NULL_VALUE = (std::uint8_t)255
};
static AggressorSide::Value get(const std::uint8_t value)
{
switch (value)
{
case 0: return NoAggressor;
case 1: return Buy;
case 2: return Sell;
case 255: return NULL_VALUE;
}
throw std::runtime_error("unknown value for enum AggressorSide [E103]");
}
static const char* c_str(const AggressorSide::Value value)
{
switch (value)
{
case NoAggressor: return "NoAggressor";
case Buy: return "Buy";
case Sell: return "Sell";
case NULL_VALUE: return "NULL_VALUE";
}
throw std::runtime_error("unknown value for enum AggressorSide [E103]:");
}
template<typename CharT, typename Traits>
friend std::basic_ostream<CharT, Traits>& operator<<(
std::basic_ostream<CharT, Traits>& os, AggressorSide::Value m)
{
return os << AggressorSide::c_str(m);
}
};
}
#endif
@@ -1,928 +0,0 @@
/* Generated SBE (Simple Binary Encoding) message codec */
#ifndef _MDP3_CHANNELRESET4_H_
#define _MDP3_CHANNELRESET4_H_
#if defined(SBE_HAVE_CMATH)
/* cmath needed for std::numeric_limits<double>::quiet_NaN() */
# include <cmath>
# define SBE_FLOAT_NAN std::numeric_limits<float>::quiet_NaN()
# define SBE_DOUBLE_NAN std::numeric_limits<double>::quiet_NaN()
#else
/* math.h needed for NAN */
# include <math.h>
# define SBE_FLOAT_NAN NAN
# define SBE_DOUBLE_NAN NAN
#endif
#if __cplusplus >= 201103L
# include <cstdint>
# include <string>
# include <cstring>
#endif
#if __cplusplus >= 201103L
# define SBE_CONSTEXPR constexpr
# define SBE_NOEXCEPT noexcept
#else
# define SBE_CONSTEXPR
# define SBE_NOEXCEPT
#endif
#if __cplusplus >= 201703L
# define SBE_NODISCARD [[nodiscard]]
#else
# define SBE_NODISCARD
#endif
#if !defined(__STDC_LIMIT_MACROS)
# define __STDC_LIMIT_MACROS 1
#endif
#include <cstdint>
#include <cstring>
#include <limits>
#include <stdexcept>
#include <ostream>
#include <sstream>
#include <iomanip>
#if defined(WIN32) || defined(_WIN32)
# define SBE_BIG_ENDIAN_ENCODE_16(v) _byteswap_ushort(v)
# define SBE_BIG_ENDIAN_ENCODE_32(v) _byteswap_ulong(v)
# define SBE_BIG_ENDIAN_ENCODE_64(v) _byteswap_uint64(v)
# define SBE_LITTLE_ENDIAN_ENCODE_16(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_32(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_64(v) (v)
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define SBE_BIG_ENDIAN_ENCODE_16(v) __builtin_bswap16(v)
# define SBE_BIG_ENDIAN_ENCODE_32(v) __builtin_bswap32(v)
# define SBE_BIG_ENDIAN_ENCODE_64(v) __builtin_bswap64(v)
# define SBE_LITTLE_ENDIAN_ENCODE_16(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_32(v) (v)
# define SBE_LITTLE_ENDIAN_ENCODE_64(v) (v)
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define SBE_LITTLE_ENDIAN_ENCODE_16(v) __builtin_bswap16(v)
# define SBE_LITTLE_ENDIAN_ENCODE_32(v) __builtin_bswap32(v)
# define SBE_LITTLE_ENDIAN_ENCODE_64(v) __builtin_bswap64(v)
# define SBE_BIG_ENDIAN_ENCODE_16(v) (v)
# define SBE_BIG_ENDIAN_ENCODE_32(v) (v)
# define SBE_BIG_ENDIAN_ENCODE_64(v) (v)
#else
# error "Byte Ordering of platform not determined. Set __BYTE_ORDER__ manually before including this file."
#endif
#if defined(SBE_NO_BOUNDS_CHECK)
# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (false)
#elif defined(_MSC_VER)
# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (exp)
#else
# define SBE_BOUNDS_CHECK_EXPECT(exp,c) (__builtin_expect(exp,c))
#endif
#define SBE_NULLVALUE_INT8 (std::numeric_limits<std::int8_t>::min)()
#define SBE_NULLVALUE_INT16 (std::numeric_limits<std::int16_t>::min)()
#define SBE_NULLVALUE_INT32 (std::numeric_limits<std::int32_t>::min)()
#define SBE_NULLVALUE_INT64 (std::numeric_limits<std::int64_t>::min)()
#define SBE_NULLVALUE_UINT8 (std::numeric_limits<std::uint8_t>::max)()
#define SBE_NULLVALUE_UINT16 (std::numeric_limits<std::uint16_t>::max)()
#define SBE_NULLVALUE_UINT32 (std::numeric_limits<std::uint32_t>::max)()
#define SBE_NULLVALUE_UINT64 (std::numeric_limits<std::uint64_t>::max)()
#include "MDEntryTypeBook.h"
#include "OpenCloseSettlFlag.h"
#include "MatchEventIndicator.h"
#include "MaturityMonthYear.h"
#include "FLOAT.h"
#include "MDEntryTypeDailyStatistics.h"
#include "EventType.h"
#include "DecimalQty.h"
#include "MDUpdateAction.h"
#include "PRICENULL9.h"
#include "GroupSize8Byte.h"
#include "HaltReason.h"
#include "PRICE9.h"
#include "MDEntryType.h"
#include "PRICENULL.h"
#include "SecurityTradingStatus.h"
#include "LegSide.h"
#include "MessageHeader.h"
#include "PRICE.h"
#include "OrderUpdateAction.h"
#include "PutOrCall.h"
#include "SecurityUpdateAction.h"
#include "SecurityTradingEvent.h"
#include "Decimal9.h"
#include "MDEntryTypeStatistics.h"
#include "InstAttribValue.h"
#include "AggressorSide.h"
#include "GroupSize.h"
#include "SettlPriceType.h"
#include "Decimal9NULL.h"
namespace mdp3 {
class ChannelReset4
{
private:
char *m_buffer = nullptr;
std::uint64_t m_bufferLength = 0;
std::uint64_t m_offset = 0;
std::uint64_t m_position = 0;
std::uint64_t m_actingVersion = 0;
inline std::uint64_t *sbePositionPtr() SBE_NOEXCEPT
{
return &m_position;
}
public:
enum MetaAttribute
{
EPOCH, TIME_UNIT, SEMANTIC_TYPE, PRESENCE
};
union sbe_float_as_uint_u
{
float fp_value;
std::uint32_t uint_value;
};
union sbe_double_as_uint_u
{
double fp_value;
std::uint64_t uint_value;
};
ChannelReset4() = default;
ChannelReset4(
char *buffer,
const std::uint64_t offset,
const std::uint64_t bufferLength,
const std::uint64_t actingBlockLength,
const std::uint64_t actingVersion) :
m_buffer(buffer),
m_bufferLength(bufferLength),
m_offset(offset),
m_position(sbeCheckPosition(offset + actingBlockLength)),
m_actingVersion(actingVersion)
{
}
ChannelReset4(char *buffer, const std::uint64_t bufferLength) :
ChannelReset4(buffer, 0, bufferLength, sbeBlockLength(), sbeSchemaVersion())
{
}
ChannelReset4(
char *buffer,
const std::uint64_t bufferLength,
const std::uint64_t actingBlockLength,
const std::uint64_t actingVersion) :
ChannelReset4(buffer, 0, bufferLength, actingBlockLength, actingVersion)
{
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeBlockLength() SBE_NOEXCEPT
{
return (std::uint16_t)9;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeTemplateId() SBE_NOEXCEPT
{
return (std::uint16_t)4;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeSchemaId() SBE_NOEXCEPT
{
return (std::uint16_t)1;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t sbeSchemaVersion() SBE_NOEXCEPT
{
return (std::uint16_t)9;
}
SBE_NODISCARD static SBE_CONSTEXPR const char * sbeSemanticType() SBE_NOEXCEPT
{
return "X";
}
SBE_NODISCARD std::uint64_t offset() const SBE_NOEXCEPT
{
return m_offset;
}
ChannelReset4 &wrapForEncode(char *buffer, const std::uint64_t offset, const std::uint64_t bufferLength)
{
return *this = ChannelReset4(buffer, offset, bufferLength, sbeBlockLength(), sbeSchemaVersion());
}
ChannelReset4 &wrapAndApplyHeader(char *buffer, const std::uint64_t offset, const std::uint64_t bufferLength)
{
MessageHeader hdr(buffer, offset, bufferLength, sbeSchemaVersion());
hdr
.blockLength(sbeBlockLength())
.templateId(sbeTemplateId())
.schemaId(sbeSchemaId())
.version(sbeSchemaVersion());
return *this = ChannelReset4(
buffer,
offset + MessageHeader::encodedLength(),
bufferLength,
sbeBlockLength(),
sbeSchemaVersion());
}
ChannelReset4 &wrapForDecode(
char *buffer,
const std::uint64_t offset,
const std::uint64_t actingBlockLength,
const std::uint64_t actingVersion,
const std::uint64_t bufferLength)
{
return *this = ChannelReset4(buffer, offset, bufferLength, actingBlockLength, actingVersion);
}
SBE_NODISCARD std::uint64_t sbePosition() const SBE_NOEXCEPT
{
return m_position;
}
std::uint64_t sbeCheckPosition(const std::uint64_t position)
{
if (SBE_BOUNDS_CHECK_EXPECT((position > m_bufferLength), false))
{
throw std::runtime_error("buffer too short [E100]");
}
return position;
}
void sbePosition(const std::uint64_t position)
{
m_position = sbeCheckPosition(position);
}
SBE_NODISCARD std::uint64_t encodedLength() const SBE_NOEXCEPT
{
return sbePosition() - m_offset;
}
SBE_NODISCARD const char * buffer() const SBE_NOEXCEPT
{
return m_buffer;
}
SBE_NODISCARD char * buffer() SBE_NOEXCEPT
{
return m_buffer;
}
SBE_NODISCARD std::uint64_t bufferLength() const SBE_NOEXCEPT
{
return m_bufferLength;
}
SBE_NODISCARD std::uint64_t actingVersion() const SBE_NOEXCEPT
{
return m_actingVersion;
}
SBE_NODISCARD static const char * TransactTimeMetaAttribute(const MetaAttribute metaAttribute) SBE_NOEXCEPT
{
switch (metaAttribute)
{
case MetaAttribute::SEMANTIC_TYPE: return "UTCTimestamp";
case MetaAttribute::PRESENCE: return "required";
default: return "";
}
}
static SBE_CONSTEXPR std::uint16_t transactTimeId() SBE_NOEXCEPT
{
return 60;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint64_t transactTimeSinceVersion() SBE_NOEXCEPT
{
return 0;
}
SBE_NODISCARD bool transactTimeInActingVersion() SBE_NOEXCEPT
{
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
return m_actingVersion >= transactTimeSinceVersion();
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}
SBE_NODISCARD static SBE_CONSTEXPR std::size_t transactTimeEncodingOffset() SBE_NOEXCEPT
{
return 0;
}
static SBE_CONSTEXPR std::uint64_t transactTimeNullValue() SBE_NOEXCEPT
{
return SBE_NULLVALUE_UINT64;
}
static SBE_CONSTEXPR std::uint64_t transactTimeMinValue() SBE_NOEXCEPT
{
return 0x0L;
}
static SBE_CONSTEXPR std::uint64_t transactTimeMaxValue() SBE_NOEXCEPT
{
return 0xfffffffffffffffeL;
}
static SBE_CONSTEXPR std::size_t transactTimeEncodingLength() SBE_NOEXCEPT
{
return 8;
}
SBE_NODISCARD std::uint64_t transactTime() const SBE_NOEXCEPT
{
std::uint64_t val;
std::memcpy(&val, m_buffer + m_offset + 0, sizeof(std::uint64_t));
return SBE_LITTLE_ENDIAN_ENCODE_64(val);
}
ChannelReset4 &transactTime(const std::uint64_t value) SBE_NOEXCEPT
{
std::uint64_t val = SBE_LITTLE_ENDIAN_ENCODE_64(value);
std::memcpy(m_buffer + m_offset + 0, &val, sizeof(std::uint64_t));
return *this;
}
SBE_NODISCARD static const char * MatchEventIndicatorMetaAttribute(const MetaAttribute metaAttribute) SBE_NOEXCEPT
{
switch (metaAttribute)
{
case MetaAttribute::SEMANTIC_TYPE: return "MultipleCharValue";
case MetaAttribute::PRESENCE: return "required";
default: return "";
}
}
static SBE_CONSTEXPR std::uint16_t matchEventIndicatorId() SBE_NOEXCEPT
{
return 5799;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint64_t matchEventIndicatorSinceVersion() SBE_NOEXCEPT
{
return 0;
}
SBE_NODISCARD bool matchEventIndicatorInActingVersion() SBE_NOEXCEPT
{
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
return m_actingVersion >= matchEventIndicatorSinceVersion();
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}
SBE_NODISCARD static SBE_CONSTEXPR std::size_t matchEventIndicatorEncodingOffset() SBE_NOEXCEPT
{
return 8;
}
private:
MatchEventIndicator m_matchEventIndicator;
public:
SBE_NODISCARD MatchEventIndicator &matchEventIndicator()
{
m_matchEventIndicator.wrap(m_buffer, m_offset + 8, m_actingVersion, m_bufferLength);
return m_matchEventIndicator;
}
static SBE_CONSTEXPR std::size_t matchEventIndicatorEncodingLength() SBE_NOEXCEPT
{
return 1;
}
class NoMDEntries
{
private:
char *m_buffer = nullptr;
std::uint64_t m_bufferLength = 0;
std::uint64_t m_initialPosition = 0;
std::uint64_t *m_positionPtr = nullptr;
std::uint64_t m_blockLength = 0;
std::uint64_t m_count = 0;
std::uint64_t m_index = 0;
std::uint64_t m_offset = 0;
std::uint64_t m_actingVersion = 0;
SBE_NODISCARD std::uint64_t *sbePositionPtr() SBE_NOEXCEPT
{
return m_positionPtr;
}
public:
inline void wrapForDecode(
char *buffer,
std::uint64_t *pos,
const std::uint64_t actingVersion,
const std::uint64_t bufferLength)
{
GroupSize dimensions(buffer, *pos, bufferLength, actingVersion);
m_buffer = buffer;
m_bufferLength = bufferLength;
m_blockLength = dimensions.blockLength();
m_count = dimensions.numInGroup();
m_index = 0;
m_actingVersion = actingVersion;
m_initialPosition = *pos;
m_positionPtr = pos;
*m_positionPtr = *m_positionPtr + 3;
}
inline void wrapForEncode(
char *buffer,
const std::uint8_t count,
std::uint64_t *pos,
const std::uint64_t actingVersion,
const std::uint64_t bufferLength)
{
#if defined(__GNUG__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
#endif
if (count > 254)
{
throw std::runtime_error("count outside of allowed range [E110]");
}
#if defined(__GNUG__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
m_buffer = buffer;
m_bufferLength = bufferLength;
GroupSize dimensions(buffer, *pos, bufferLength, actingVersion);
dimensions.blockLength((std::uint16_t)2);
dimensions.numInGroup((std::uint8_t)count);
m_index = 0;
m_count = count;
m_blockLength = 2;
m_actingVersion = actingVersion;
m_initialPosition = *pos;
m_positionPtr = pos;
*m_positionPtr = *m_positionPtr + 3;
}
static SBE_CONSTEXPR std::uint64_t sbeHeaderSize() SBE_NOEXCEPT
{
return 3;
}
static SBE_CONSTEXPR std::uint64_t sbeBlockLength() SBE_NOEXCEPT
{
return 2;
}
SBE_NODISCARD std::uint64_t sbePosition() const
{
return *m_positionPtr;
}
std::uint64_t sbeCheckPosition(const std::uint64_t position)
{
if (SBE_BOUNDS_CHECK_EXPECT((position > m_bufferLength), false))
{
throw std::runtime_error("buffer too short [E100]");
}
return position;
}
void sbePosition(const std::uint64_t position)
{
*m_positionPtr = sbeCheckPosition(position);
}
SBE_NODISCARD inline std::uint64_t count() const SBE_NOEXCEPT
{
return m_count;
}
SBE_NODISCARD inline bool hasNext() const SBE_NOEXCEPT
{
return m_index < m_count;
}
inline NoMDEntries &next()
{
if (m_index >= m_count)
{
throw std::runtime_error("index >= count [E108]");
}
m_offset = *m_positionPtr;
if (SBE_BOUNDS_CHECK_EXPECT(((m_offset + m_blockLength) > m_bufferLength), false))
{
throw std::runtime_error("buffer too short for next group index [E108]");
}
*m_positionPtr = m_offset + m_blockLength;
++m_index;
return *this;
}
inline std::uint64_t resetCountToIndex() SBE_NOEXCEPT
{
m_count = m_index;
GroupSize dimensions(m_buffer, m_initialPosition, m_bufferLength, m_actingVersion);
dimensions.numInGroup((std::uint8_t)m_count);
return m_count;
}
#if __cplusplus < 201103L
template<class Func> inline void forEach(Func& func)
{
while (hasNext())
{
next();
func(*this);
}
}
#else
template<class Func> inline void forEach(Func&& func)
{
while (hasNext())
{
next();
func(*this);
}
}
#endif
SBE_NODISCARD static const char * MDUpdateActionMetaAttribute(const MetaAttribute metaAttribute) SBE_NOEXCEPT
{
switch (metaAttribute)
{
case MetaAttribute::SEMANTIC_TYPE: return "int";
case MetaAttribute::PRESENCE: return "constant";
default: return "";
}
}
static SBE_CONSTEXPR std::uint16_t mDUpdateActionId() SBE_NOEXCEPT
{
return 279;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint64_t mDUpdateActionSinceVersion() SBE_NOEXCEPT
{
return 2;
}
SBE_NODISCARD bool mDUpdateActionInActingVersion() SBE_NOEXCEPT
{
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
return m_actingVersion >= mDUpdateActionSinceVersion();
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}
SBE_NODISCARD static SBE_CONSTEXPR std::size_t mDUpdateActionEncodingOffset() SBE_NOEXCEPT
{
return 0;
}
static SBE_CONSTEXPR std::int8_t mDUpdateActionNullValue() SBE_NOEXCEPT
{
return SBE_NULLVALUE_INT8;
}
static SBE_CONSTEXPR std::int8_t mDUpdateActionMinValue() SBE_NOEXCEPT
{
return (std::int8_t)-127;
}
static SBE_CONSTEXPR std::int8_t mDUpdateActionMaxValue() SBE_NOEXCEPT
{
return (std::int8_t)127;
}
static SBE_CONSTEXPR std::size_t mDUpdateActionEncodingLength() SBE_NOEXCEPT
{
return 0;
}
SBE_NODISCARD static SBE_CONSTEXPR std::int8_t mDUpdateAction() SBE_NOEXCEPT
{
return (std::int8_t)0;
}
SBE_NODISCARD static const char * MDEntryTypeMetaAttribute(const MetaAttribute metaAttribute) SBE_NOEXCEPT
{
switch (metaAttribute)
{
case MetaAttribute::SEMANTIC_TYPE: return "char";
case MetaAttribute::PRESENCE: return "constant";
default: return "";
}
}
static SBE_CONSTEXPR std::uint16_t mDEntryTypeId() SBE_NOEXCEPT
{
return 269;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint64_t mDEntryTypeSinceVersion() SBE_NOEXCEPT
{
return 0;
}
SBE_NODISCARD bool mDEntryTypeInActingVersion() SBE_NOEXCEPT
{
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
return m_actingVersion >= mDEntryTypeSinceVersion();
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}
SBE_NODISCARD static SBE_CONSTEXPR std::size_t mDEntryTypeEncodingOffset() SBE_NOEXCEPT
{
return 0;
}
static SBE_CONSTEXPR char mDEntryTypeNullValue() SBE_NOEXCEPT
{
return (char)0;
}
static SBE_CONSTEXPR char mDEntryTypeMinValue() SBE_NOEXCEPT
{
return (char)32;
}
static SBE_CONSTEXPR char mDEntryTypeMaxValue() SBE_NOEXCEPT
{
return (char)126;
}
static SBE_CONSTEXPR std::size_t mDEntryTypeEncodingLength() SBE_NOEXCEPT
{
return 0;
}
static SBE_CONSTEXPR std::uint64_t mDEntryTypeLength() SBE_NOEXCEPT
{
return 1;
}
SBE_NODISCARD const char *mDEntryType() const
{
static const std::uint8_t mDEntryTypeValues[] = { 74 };
return (const char *)mDEntryTypeValues;
}
SBE_NODISCARD char mDEntryType(const std::uint64_t index) const
{
static const std::uint8_t mDEntryTypeValues[] = { 74 };
return (char)mDEntryTypeValues[index];
}
std::uint64_t getMDEntryType(char *dst, const std::uint64_t length) const
{
static std::uint8_t mDEntryTypeValues[] = { 74 };
std::uint64_t bytesToCopy = length < sizeof(mDEntryTypeValues) ? length : sizeof(mDEntryTypeValues);
std::memcpy(dst, mDEntryTypeValues, static_cast<size_t>(bytesToCopy));
return bytesToCopy;
}
std::string getMDEntryTypeAsString() const
{
static const std::uint8_t MDEntryTypeValues[] = { 74 };
return std::string((const char *)MDEntryTypeValues, 1);
}
std::string getMDEntryTypeAsJsonEscapedString()
{
std::ostringstream oss;
std::string s = getMDEntryTypeAsString();
for (auto c = s.cbegin(); c != s.cend(); c++)
{
switch (*c)
{
case '"': oss << "\\\""; break;
case '\\': oss << "\\\\"; break;
case '\b': oss << "\\b"; break;
case '\f': oss << "\\f"; break;
case '\n': oss << "\\n"; break;
case '\r': oss << "\\r"; break;
case '\t': oss << "\\t"; break;
default:
if ('\x00' <= *c && *c <= '\x1f')
{
oss << "\\u" << std::hex << std::setw(4)
<< std::setfill('0') << (int)(*c);
}
else
{
oss << *c;
}
}
}
return oss.str();
}
SBE_NODISCARD static const char * ApplIDMetaAttribute(const MetaAttribute metaAttribute) SBE_NOEXCEPT
{
switch (metaAttribute)
{
case MetaAttribute::SEMANTIC_TYPE: return "int";
case MetaAttribute::PRESENCE: return "required";
default: return "";
}
}
static SBE_CONSTEXPR std::uint16_t applIDId() SBE_NOEXCEPT
{
return 1180;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint64_t applIDSinceVersion() SBE_NOEXCEPT
{
return 3;
}
SBE_NODISCARD bool applIDInActingVersion() SBE_NOEXCEPT
{
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
return m_actingVersion >= applIDSinceVersion();
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}
SBE_NODISCARD static SBE_CONSTEXPR std::size_t applIDEncodingOffset() SBE_NOEXCEPT
{
return 0;
}
static SBE_CONSTEXPR std::int16_t applIDNullValue() SBE_NOEXCEPT
{
return SBE_NULLVALUE_INT16;
}
static SBE_CONSTEXPR std::int16_t applIDMinValue() SBE_NOEXCEPT
{
return (std::int16_t)-32767;
}
static SBE_CONSTEXPR std::int16_t applIDMaxValue() SBE_NOEXCEPT
{
return (std::int16_t)32767;
}
static SBE_CONSTEXPR std::size_t applIDEncodingLength() SBE_NOEXCEPT
{
return 2;
}
SBE_NODISCARD std::int16_t applID() const SBE_NOEXCEPT
{
if (m_actingVersion < 3)
{
return (std::int16_t)-32768;
}
std::int16_t val;
std::memcpy(&val, m_buffer + m_offset + 0, sizeof(std::int16_t));
return SBE_LITTLE_ENDIAN_ENCODE_16(val);
}
NoMDEntries &applID(const std::int16_t value) SBE_NOEXCEPT
{
std::int16_t val = SBE_LITTLE_ENDIAN_ENCODE_16(value);
std::memcpy(m_buffer + m_offset + 0, &val, sizeof(std::int16_t));
return *this;
}
template<typename CharT, typename Traits>
friend std::basic_ostream<CharT, Traits>& operator<<(
std::basic_ostream<CharT, Traits>& builder, NoMDEntries writer)
{
builder << '{';
builder << R"("ApplID": )";
builder << +writer.applID();
builder << '}';
return builder;
}
};
private:
NoMDEntries m_noMDEntries;
public:
SBE_NODISCARD static SBE_CONSTEXPR std::uint16_t NoMDEntriesId() SBE_NOEXCEPT
{
return 268;
}
SBE_NODISCARD inline NoMDEntries &noMDEntries()
{
m_noMDEntries.wrapForDecode(m_buffer, sbePositionPtr(), m_actingVersion, m_bufferLength);
return m_noMDEntries;
}
NoMDEntries &noMDEntriesCount(const std::uint8_t count)
{
m_noMDEntries.wrapForEncode(m_buffer, count, sbePositionPtr(), m_actingVersion, m_bufferLength);
return m_noMDEntries;
}
SBE_NODISCARD static SBE_CONSTEXPR std::uint64_t noMDEntriesSinceVersion() SBE_NOEXCEPT
{
return 0;
}
SBE_NODISCARD bool noMDEntriesInActingVersion() const SBE_NOEXCEPT
{
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
return m_actingVersion >= noMDEntriesSinceVersion();
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}
template<typename CharT, typename Traits>
friend std::basic_ostream<CharT, Traits>& operator<<(
std::basic_ostream<CharT, Traits>& builder, ChannelReset4 _writer)
{
ChannelReset4 writer(_writer.m_buffer, _writer.m_offset,
_writer.m_bufferLength, _writer.sbeBlockLength(), _writer.m_actingVersion);
builder << '{';
builder << R"("Name": "ChannelReset4", )";
builder << R"("sbeTemplateId": )";
builder << writer.sbeTemplateId();
builder << ", ";
builder << R"("TransactTime": )";
builder << +writer.transactTime();
builder << ", ";
builder << R"("MatchEventIndicator": )";
builder << writer.matchEventIndicator();
builder << ", ";
{
bool atLeastOne = false;
builder << R"("NoMDEntries": [)";
writer.noMDEntries().forEach([&](NoMDEntries& noMDEntries)
{
if (atLeastOne)
{
builder << ", ";
}
atLeastOne = true;
builder << noMDEntries;
});
builder << ']';
}
builder << '}';
return builder;
}
};
}
#endif
Loaded 100 of 200 files, more files were not shown because too many files have changed in this diff. Show more