Slick Trader 0.11.0
Multi-broker algorithmic trading engine with plugin strategies and a live web dashboard
Loading...
Searching...
No Matches
strategy_export.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <slick/logger.hpp>
6
7#ifdef _WIN32
8 #define SLICK_TRADER_EXPORT __declspec(dllexport)
9 #define SLICK_TRADER_IMPORT __declspec(dllimport)
10#else
11 #define SLICK_TRADER_EXPORT __attribute__((visibility("default")))
12 #define SLICK_TRADER_IMPORT
13#endif
14
15// Macro for strategy plugin authors to export their strategy
16// Usage in strategy .cpp:
17// SLICK_TRADER_EXPORT_STRATEGY(MyStrategy)
18//
19// get_strategy_api_version() is the STRATEGY_API_VERSION it was built against: StrategyLoader
20// loads only its own.
21//
22// The set_* entry points exist because a plugin links slick-trader-core statically
23// and therefore owns private copies of the host's singletons. StrategyLoader calls
24// them before create_strategy() to redirect the plugin at the host's instances.
25#define SLICK_TRADER_EXPORT_STRATEGY(StrategyClass) \
26 extern "C" { \
27 SLICK_TRADER_EXPORT uint32_t get_strategy_api_version() { \
28 return slick::trader::STRATEGY_API_VERSION; \
29 } \
30 SLICK_TRADER_EXPORT slick::trader::IStrategy* create_strategy() { \
31 return new StrategyClass(); \
32 } \
33 SLICK_TRADER_EXPORT void destroy_strategy(slick::trader::IStrategy* strategy) { \
34 delete strategy; \
35 } \
36 SLICK_TRADER_EXPORT const char* get_strategy_name() { \
37 static StrategyClass instance; \
38 return instance.name(); \
39 } \
40 SLICK_TRADER_EXPORT const char* get_strategy_version() { \
41 static StrategyClass instance; \
42 return instance.version(); \
43 } \
44 SLICK_TRADER_EXPORT void set_logger_instance(slick::logger::Logger* logger) { \
45 slick::logger::Logger::set_instance(logger); \
46 } \
47 SLICK_TRADER_EXPORT void set_broker_status_registry(slick::trader::BrokerStatusRegistry* registry) { \
48 slick::trader::BrokerStatusRegistry::set_instance(registry); \
49 } \
50 }