Trading API for C  7.0.0.309536
ctl.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright CAPLIN Systems Ltd 2000-2015
4  *
5  *
6  * $Author: andys $
7  * $DateTime: 2016/12/29 13:36:44 $
8  * $Change: 308038 $
9  * $Id: //CDev/V-7_0/trading/include/ctl.h#2 $
10  *
11  *
12  */
13 
14 #ifndef CTL_H
15 #define CTL_H
16 
26 #ifndef CTL_EXPORT
27 #ifdef WIN32
28 #define CTL_EXPORT __declspec(dllimport)
29 #else
30 #define CTL_EXPORT extern
31 #endif
32 #endif
33 
34 #ifdef HAVE_STREAMLINK
35 #define HAVE_CLIENT_API
36 #endif
37 
38 
39 #ifdef HAVE_DSDK
40 #define HAVE_SERVER_API
41 #define HAVE_CLIENT_API
42 #endif
43 
44 #ifdef HAVE_TRANSFORMER
45 #define HAVE_CLIENT_API
46 #define HAVE_SERVER_API
47 #endif
48 
49 
50 #include <stdarg.h>
51 #include <sys/types.h>
52 
53 
57 typedef struct ctl_trade_s ctl_trade;
61 typedef struct ctl_tradeevent_s ctl_tradeevent;
65 typedef struct ctl_channel_s ctl_channel;
67 typedef struct ctl_provider_s ctl_provider;
68 
69 
70 
71 
72 
73 #define FIELD_REQUESTID "RequestID"
74 #define FIELD_PROTOCOL "TradingProtocol"
75 #define FIELD_MSGTYPE "MsgType"
76 
82 typedef enum {
90 } ctl_error;
91 
95 typedef struct {
104  void (*on_event)(void *context, ctl_provider *provider, ctl_channel *channel, ctl_trade *trade, ctl_tradeevent *ev);
105 
114  void (*on_invalid_event)(void *context, ctl_provider *provider, ctl_channel *channel, ctl_trade *trade, ctl_tradeevent *ev, ctl_error reason);
116 
120 typedef struct {
130  void (*trade_created)(void *context, ctl_provider *provider, ctl_channel *channel, ctl_trade *trade);
138  void (*trade_closed)(void *context, ctl_provider *provider, ctl_channel *channel, ctl_trade *trade);
139 
140 
147  void (*channel_closed)(void *context, ctl_provider *provider, ctl_channel *channel);
148 
150 
151 
152 
153 #ifdef HAVE_STREAMLINK
154 #ifdef WIN32
155 #include <time.h>
156 #endif
157 #include "sl4c.h"
158 CTL_EXPORT ctl_provider *ctl_create_sl_provider(streamlink *sl, int num_models, const char * const *models);
159 #endif
160 
161 #ifdef HAVE_CLIENT_API
162 CTL_EXPORT ctl_channel *ctl_provider_create_channel(ctl_provider *provider, const char *subject, ctl_channel_listener *listener, void *context);
163 CTL_EXPORT ctl_trade *ctl_channel_create_trade(ctl_provider *provider, ctl_channel *channel, const char *model);
164 CTL_EXPORT ctl_trade *ctl_channel_create_trade_with_requestid(ctl_provider *provider, ctl_channel *channel, const char *model, const char *requestid);
165 #endif
166 
167 
168 #ifdef HAVE_SERVER_API
169 /* DataSource API */
176 typedef struct {
185  void (*channel_created)(void *context, ctl_provider *provider, ctl_channel *channel);
186 
193  void (*channel_closed)(void *context, ctl_provider *provider, ctl_channel *channel);
195 
207 typedef void (*ctl_audit_log_cb)(void *ctx, ctl_provider *provider, const char *id, ctl_trade *trade, ctl_tradeevent *ev);
208 #endif
209 
210 #ifdef HAVE_TRANSFORMER
211 CTL_EXPORT ctl_provider *ctl_create_tf_server_provider(ctl_app_listener *listener, void *context, int num_models, const char * const *models, const char *namespacePattern);
212 CTL_EXPORT ctl_provider *ctl_create_tf_client_provider(int num_models, const char * const *models);
213 CTL_EXPORT void ctl_provider_set_use_generic_messages(ctl_provider *provider, int use_generic_messages);
214 
215 #else
216 
217 #ifdef HAVE_DSDK
218 #include "datasrc.h"
219 CTL_EXPORT ctl_provider *ctl_create_ds_provider(ctl_app_listener *listener, void *context, int num_models, const char * const *models, const char *namespacePattern);
220 CTL_EXPORT ctl_provider *ctl_create_ds_client_provider(int num_models, const char * const *models);
221 CTL_EXPORT void ctl_provider_set_audit_dslog(ctl_provider *provider, ds_log_t *log);
222 CTL_EXPORT void ctl_provider_set_audit_logger(ctl_provider *provider, ctl_audit_log_cb callback, void *ctx);
223 CTL_EXPORT void ctl_provider_set_application_listener(ctl_provider *provider, ctl_app_listener *listener, void *context);
224 CTL_EXPORT void ctl_provider_set_use_generic_messages(ctl_provider *provider, int use_generic_messages);
225 #endif
226 
227 #endif
228 
229 
230 CTL_EXPORT void ctl_provider_set_name(ctl_provider *provider, const char *name);
231 CTL_EXPORT void ctl_provider_dealloc(ctl_provider *provider);
232 CTL_EXPORT void ctl_channel_set_listener(ctl_provider *provider, ctl_channel *channel, ctl_channel_listener *listener, void *context);
233 CTL_EXPORT const char *ctl_channel_get_username(ctl_provider *provider, ctl_channel *channel);
234 CTL_EXPORT const char *ctl_channel_get_subject(ctl_provider *provider, ctl_channel *channel);
235 CTL_EXPORT void *ctl_channel_get_user_pointer(ctl_provider *provider, ctl_channel *channel);
236 CTL_EXPORT void ctl_channel_set_user_pointer(ctl_provider *provider, ctl_channel *channel, void *ptr);
237 CTL_EXPORT void ctl_channel_close(ctl_provider *provider, ctl_channel *channel);
238 
239 
240 CTL_EXPORT void ctl_trade_set_listener(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade, ctl_trade_listener *listener, void *context);
241 CTL_EXPORT ctl_error ctl_trade_process_event(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade, ctl_tradeevent *tradeevent); /* Deallocates tradeevent */
242 CTL_EXPORT const char *ctl_trade_get_field(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade, const char *fieldname);
243 CTL_EXPORT const char *ctl_trade_get_protocol(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade);
244 CTL_EXPORT const char *ctl_trade_get_requestid(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade);
245 CTL_EXPORT const char *ctl_trade_get_state(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade);
246 CTL_EXPORT void *ctl_trade_get_user_pointer(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade);
247 CTL_EXPORT void ctl_trade_set_user_pointer(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade, void *ptr);
248 
249 
250 CTL_EXPORT ctl_tradeevent *ctl_trade_create_tradeevent(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade, const char *type);
251 CTL_EXPORT void ctl_tradeevent_add_field(ctl_tradeevent *ev, const char *name, const char *value);
252 CTL_EXPORT const char *ctl_tradeevent_get_type(ctl_tradeevent *ev);
253 CTL_EXPORT const char *ctl_tradeevent_get_field(ctl_tradeevent *ev, const char *name);
254 CTL_EXPORT char const **ctl_tradeevent_get_fields(ctl_tradeevent *ev, int *num_ptr); // User to free returned ptr
255 CTL_EXPORT void ctl_tradeevent_dealloc(ctl_tradeevent *ev);
256 CTL_EXPORT ctl_tradeevent *ctl_tradeevent_clone(ctl_tradeevent *ev);
257 
263 typedef enum {
273 } ctl_loglevel;
274 
286 typedef void (*ctl_log_cb)(void *ctx, ctl_loglevel level, const char *fmt, va_list ap);
287 
288 CTL_EXPORT void ctl_set_log_callback(ctl_provider *provider, ctl_log_cb callback, void *ctx);
289 CTL_EXPORT void ctl_free(void *ptr);
290 CTL_EXPORT void ctl_log(ctl_provider *provider, ctl_loglevel level, const char *fmt, ...);
291 CTL_EXPORT void ctl_set_allocator(void *(*realloc_func)(void *ctx, void *orig, size_t size), void (*free_func)(void *ctx, void *), void *ctx);
292 CTL_EXPORT void *ctl_malloc(size_t size);
293 CTL_EXPORT void *ctl_realloc(void *orig, size_t size);
294 CTL_EXPORT void ctl_free(void *);
295 CTL_EXPORT char *ctl_strdup(const char *orig);
296 CTL_EXPORT void *ctl_calloc(size_t nmemb, size_t size);
297 CTL_EXPORT const char *ctl_loglevel_tostring(ctl_loglevel level);
298 CTL_EXPORT const char *ctl_error_tostring(ctl_error error);
299 CTL_EXPORT char *ctl_tradeevent_tostring(ctl_tradeevent *trade, char *buf, size_t buflen);
300 CTL_EXPORT char *ctl_trade_tostring(ctl_trade *trade, char *buf, size_t buflen);
301 CTL_EXPORT char *ctl_channel_tostring(ctl_channel *channel, char *buf, size_t buflen);
302 
303 
304 #endif
CTL_EXPORT void * ctl_realloc(void *orig, size_t size)
Reallocate the supplied memory.
Definition: misc.c:119
struct ctl_channel_s ctl_channel
Opaque handle representing a trade channel.
Definition: ctl.h:65
CTL_EXPORT void * ctl_calloc(size_t nmemb, size_t size)
Allocate and zero an array of elements.
Definition: misc.c:87
CTL_EXPORT const char * ctl_trade_get_protocol(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade)
Get the name of the trade model that is in use for the specified trade.
Definition: api.c:202
CTL_EXPORT void ctl_provider_set_audit_dslog(ctl_provider *provider, ds_log_t *log)
Set the logfile that audit logs will be written to.
Definition: ds_provider.c:255
Definition: ctl.h:83
CTL_EXPORT const char * ctl_tradeevent_get_type(ctl_tradeevent *ev)
Get the type of the trade event.
Definition: tradeevent.c:108
Definition: ctl.h:86
CTL_EXPORT void ctl_set_allocator(void *(*realloc_func)(void *ctx, void *orig, size_t size), void(*free_func)(void *ctx, void *), void *ctx)
Set the allocator that will be used by the library.
Definition: misc.c:52
CTL_EXPORT void ctl_tradeevent_dealloc(ctl_tradeevent *ev)
Free up the trade event.
Definition: tradeevent.c:51
CTL_EXPORT ctl_trade * ctl_channel_create_trade_with_requestid(ctl_provider *provider, ctl_channel *channel, const char *model, const char *requestid)
Create a trade on the specified trade channel.
Definition: api.c:609
CTL_EXPORT ctl_trade * ctl_channel_create_trade(ctl_provider *provider, ctl_channel *channel, const char *model)
Create a trade on the specified trade channel.
Definition: api.c:584
CTL_EXPORT void ctl_trade_set_user_pointer(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade, void *ptr)
Set a user pointer on the ctl_trade object.
Definition: api.c:372
Definition: ctl.h:85
Definition: ctl.h:269
ctl_error
Error codes used by the library.
Definition: ctl.h:82
CTL_EXPORT void ctl_tradeevent_add_field(ctl_tradeevent *ev, const char *name, const char *value)
Add a field to a trade event.
Definition: tradeevent.c:77
CTL_EXPORT char * ctl_channel_tostring(ctl_channel *channel, char *buf, size_t buflen)
Create a string representation of a ctl_channel object.
Definition: tradechannel.c:264
CTL_EXPORT void ctl_trade_set_listener(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade, ctl_trade_listener *listener, void *context)
Set the listener for the specified trade.
Definition: api.c:78
CTL_EXPORT void * ctl_channel_get_user_pointer(ctl_provider *provider, ctl_channel *channel)
Gets the user pointer on the ctl_trade object.
Definition: api.c:460
CTL_EXPORT const char * ctl_trade_get_state(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade)
Get the current state of the specified trade.
Definition: api.c:313
Listener interface that should be registered if you wish to receive notification of trade creation an...
Definition: ctl.h:120
CTL_EXPORT ctl_tradeevent * ctl_trade_create_tradeevent(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade, const char *type)
Create a new trade event.
Definition: api.c:244
CTL_EXPORT void ctl_channel_set_listener(ctl_provider *provider, ctl_channel *channel, ctl_channel_listener *listener, void *context)
Set the listener on the trade channel.
Definition: api.c:40
CTL_EXPORT void ctl_provider_set_use_generic_messages(ctl_provider *provider, int use_generic_messages)
Set whether the Trading provider will use generic messages.
Definition: ds_provider.c:293
Definition: ctl.h:266
void(* ctl_audit_log_cb)(void *ctx, ctl_provider *provider, const char *id, ctl_trade *trade, ctl_tradeevent *ev)
Definition of the function that you should implement to receive audit logging.
Definition: ctl.h:207
Listener interface that should be registered if you wish to receive events for a trade.
Definition: ctl.h:95
CTL_EXPORT void ctl_provider_set_application_listener(ctl_provider *provider, ctl_app_listener *listener, void *context)
Set the application listener for the supplied provider.
Definition: ds_provider.c:238
CTL_EXPORT void ctl_free(void *ptr)
Free the supplied memory block.
Definition: misc.c:138
CTL_EXPORT ctl_error ctl_trade_process_event(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade, ctl_tradeevent *tradeevent)
Process an event for the specified trade.
Definition: api.c:128
Definition: ctl.h:267
CTL_EXPORT void ctl_channel_close(ctl_provider *provider, ctl_channel *channel)
Forcibly close the trade channel.
Definition: api.c:551
Definition: ctl.h:87
struct ctl_tradeevent_s ctl_tradeevent
Opaque handle representing a trade event.
Definition: ctl.h:61
CTL_EXPORT ctl_provider * ctl_create_ds_client_provider(int num_models, const char *const *models)
Create a DataSource client Trading provider.
Definition: ds_provider.c:660
CTL_EXPORT void * ctl_trade_get_user_pointer(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade)
Gets the user pointer on the ctl_trade object.
Definition: api.c:402
Definition: ctl.h:270
struct ctl_provider_s ctl_provider
Opaque handle representing a trading provider.
Definition: ctl.h:67
CTL_EXPORT char const ** ctl_tradeevent_get_fields(ctl_tradeevent *ev, int *num_ptr)
Gets all fields on the trade event.
Definition: tradeevent.c:146
Definition: ctl.h:264
CTL_EXPORT const char * ctl_loglevel_tostring(ctl_loglevel level)
Return a textual description for the given log level.
Definition: misc.c:264
CTL_EXPORT const char * ctl_trade_get_field(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade, const char *fieldname)
Get a field that is stored on the trade.
Definition: api.c:166
CTL_EXPORT char * ctl_tradeevent_tostring(ctl_tradeevent *trade, char *buf, size_t buflen)
Create a string representation of a ctl_tradeevent object.
Definition: tradeevent.c:174
CTL_EXPORT ctl_provider * ctl_create_ds_provider(ctl_app_listener *listener, void *context, int num_models, const char *const *models, const char *namespacePattern)
Create a DataSource trading provider.
Definition: ds_provider.c:166
Listener interface that should be registered to receive notification of tradechannel creation and clo...
Definition: ctl.h:176
Definition: ctl.h:272
CTL_EXPORT const char * ctl_trade_get_requestid(ctl_provider *provider, ctl_channel *channel, ctl_trade *trade)
Get the client generated identifier that is in use for the specified trade.
Definition: api.c:280
Definition: ctl.h:88
CTL_EXPORT void ctl_channel_set_user_pointer(ctl_provider *provider, ctl_channel *channel, void *ptr)
Set a user pointer on the ctl_channel object.
Definition: api.c:434
CTL_EXPORT const char * ctl_error_tostring(ctl_error error)
Return a textual description for the given error code.
Definition: misc.c:299
CTL_EXPORT char * ctl_trade_tostring(ctl_trade *trade, char *buf, size_t buflen)
Create a string representation of a ctl_trade object.
Definition: trade.c:299
CTL_EXPORT const char * ctl_tradeevent_get_field(ctl_tradeevent *ev, const char *name)
Gets the value of a field on the tradeevent.
Definition: tradeevent.c:123
CTL_EXPORT const char * ctl_channel_get_subject(ctl_provider *provider, ctl_channel *channel)
Get the subject of the TradeChannel.
Definition: api.c:523
Definition: ctl.h:84
CTL_EXPORT void ctl_log(ctl_provider *provider, ctl_loglevel level, const char *fmt,...)
Log a message to the logfile for the provider.
Definition: misc.c:192
CTL_EXPORT void ctl_set_log_callback(ctl_provider *provider, ctl_log_cb callback, void *ctx)
Set the log callback function.
Definition: misc.c:174
CTL_EXPORT ctl_provider * ctl_create_sl_provider(streamlink *sl, int num_models, const char *const *models)
Create a StreamLink trading provider.
Definition: sl_provider.c:123
void(* ctl_log_cb)(void *ctx, ctl_loglevel level, const char *fmt, va_list ap)
Callback type for logging.
Definition: ctl.h:286
struct ctl_trade_s ctl_trade
Opaque handle representing a trade.
Definition: ctl.h:57
Definition: ctl.h:271
Definition: ctl.h:265
CTL_EXPORT void ctl_provider_dealloc(ctl_provider *provider)
Deallocate the trading provider.
Definition: api.c:342
CTL_EXPORT const char * ctl_channel_get_username(ctl_provider *provider, ctl_channel *channel)
Get the name of the user that opened the specified channel.
Definition: api.c:492
CTL_EXPORT char * ctl_strdup(const char *orig)
Duplicate the supplied string.
Definition: misc.c:69
Definition: ctl.h:268
ctl_loglevel
Enumeration that represents the available logging levels.
Definition: ctl.h:263
CTL_EXPORT void * ctl_malloc(size_t size)
Allocate a chunk of memory.
Definition: misc.c:106
CTL_EXPORT ctl_channel * ctl_provider_create_channel(ctl_provider *provider, const char *subject, ctl_channel_listener *listener, void *context)
Create a trade channel using the supplied provider.
Definition: ds_provider.c:740
CTL_EXPORT void ctl_provider_set_audit_logger(ctl_provider *provider, ctl_audit_log_cb callback, void *ctx)
Set the callback function for the audit logger.
Definition: ds_provider.c:270

Generated on Thu Jun 15 2017 10:22:29 for Trading API for C