now shove this c++ back into the sdk

This commit is contained in:
Kevin Darby committed 2019-07-17 14:27:22 -04:00
1 parent 2881e5ea32
commit d7ea71de84
8 files changed
+51 -22

No files matched your search

+1
View File
@@ -59,6 +59,7 @@ else ()
COMMAND ln ARGS -sf ${EXTERNALS_ROOT}/lib/Release/libACE-5.7.5.so ${CMAKE_BINARY_DIR}/server
COMMAND mkdir ARGS -p ${CMAKE_BINARY_DIR}/server/plugins
COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/sdk/examples/order_plugin_example.so ${CMAKE_BINARY_DIR}/server/plugins/
COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/sdk/examples/excel_plugin_example.so ${CMAKE_BINARY_DIR}/server/plugins/
COMMENT "Creating server runtime layout"
DEPENDS sparkd data_files_dir)
+2 -1
View File
@@ -56,7 +56,7 @@ namespace bts.excel
using (StreamReader reader = new StreamReader(stream))
{
string cpp = reader.ReadToEnd();
cpp = cpp.Replace("#define __AlgoName__", "//#define __#AlgoName__");
//cpp = cpp.Replace("#define __AlgoName__", "//#define __#AlgoName__");
cpp = cpp.Replace("#define __FunctionDefs__", "//#define __#FunctionDefs__");
cpp = cpp.Replace("#define __FunctionCalls__", "//#define __#FunctionCalls__");
cpp = cpp.Replace("#define __FunctionImpls__", "//#define __#FunctionImpls__");
@@ -68,6 +68,7 @@ namespace bts.excel
cpp = cpp.Replace("#define __ParameterLaunches__", "//#define __#ParameterLaunches__");
cpp = cpp.Replace("#define __ParameterUpdates__", "//#define __#ParameterUpdates__");
cpp = cpp.Replace("#define __ParameterSetups__", "//#define __#ParameterSetups__");
cpp = cpp.Replace("__Remove__", string.Empty);
cpp = cpp.Replace("__AlgoName__", algoname);
@@ -109,14 +109,6 @@ namespace bts.excel
[ExcelFunction(Category = "BTS", Description = "Resolve a security id from contract details")]
[SparkAlgoCode(
dual_definition = "SecurityKey spark_resolve_security_id();",
dual_impl = @"
SecurityKey __AlgoName__::sparkalgo_resolve_security_id()
{
auto sk = SecurityKey(algo_services().security().id())
return sk;
}
",
replacement_call = "sparkalgo_resolve_security_id()"
)]
public async static void sparkalgo_resolve_security_id(
+1 -2
View File
@@ -90,11 +90,10 @@
<ItemGroup>
<None Include="spark_excel_example_2018.xlsm"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></None>
<None Include="ExcelAlgoTemplate.cpp"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ExcelAlgoTemplate.cpp" />
<EmbeddedResource Include="../../sdk/examples/ExcelAlgoTemplate.cpp" />
</ItemGroup>
+2
View File
@@ -12,6 +12,8 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/sdk
${CMAKE_CURRENT_SOURCE_DIR}/examples/build_examples.sh
${CMAKE_CURRENT_SOURCE_DIR}/examples/md_publisher_example.cpp
${CMAKE_CURRENT_SOURCE_DIR}/examples/order_plugin_example.cpp
${CMAKE_CURRENT_SOURCE_DIR}/examples/excel_plugin_example.cpp
${CMAKE_CURRENT_SOURCE_DIR}/examples/ExcelAlgoTemplate.cpp
server_layout)
add_custom_target(sdk_dir ALL DEPENDS ${CMAKE_BINARY_DIR}/sdk)
@@ -13,7 +13,10 @@
using namespace bts::api::orderman;
using namespace bts::orderman;
#define __AlgoName__ "_";
// This file serves as a template for the excel algogen process the following defines are replaced by the algogen
// I thought it useful to put this file in the build to make sure the template compiles in it's own right
//#define __AlgoName__ __
#define __FunctionDefs__
#define __FunctionImpls__
#define __FunctionCalls__
@@ -42,9 +45,9 @@ struct ExcelBookAccessor
ExcelBookAccessor(Book& book) : book(book) { }
const double& operator()(int row, int col) const
{
return this->operator(row, col);
return this->operator()(row, col);
}
double& operator()(int row, int col)
double operator()(int row, int col)
{
if(col == 0)
{
@@ -79,6 +82,8 @@ struct ExcelBookAccessor
return os::nan();
}
};
template<typename T> struct Range;
template<typename T>
struct range_iterator : public std::iterator<std::forward_iterator_tag, T>
@@ -107,7 +112,7 @@ public:
bool operator!=(const range_iterator& rhs) const {return p.row != rhs.row || p.col != rhs.col;}
T& operator*() {return p(row, col);}
const T& operator*() const {return p(row, col);}
}
};
template<typename T>
struct Range
@@ -147,11 +152,11 @@ struct Range
return 0;
}
range_iterator begin()
range_iterator<T> begin()
{
return range_iterator(*this, 0, 0);
}
range_iterator end()
range_iterator<T> end()
{
return range_iterator(*this, nrows, ncols);
}
@@ -181,15 +186,24 @@ class __AlgoName__ : public IAlgoOrder
void do_functions();
SecurityKey sparkalgo_resolve_security_id(const std::string& contract = "", const std::string& symbol = "",
const std::string& security_type = "", const std::string& exchange = "");
template<typename T>
Range <T> sparkalgo_take_snapshot<T>(const Range<T>&, const std::string& name);
Range<T> sparkalgo_take_snapshot(const Range<T>&, const std::string& name);
__DualDefs__;
};
SecurityKey __AlgoName__::sparkalgo_resolve_security_id(const std::string& contract, const std::string& symbol,
const std::string& security_type, const std::string& exchange)
{
auto sk = SecurityKey(algo_services().security().id());
return sk;
}
template<typename T>
Range<T> __AlgoName__::sparkalgo_take_snapshot<T>(const Range<T>& rng, const std::string& name)
Range<T> __AlgoName__::sparkalgo_take_snapshot(const Range<T>& rng, const std::string& name)
{
static std::map<std::string, Range<T> > cache;
auto it = cache.find(name);
@@ -281,7 +295,7 @@ void __AlgoName__::do_launch(IAlgoServices& services)
// Subscribe to market data
if(__NeedsBook__)
services.subscribe_book( spark_resolve_security_id() );
services.subscribe_book( sparkalgo_resolve_security_id() );
}
// Called in the latency sensitive path, once, when the algo is first
@@ -304,7 +318,7 @@ void __AlgoName__::do_launch_attached(IAlgoServices& services, OrderKey attached
// Subscribe to market data
if(__NeedsBook__)
services.subscribe_book( spark_resolve_security_id() );
services.subscribe_book( sparkalgo_resolve_security_id() );
// Simulate a child change so we can update our own state to
// reflect that of the child order we attached to. From this point
@@ -411,7 +425,7 @@ void __AlgoName__::on_child_change(OrderKey, const ChildState& st)
// This is called by the spark daemon at startup. In this call we
// describe our algo's parameters and register a factory function to
// create an instance of the algo.
extern "C" void init_spark_plugin(bts::SparkServices& serv)
extern "C" void __Remove__init_spark_plugin(bts::SparkServices& serv)
{
using namespace bts;
+14
View File
@@ -24,3 +24,17 @@ g++ -isystem ../externals/include \
-Wl,-rpath,.. \
-L ../lib \
-l spark
g++ -isystem ../externals/include \
-I ../include \
-I ../include/spark \
-std=c++1z \
-fPIC \
-g \
-shared \
-o excel_plugin_example.so \
ExcelAlgoTemplate.cpp \
excel_plugin_example.cpp \
-Wl,-rpath,.. \
-L ../lib \
-l spark
@@ -0,0 +1,6 @@
#include "spark/lib/plugin/SparkServices.h"
extern "C" void init_spark_plugin(bts::SparkServices& serv)
{
//this file will be overriten by the excel algogen process, this function is here to dummy up
}