TT CORE SDK 2.0.1.1
TT CORE SDK documentation
Loading...
Searching...
No Matches
sdkalgo.h
Go to the documentation of this file.
1/***************************************************************************
2 *
3 * Unpublished Work Copyright (c) 2020
4 * Trading Technologies International, Inc.
5 * All Rights Reserved Worldwide
6 *
7 * * * * S T R I C T L Y P R O P R I E T A R Y * * *
8 *
9 * WARNING: This program (or document) is unpublished, proprietary property
10 * of Trading Technologies International, Inc. and is to be maintained in
11 * strict confidence. Unauthorized reproduction, distribution or disclosure
12 * of this program (or document), or any program (or document) derived from
13 * it is prohibited by State and Federal law, and by local law outside of
14 * the U.S.
15 *
16 ***************************************************************************/
17#pragma once
18
19#include "consts.h"
20#include "instrument.h"
21#include "algo_definition.h"
22#include "execution_report.h"
23#include "sdkalgo_request.h"
24#include "position.h"
25#include "shared_ptr.h"
26#include "enums/MarketId.h"
27#include "enums/OrdStatus.h"
28#include "enums/ExecType.h"
31#include "enums/RiskSide.h"
32
33namespace ttsdk
34{
35 class SDKAlgo;
37
41 {
42 public:
43 virtual ~ISDKAlgoManager() noexcept = default;
44
50 virtual const char* GetMarkets() = 0;
51
60 virtual bool RecoverSDKAlgos() const { return false; }
61
62
64 virtual void OnRecoverAlgo(SDKAlgoPtr algoOrder, SDKAlgoRequestPtr req) = 0;
66 virtual void OnRecoveryEnd() = 0;
68 virtual void OnRecoveryFailed() = 0;
69
71 virtual void OnStartRequest(SDKAlgoPtr algoOrder, SDKAlgoRequestPtr req) = 0;
73 virtual void OnStopRequest(SDKAlgoPtr algoOrder, SDKAlgoRequestPtr req) = 0;
75 virtual void OnUpdateRequest(SDKAlgoPtr algoOrder, SDKAlgoRequestPtr req) = 0;
77 // no fills or user response messages may be generated and set to the users.
78 virtual void OnPauseRequest(SDKAlgoPtr algoOrder, SDKAlgoRequestPtr req) = 0;
80 virtual void OnResumeRequest(SDKAlgoPtr algoOrder, SDKAlgoRequestPtr req) = 0;
81
83 // through the ScheduleEvent() method.
84 virtual void OnScheduledEvent(SDKAlgoPtr algoOrder, unsigned int eventId, void* eventUserData) = 0;
85
86
88 virtual void OnRiskReserved(SDKAlgoPtr algoOrder, const uint64_t instrumentId, const uint64_t accountId,
89 const ttsdk::RiskSide side, const AlgoResponseCode code) {};
91 virtual void OnRiskReleased(SDKAlgoPtr algoOrder, const uint64_t instrumentId, const uint64_t accountId,
92 const ttsdk::RiskSide side, const AlgoResponseCode code) {};
93
94
95
97 // when a stop request is successful, a full fill is sent, the algo fails or the
98 // start request fails. The user should properly shutdown the algo and clean up
99 // the resources it is using when this event is received.
100 virtual void OnAlgoCompleted(SDKAlgoPtr algoOrder) = 0;
101
102 };
104
105
108 // The algo order lifespan begins with new order single request. Once that algo is running,
109 // the sdk algo will exist until either:
110 // 1) a cancel request is issued by the user and the OnStopRequest request return ok
111 // 2) the application fails the algo using the FailAlgo method
112 // 3) the order is fully filled which is indicated by the application calling GenerateSyntheticFill
113 // and the fill qty becomes equal or greater than the algo order qty
114 class SDKAlgo : public shared_base
115 {
116 public:
117 explicit SDKAlgo() {};
119
121 virtual const char* GetOrderId() const noexcept = 0;
123 // an instrument in the tradition manner in the algo requests.
124 virtual InstrumentPtr GetInstrument() const noexcept = 0;
126 virtual AlgoDefinitionPtr GetAlgoDefinition() const noexcept = 0;
128 virtual ExecutionReportPtr GetCurrentState() const noexcept = 0;
129
131 // working qty of the algo, a full fill will be sent and the algo will be complete, triggering
132 // the ISDKAlgoManager::OnAlgoCompleted callback. Fills sent before the algo is started will be sent
133 // after the start is completed.
134 virtual bool GenerateSyntheticFill(const double fillPrc, const double fillQty) noexcept = 0;
136 // if there is a pending action, this data will be collapsed into the pending action reqponse message.
137 // In addition, these messages are throttled so a limited number are sent per second to over constant
138 // sending of restatement messages. Throttle messages will be collapsed the lastest sent.
139 virtual bool GenerateUserResponse(const char* msg, const ttsdk::UserParameter params[], const size_t numParams) noexcept = 0;
140
144 virtual bool FailAlgo(const char* message) noexcept = 0;
146 virtual bool StopAlgo(const char* message) noexcept = 0;
147
150 virtual void OnPendingRequestCompleted(const AlgoResponseCode code, const char* message = nullptr) noexcept = 0;
151
153 // eventId: id to identify the event
154 // eventUserData: user provided data to be passed to the callback
155 virtual void ScheduledEvent(unsigned int eventId, void* eventUserData) = 0;
156
157 // Position Reserve Order support
158
164 virtual bool ReserveRisk(InstrumentPtr instrument, const uint64_t accountId, const RiskSide side,
165 const double quantity, const double maxClipSize) noexcept = 0;
167 virtual bool ReleaseRisk(InstrumentPtr instrument, const uint64_t accountId, const RiskSide side) noexcept = 0;
169 virtual PositionReserveBucket GetRiskBucket(InstrumentPtr instrument, const uint64_t accountId) noexcept = 0;
170
171
172 private:
173 SDKAlgo(const SDKAlgo&) = delete;
174 SDKAlgo& operator=(SDKAlgo&) = delete;
175 SDKAlgo(SDKAlgo&&) = delete;
176 SDKAlgo& operator=(SDKAlgo&&) = delete;
177 };
178
179
180}
Interface for listening to sdk algo events.
Definition sdkalgo.h:41
virtual void OnStopRequest(SDKAlgoPtr algoOrder, SDKAlgoRequestPtr req)=0
Callback to stop an existiong algo instance.
virtual bool RecoverSDKAlgos() const
Returns whether or not the SDK algos created in prior instance of the application should be recovered...
Definition sdkalgo.h:60
virtual void OnAlgoCompleted(SDKAlgoPtr algoOrder)=0
Callback when an algo is finished and should no longer be used. This will be called.
virtual void OnRiskReleased(SDKAlgoPtr algoOrder, const uint64_t instrumentId, const uint64_t accountId, const ttsdk::RiskSide side, const AlgoResponseCode code)
Callback for a release reserve risk request.
Definition sdkalgo.h:91
virtual void OnScheduledEvent(SDKAlgoPtr algoOrder, unsigned int eventId, void *eventUserData)=0
Callback for an event scheduled by the user.An event is scheduled programmatically.
virtual void OnStartRequest(SDKAlgoPtr algoOrder, SDKAlgoRequestPtr req)=0
Callback to start a new algo instance.
virtual void OnRecoverAlgo(SDKAlgoPtr algoOrder, SDKAlgoRequestPtr req)=0
Callback when a working algo is downloaded on startup and need to be recovered.
virtual void OnPauseRequest(SDKAlgoPtr algoOrder, SDKAlgoRequestPtr req)=0
Callback when a request to pause an algo is received. When an algo is in paused state,...
virtual void OnResumeRequest(SDKAlgoPtr algoOrder, SDKAlgoRequestPtr req)=0
Callback when a request to restart a paused algo is received.
virtual void OnRecoveryEnd()=0
Callback when all algos have been downloaded and OnRecoverAlgo called for each of them.
virtual void OnRecoveryFailed()=0
Callback when the previous algos can not be downloaded and recovered.
virtual const char * GetMarkets()=0
Returns the preferred markets for this instance in a comma separated list of market ids....
virtual void OnRiskReserved(SDKAlgoPtr algoOrder, const uint64_t instrumentId, const uint64_t accountId, const ttsdk::RiskSide side, const AlgoResponseCode code)
Callback for a reserve risk request. Orders sent before a PR is acked will be rejected.
Definition sdkalgo.h:88
virtual ~ISDKAlgoManager() noexcept=default
virtual void OnUpdateRequest(SDKAlgoPtr algoOrder, SDKAlgoRequestPtr req)=0
Callback when an update request is made for an existing algo.
an interface to interact with the sdk managed algo.
Definition sdkalgo.h:115
virtual bool GenerateUserResponse(const char *msg, const ttsdk::UserParameter params[], const size_t numParams) noexcept=0
Generates and sends a restatement message to the user contains the given information....
virtual ExecutionReportPtr GetCurrentState() const noexcept=0
Returns the current state of the algo.
virtual bool ReserveRisk(InstrumentPtr instrument, const uint64_t accountId, const RiskSide side, const double quantity, const double maxClipSize) noexcept=0
Reserves a quantity of risk for the given instrumentId/accountId/side to be used to by this algo to a...
virtual AlgoDefinitionPtr GetAlgoDefinition() const noexcept=0
Returns the algo definition Id for the algo definition.
virtual bool ReleaseRisk(InstrumentPtr instrument, const uint64_t accountId, const RiskSide side) noexcept=0
Releases the previously allocated quantity of risk for the given instrumentId/accountId/side.
virtual const char * GetOrderId() const noexcept=0
Returns the unique id of this algo.
virtual bool FailAlgo(const char *message) noexcept=0
Sets this algo as failed and send a message to user indicating failed status. This will not remove th...
virtual bool StopAlgo(const char *message) noexcept=0
Sets this algo as finished and send a message to user indicating finished status.
virtual PositionReserveBucket GetRiskBucket(InstrumentPtr instrument, const uint64_t accountId) noexcept=0
Returns the current position reserve bucket for the instrument and account.
virtual void OnPendingRequestCompleted(const AlgoResponseCode code, const char *message=nullptr) noexcept=0
This needs to be called when a request from the user is completed. If the algo request action was suc...
virtual void ScheduledEvent(unsigned int eventId, void *eventUserData)=0
Schedules an OnScheduleEvent callback to be triggered for this algo with the given id and user data.
virtual bool GenerateSyntheticFill(const double fillPrc, const double fillQty) noexcept=0
Generates and sends a fill message for the given qty and price. If the fill qty exceeds the currently...
virtual InstrumentPtr GetInstrument() const noexcept=0
Returns the instrument referenced by the algo. Might be null if the user did not send.
RiskSide
Definition RiskSide.h:23