Manual - ProfitDLL en - Us
Manual - ProfitDLL en - Us
1. Product Description
The files contained in the zip archive are organized into separate directories for the 64 bit and 32 bit versions.
Each directory has the same file structure. In the directory named DLL and Executable, you can find the
ProfitDLL.dll file for the 32 bit version and ProfitDLL64.dll for the 64 bit version. Additionally, there is a
compiled example in Delphi that can be used to validate the software's functionalities. In the directory named
Interface, files containing the declarations of the functions and types necessary to communicate with the DLL
in Delphi are provided.
There are also examples for 4 different programming languages in the Example folders
Delphi
C#
C++
Python
They contain the source code to use the main functionalities of the product.
2. Library Description
The library provides basic communication functions with the Routing and Market Data servers for developing
32 bit or 64 bit applications. The DLL responds to server events and sends them, processed in real time, to the
client application, primarily through callbacks that will be described in section 3.2.
The following sections describe, in more detail, how the communication between the library and the client
application is carried out, as well as present the technical details of each function or callback.
3. Library Interface The library exposes several functions that are directly called by the client application,
which make requests to the servers or directly to the internal services and structures of the DLL. The
types specified in this documentation are coded in Delphi, with specific examples for other
programming languages in their respective example files.
All the structures necessary to define the library's functions are defined below:
Definitions:
// Exchanges
gc_bvBCB = 65; // A
gc_bvBovespa = 66; // B
gc_bvCambio = 68; // D
gc_bvEconomic = 69; // E
gc_bvBMF = 70; // F
gc_bvMetrics = 75; // K
gc_bvCME = 77; // M
gc_bvNasdaq = 78; // N
gc_bvOXR = 79; // O
gc_bvPioneer = 80; // P
gc_bvDowJones = 88; // X
gc_bvNyse = 89; // Y
// Status
CONNECTION_STATE_LOGIN = 0; // Connection to login server
CONNECTION_STATE_ROTEAMENTO = 1; // Connection to routing server
CONNECTION_STATE_MARKET_DATA = 2; // Connection to market data server
CONNECTION_STATE_MARKET_LOGIN = 3; // Login to market data server
ROTEAMENTO_DISCONNECTED = 0;
ROTEAMENTO_CONNECTING = 1;
ROTEAMENTO_CONNECTED = 2;
ROTEAMENTO_BROKER_DISCONNECTED = 3;
ROTEAMENTO_BROKER_CONNECTING = 4;
ROTEAMENTO_BROKER_CONNECTED = 5;
MARKET_DISCONNECTED = 0; // Disconnected from market data server
MARKET_CONNECTING = 1; // Connecting to market data server
MARKET_WAITING = 2; // Waiting for connection
MARKET_NOT_LOGGED = 3; // Not logged in to market data server
MARKET_CONNECTED = 4; // Connected to market data
Error Codes:
NL_OK = Integer($00000000); // OK
NL_INTERNAL_ERROR = Integer($80000001); // Internal error
NL_NOT_INITIALIZED = Integer($80000002); // Not initialized
NL_INVALID_ARGS = Integer($80000003); // Invalid arguments
NL_WAITING_SERVER = Integer($80000004); // Waiting for data from the server
The declarations of all exposed functions are found in this section. Some functions take types containing
"callback" in their name, which will be described in the next subsection.
function DLLInitializeLogin(
const pwcActivationKey : PWideChar;
const pwcUser : PWideChar;
const pwcPassword : PWideChar;
StateCallback : TStateCallback;
HistoryCallback : THistoryCallback;
OrderChangeCallback : TOrderChangeCallback;
AccountCallback : TAccountCallback;
NewTradeCallback : TNewTradeCallback;
NewDailyCallback : TNewDailyCallback;
PriceBookCallback : TPriceBookCallback;
OfferBookCallback : TOfferBookCallback;
HistoryTradeCallback : THistoryTradeCallback;
ProgressCallback : TProgressCallback;
TinyBookCallback : TTinyBookCallback) : Integer; stdcall;
function DLLInitializeMarketLogin(
const pwcActivationKey : PWideChar;
const pwcUser : PWideChar;
const pwcPassword : PWideChar;
StateCallback : TStateCallback;
NewTradeCallback : TNewTradeCallback;
NewDailyCallback : TnewDailyCallback
PriceBookCallback : TPriceBookCallback;
OfferBookCallback : TOfferBookCallback;
HistoryTradeCallback : THistoryTradeCallback;
ProgressCallback : TProgressCallback;
TinyBookCallback : TTinyBookCallback) : Integer; stdcall;
function SendBuyOrder(
pwcIDAccount : PWideChar;
pwcIDCorretora : PWideChar;
pwcSenha : PWideChar;
pwcTicker : PWideChar;
pwcBolsa : PWideChar;
dPrice : Double;
nAmount : Integer) : Int64; stdcall;
function SendSellOrder(
pwcIDAccount : PWideChar;
pwcIDCorretora : PWideChar;
pwcSenha : PWideChar;
pwcTicker : PWideChar;
pwcBolsa : PWideChar;
dPrice : Double;
nAmount : Integer) : Int64; stdcall;
function SendMarketBuyOrder(
pwcIDAccount : PWideChar;
pwcIDCorretora : PWideChar;
pwcSenha : PWideChar;
pwcTicker : PWideChar;
pwcBolsa : PWideChar;
nAmount : Integer) : Int64; stdcall;
function SendMarketSellOrder(
pwcIDAccount : PWideChar;
pwcIDCorretora : PWideChar;
pwcSenha : PWideChar;
pwcTicker : PWideChar;
pwcBolsa : PWideChar;
nAmount : Integer) : Int64; stdcall;
function SendStopBuyOrder(
pwcIDAccount : PWideChar;
pwcIDCorretora : PWideChar;
pwcSenha : PWideChar;
pwcTicker : PWideChar;
pwcBolsa : PWideChar;
dPrice : Double;
dStopPrice : Double;
nAmount : Integer) : Int64; stdcall;
function SendStopSellOrder(
pwcIDAccount : PWideChar;
pwcIDCorretora : PWideChar;
pwcSenha : PWideChar;
pwcTicker : PWideChar;
pwcBolsa : PWideChar;
dPrice : Double;
dStopPrice : Double;
nAmount : Integer) : Int64; stdcall;
function SendChangeOrder(
pwcIDAccount : PWideChar;
pwcIDCorretora : PWideChar;
pwcSenha : PWideChar;
pwcstrClOrdID : PWideChar;
dPrice : Double;
nAmount : Integer) : Integer; stdcall;
function SendCancelOrder(
pwcIDAccount : PWideChar;
pwcIDCorretora : PWideChar;
pwcClOrdId : PWideChar;
pwcSenha : PWideChar) : Integer; stdcall;
function SendCancelOrders(
pwcIDAccount : PWideChar;
pwcIDCorretora : PWideChar;
pwcSenha : PWideChar;
pwcTicker : PWideChar;
pwcBolsa : PWideChar) : Integer; stdcall;
function SendCancelAllOrders(
pwcIDAccount : PWideChar;
pwcIDCorretora : PWideChar;
pwcSenha : PWideChar) : Integer; stdcall;
function SendZeroPosition(
pwcIDAccount : PWideChar;
pwcIDCorretora : PWideChar;
pwcTicker : PWideChar;
pwcBolsa : PWideChar;
pwcSenha : PWideChar;
dPrice : Double) : Int64; stdcall;
function SendZeroPositionAtMarket(
pwcIDAccount : PWideChar;
pwcIDCorretora : PWideChar;
pwcTicker : PWideChar;
pwcBolsa : PWideChar;
pwcSenha : PWideChar) : Int64; stdcall;
function GetOrders(
pwcIDAccount : PWideChar;
pwcIDCorretora : PWideChar;
dtStart : PWideChar;
dtEnd : PWideChar) : Integer; stdcall;
function GetPosition(
pwcIDAccount : PWideChar;
pwcIDCorretora : PWideChar;
pwcTicker : PWideChar;
pwcBolsa : PWideChar) : Pointer; stdcall;
function GetHistoryTrades(
const pwcTicker : PWideChar;
const pwcBolsa : PWideChar;
dtDateStart : PWideChar;
dtDateEnd : PWideChar) : Integer; stdcall;
function GetServerClock (var dtDate : Double; var nYear, nMonth, nDay, nHour,
nMin, nSec, nMilisec: Integer) : Integer; stdcall;
DLLInitializeLogin
const
PWideChar Activation key provided for login
pwcActivationKey
DLLInitializeMarketLogin
const
PWideChar Activation key provided for login
pwcActivationKey
Equivalent to the DLLInitializeLogin function, but initializes only Market Data services.
DLLFinalize
SetServerAndPort
This is used to connect to specific Market Data servers and needs to be called before initialization
(DLLInitialize or InitializeMarket).
Important: Only use this function with guidance from the development team; the DLL operates best by
internally selecting the servers.
GetServerClock
Returns the time of the Market Data server; it can only be called after initialization. The parameter dtDate
corresponds to a reference for Double that follows the TDateTime standard of Delphi, as described in
http://docwiki.embarcadero.com/Libraries/Sydney/en/System.TDateTime. The other parameters are also
passed by reference to the caller and represent the calendar date values of the value encoded in the dtDate
parameter.
GetLastDailyClose
The function returns the closing value (dClose) of the candle prior to the current day, according to the
bAdjusted parameter. If bAdjusted is 0, the unadjusted value is returned; otherwise, the adjusted value is
returned.
For the function to return NL_OK with data, SubscribeTicker must have been called previously for the same
asset. On the first call to the function, data is requested from the server, and the function returns
NL_WAITING_SERVER.
All subsequent calls for the same asset return the data already loaded. Invalid assets return
NL_ERR_INVALID_ARGS. If the daily series data or adjustments are not previously loaded, this call will load
them and consequently trigger the progressCallback and adjustHistoryCallback callbacks.
SubscribeTicker
This is used to receive real-time quotes for a specific asset. The information is received after subscription as
soon as it becomes available through the callback specified in the NewTradeCallback parameter of the
initialization function. UnsubscribeTicker disables this service.
UnsubscribeTicker
Requests the Market Data service to stop sending real-time quotes for a specific asset.
SubscribeOfferBook
This is used to receive real-time information from the order book. The information is received after
subscription as soon as it becomes available through the callback specified in the OfferBookCallback
parameter of the initialization function. UnsubscribeOfferBook disables this service.
UnsubscribeOfferBook
Requests the Market Data service to stop sending real-time order book updates for a specific asset.
SubscribePriceBook
It is used to receive real-time price market depth information. The information is received after subscription as
soon as it becomes available through the callback specified in the PriceBookCallback parameter of the
initialization function. UnsubscribePriceBook disables this service.
UnsubscribePriceBook
Requests the Market Data service to stop sending real-time price market depth updates for a specific asset.
SubscribeAdjustHistory
This is used to receive the adjustment history for the specified ticker asset. It is necessary to provide the
callback function SetAdjustHistoryCallback or SetAdjustHistoryCallbackV2 to use this subscribe.
UnsubscribeAdjustHistory
Requests the Market Data service to stop sending adjustment information for a specific asset.
GetAgentNameByID e GetAgentShortNameByID
The returned value provides the full name and abbreviated name of this agent, respectively.
GetHistoryTrades
const
PWideChar Ticker of the asset
pwcTicker
const
PWideChar Exchange of the asset
pwcBolsa
This is used to request historical information for an asset starting from a specific date (pwcTicker = 'PETR4';
dtDateStart = '06/08/2018 09:00:00'; dtDateEnd = '06/08/2018 18:00:00'). The return will be given in the
callback function THistoryTradeCallback specified as a parameter in the initialization function. The
TProgressCallback will return the download progress (from 1 to 100), with a progress value of 1000
indicating that all trades have been sent to the client application.
SetDayTrade
bUseDayTrade Integer Indicates whether to use the day trade flag (1 true, 0 false)
This function is available for clients whose brokers have day trade risk control. Thus, orders are sent with the
DayTrade tag. The parameter is a boolean (0 = False, 1 = True). By setting it to true, all orders will be sent with
day trade mode activated. To deactivate, simply set it to false.
SetEnabledLogToDebug
Function to determine if the DLL should save logs for debugging (1 = save / 0 = do not save).
RequestTickerInfo
This is used to fetch new information about the asset (ex., ISIN). The response is returned in the callbacks
TAssetListInfoCallback, TAssetListInfoCallbackV2, and TAssetListCallback, provided they have
been set in the DLL via the functions SetAssetListInfoCallback, SetAssetListInfoCallbackV2, and
SetAssetListCallback.
The functions below provide a callback address for the DLL to return information. They are optional for using
the library. If they are not specified, the corresponding information will not be provided when requested.
SetChangeCotationCallback
Used to set a callback function of type TChangeCotation, this function notifies whenever the asset undergoes
a price change.
SetAssetListCallback
Used to set a callback function of type TAssetListCallback, which is responsible for returning asset
information.
SetAssetListInfoCallback
Used to set a callback function of type TAssetListInfoCallback, which is responsible for returning asset
information and provides additional details compared to AssetListCallback.
SetAssetListInfoCallbackV2
Similar to SetAssetListInfoCallback, but returns information about the sector, subsector, and segment.
SetChangeStateTickerCallback
Used to set the callback TChangeStateTicker, which informs about changes in the ticker state, such as
whether the asset is in auction, suspended, in pre-closing, after market, or closed.
SetAdjustHistoryCallback
Used to set the callback TAdjustHistoryCallback, which informs about the adjustment history of the ticker.
SetAdjustHistoryCallbackV2
Used to set the callback TAdjustHistoryCallbackV2, which provides information about the adjustment
history of the ticker.
SetTheoreticalPriceCallback
Used to set the callback function of type TTheoreticalPriceCallback, which receives theoretical prices and
quantities during the auction.
SetHistoryCallbackV2
Used to set the callback function of type THistoryCallbackV2, which is similar to THistoryCallback and
receives order history.
SetOrderChangeCallbackV2
Used to set the callback function of type TOrderChangeCallbackV2, which is similar to
TOrderChangeCallback and receives updates about orders.
SetOfferBookCallbackV2
Used to set the callback function of type TOfferBookCallbackV2, which is similar to TOfferBookCallback
and receives the order book in a new format.
SetPriceBookCallbackV2
Used to set the callback function of type TPriceBookCallbackV2, which is similar to TPriceBookCallback
and receives the price market depth in a new format.
SetStateCallback
Used to define the callback function of type TStateCallback. This overrides the callback defined by
DLLInitializeLogin or DLLInitializeMarketLogin.
SetTradeCallback
Used to define the callback function of type TTradeCallback. This overrides the callback defined by
DLLInitializeLogin or DLLInitializeMarketLogin.
SetHistoryTradeCallback
Used to define the callback function of type THistoryTradeCallback. This overrides the callback defined by
DLLInitializeLogin or DLLInitializeMarketLogin.
SetDailyCallback
Used to define the callback function of type TDailyCallback. This overrides the callback defined by
DLLInitializeLogin or DLLInitializeMarketLogin.
SetSerieProgressCallback
Used to define the callback function of type TProgressCallback. This overrides the callback defined by
DLLInitializeLogin or DLLInitializeMarketLogin.
SetOfferBookCallback
Used to define the callback function of type TOfferBookCallback. This overrides the callback defined by
DLLInitializeLogin or DLLInitializeMarketLogin.
SetPriceBookCallback
Used to define the callback function of type TPriceBookCallback. This overrides the callback defined by
DLLInitializeLogin or DLLInitializeMarketLogin.
SetAccountCallback
Used to define the callback function of type TAccountCallback. This overrides the callback defined by
DLLInitializeLogin.
SetHistoryCallback
Used to define the callback function of type THistoryCallback. This overrides the callback defined by
DLLInitializeLogin.
SetOrderChangeCallback
Used to define the callback function of type TOrderChangeCallback. This overrides the callback defined by
DLLInitializeLogin.
The functions described below are only available for initialization with routing after using the
DLLInitializeLogin function during initialization.
GetAccount
Function that returns information about linked accounts through the TAccountCallback passed as a
parameter to the initialization function.
SendBuyOrder
Sends a limit buy order. Returns the internal ID (per session) of the order that can be compared with the
return of THistoryCallback.
SendSellOrder
Sends a limit sell order. Returns the internal ID (per session) of the order that can be compared with the return
of THistoryCallback.
SendMarketBuyOrder
Sends a market buy order. Returns the internal ID (per session) of the order that can be compared with the
return of THistoryCallback.
SendMarketSellOrder
Name Type Description
Sends a market sell order. Returns the internal ID (per session) of the order that can be compared with the
return of THistoryCallback.
SendStopBuyOrder
Sends a stop buy order. Returns the internal ID (per session) of the order that can be compared with the
return of THistoryCallback.
SendStopSellOrder
Sends a stop sell order. Returns the internal ID (per session) of the order that can be compared with the return
of THistoryCallback.
SendChangeOrder
Sends a modification order. When modifying a stop order, the stop price must be provided as the target price,
and the limit price will be calculated based on the same offset.
SendCancelOrder
Sends a cancellation order. The result of the cancellation request can be monitored in
TOrderChangeCallback.
SendCancelOrders
Name Type Description
Sends an order to cancel all orders for an asset. The result of the cancellation request can be monitored in
TOrderChangeCallback for each canceled order.
SendCancelAllOrders
Sends an order to cancel all open orders for all assets. The result of the cancellation request can be monitored
in TOrderChangeCallback for each canceled order.
SendZeroPosition
Sends an order to close the position of a specific asset. Returns the internal ID (per session) of the closing
order, which can be compared with the return of THistoryCallback.
SendZeroPositionAtMarket
Sends an order to close the position of a specific asset at market value. Returns the internal ID (per session) of
the closing order, which can be compared with the return of THistoryCallback.
GetOrders
Function that returns orders within a specified period. The return is made through the callback
THistoryCallback, passed as a parameter to the initialization function.
GetOrder
Function that returns order data based on a ClOrdID. The return is made through the callback
TOrderChangeCallback, passed as a parameter to the initialization function.
GetOrderProfitID
Function that returns order data based on a ProfitID (internal ID per session). The return is made through the
callback TOrderChangeCallback, passed as a parameter to the initialization function. The ProfitID is valid
only during the application's execution, unlike the ClOrdID. This ID is the return from the order sending
functions.
GetPosition
Function that returns the position for a given ticker. It returns a data structure specified below, with a total
size of (91 + N + S + K) bytes:
SetEnabledHistOrder
This function is used to enable/disable the history and automatic order updates when starting the application
(1 = Enable / 0 = Disable). When the history is disabled, the application will not automatically receive order
data at startup, and calls such as GetPosition, which require the position to be built using operations, will not
return valid results. To disable automatic updates, this function should be called immediately after the
initialization functions. It is important to note that by disabling the history, position control will not be
calculated correctly by the platform, and the functionalities for zeroing positions and order status may be
compromised. The user should be aware of these risks before disabling the history..
3.2 Callbacks
This section describes how each callback function in the library should be declared and its purpose.
Callbacks are invoked from the ConnectorThread, meaning they run on a different thread than the main
thread of the client program.
All callback functions must be declared using the stdcall calling convention
(https://en.wikipedia.org/wiki/X86_calling_conventions). This applies to both 32-bit and 64-bit versions.
TNewTradeCallback = procedure(
rAssetID : TAssetIDRec;
pwcDate : PWideChar;
nTradeNumber : Cardinal;
dPrice : Double;
dVol : Double;
nQtd : Integer;
nBuyAgent : Integer;
nSellAgent : Integer;
nTradeType : Integer;
bEdit : Char) stdcall;
TNewDailyCallback = procedure(
rAssetID : TAssetIDRec;
pwcDate : PWideChar;
dOpen : Double;
dHigh : Double;
dLow : Double;
dClose : Double;
dVol : Double;
dAjuste : Double;
dMaxLimit : Double;
dMinLimit : Double;
dVolBuyer : Double;
dVolSeller : Double;
nQtd : Integer;
nNegocios : Integer;
nContratosOpen : Integer;
nQtdBuyer : Integer;
nQtdSeller : Integer;
nNegBuyer : Integer;
nNegSeller : Integer) stdcall;
TPriceBookCallback = procedure(
rAssetID : TAssetIDRec;
nAction : Integer;
nPosition : Integer;
nSide : Integer;
nQtds : Integer;
nCount : Integer;
dPrice : Double;
pArraySell : Pointer;
pArrayBuy : Pointer) stdcall;
TPriceBookCallbackV2 = procedure(
rAssetID : TAssetIDRec;
nAction : Integer;
nPosition : Integer;
nSide : Integer;
nQtds : Int64;
nCount : Integer;
dPrice : Double;
pArraySell : Pointer;
pArrayBuy : Pointer) stdcall;
TOfferBookCallback = procedure(
rAssetID : TAssetIDRec ;
nAction : Integer;
nPosition : Integer;
Side : Integer;
nQtd : Integer;
nAgent : Integer;
nOfferID : Int64;
dPrice : Double;
bHasPrice : Char;
bHasQtd : Char;
bHasDate : Char;
bHasOfferID : Char;
bHasAgent : Char;
pwcDate : PWideChar;
pArraySell : Pointer
pArrayBuy : Pointer) stdcall;
TOfferBookCallbackV2 = procedure(
rAssetID : TAssetIDRec ;
nAction : Integer;
nPosition : Integer;
Side : Integer;
nQtd : Int64;
nAgent : Integer;
nOfferID : Int64;
dPrice : Double;
bHasPrice : Char;
bHasQtd : Char;
bHasDate : Char;
bHasOfferID : Char;
bHasAgent : Char;
pwcDate : PWideChar;
pArraySell : Pointer
pArrayBuy : Pointer) stdcall;
TAccountCallback = procedure(
nCorretora : Integer;
CorretoraNomeCompleto : PWideChar;
AccountID : PWideChar
NomeTitular : PWideChar) stdcall; forward;
TOrderChangeCallback = procedure(
rAssetID : TAssetIDRec;
nCorretora : Integer;
nQtd : Integer;
nTradedQtd : Integer;
nLeavesQtd : Integer;
nSide : Integer;
dPrice : Double;
dStopPrice : Double;
dAvgPrice : Double;
nProfitID : Int64;
TipoOrdem : PWideChar;
Conta : PWideChar;
Titular : PWideChar;
ClOrdID : PWideChar;
Status : PWideChar;
Date : PWideChar;
TextMessage : PWideChar) stdcall;
THistoryCallback = procedure(
rAssetID : TAssetIDRec;
nCorretora : Integer;
nQtd : Integer;
nTradedQtd : Integer;
nLeavesQtd : Integer;
nSide : Integer;
dPrice : Double;
dStopPrice : Double;
dAvgPrice : Double;
nProfitID : Int64;
TipoOrdem : PWideChar;
Conta : PWideChar;
Titular : PWideChar;
ClOrdID : PWideChar;
Status : PWideChar;
Date : PWideChar) stdcall;
THistoryTradeCallback = procedure(
rAssetID : TAssetIDRec;
pwcDate : PWideChar;
nTradeNumber : Cardinal;
dPrice : Double;
dVol : Double;
nQtd : Integer;
nBuyAgent : Integer;
nSellAgent : Integer;
nTradeType : Integer) stdcall;
TTinyBookCallback = procedure(
rAssetID : TAssetIDRec;
dPrice : Double;
nQtd : Integer;
nSide : Integer) stdcall;
TAssetListCallback = procedure(
rAssetID : TAssetIDRec;
pwcName : PWideChar) stdcall;
TAssetListInfoCallback = procedure(
rAssetID : TAssetIDRec;
pwcName : PWideChar;
pwcDescription : PWideChar;
nMinOrderQtd : Integer;
nMaxOrderQtd : Integer;
nLote : Integer;
stSecurityType : Integer;
ssSecuritySubType : Integer;
dMinPriceIncrement : Double;
dContractMultiplier : Double;
strValidDate : PWideChar;
strISIN : PWideChar) stdcall;
TAssetListInfoCallbackV2 = procedure(
rAssetID : TAssetIDRec;
pwcName : PWideChar;
pwcDescription : PWideChar;
nMinOrderQtd : Integer;
nMaxOrderQtd : Integer;
nLote : Integer;
stSecurityType : Integer;
ssSecuritySubType : Integer;
dMinPriceIncrement : Double;
dContractMultiplier : Double;
strValidDate : PWideChar;
strISIN : PWideChar;
strSetor : PWideChar;
strSubSetor : PWideChar;
strSegmento : PWideChar) stdcall;
TChangeStateTicker = procedure(
rAssetID : TAssetIDRec;
pwcDate : PWideChar;
nState : Integer) stdcall;
TAdjustHistoryCallback = procedure(
rAssetID : TAssetIDRec;
dValue : Double;
strAdjustType : PWideChar;
strObserv : PWideChar;
dtAjuste : PWideChar;
dtDeliber : PWideChar;
dtPagamento : PWideChar;
nAffectPrice : Integer) stdcall;
TAdjustHistoryCallbackV2 = procedure(
rAssetID : TAssetIDRec;
dValue : Double;
strAdjustType : PwideChar;
strObserv : PwideChar;
dtAjuste : PwideChar;
dtDeliber : PwideChar;
dtPagamento : PwideChar;
nFlags : Cardinal;
dMult : Double) stdcall;
TTheoreticalPriceCallback = procedure(
rAssetID : TAssetIDRec;
dTheoreticalPrice : Double;
nTheoreticalQtd : Int64) stdcall;
TChangeCotation = procedure(
rAssetID : TAssetIDRec;
pwcDate : PWideChar;
nTradeNumber : Cardinal;
dPrice : Double) stdcall;
THistoryCallbackV2 = procedure(
rAssetID : TAssetIDRec;
nCorretora : Integer;
nQtd : Integer;
nTradedQtd : Integer;
nLeavesQtd : Integer;
nSide : Integer;
nValidity : Integer;
dPrice : Double;
dStopPrice : Double;
dAvgPrice : Double;
nProfitID : Int64;
TipoOrdem : PWideChar;
Conta : PWideChar;
Titular : PWideChar;
ClOrdID : PWideChar;
Status : PWideChar;
LastUpdate : PWideChar;
CloseDate : PWideChar;
ValidityDate : PWideChar) stdcall;
TOrderChangeCallbackV2 = procedure(
rAssetID : TAssetIDRec;
nCorretora : Integer;
nQtd : Integer;
nTradedQtd : Integer;
nLeavesQtd : Integer;
nSide : Integer;
nValidity : Integer;
dPrice : Double;
dStopPrice : Double;
dAvgPrice : Double;
nProfitID : Int64;
TipoOrdem : PWideChar;
Conta : PWideChar;
Titular : PWideChar;
ClOrdID : PWideChar;
Status : PWideChar;
LastUpdate : PWideChar;
CloseDate : PWideChar;
ValidityDate : PWideChar;
TextMessage : PWideChar) stdcall;
TStateCallback
Corresponds to the callback to inform the login state, connection status, routing status, and product
activation. According to the type of nConnStateType provided, which are:
ROTEAMENTO_DISCONNECTED = 0;
ROTEAMENTO_CONNECTING = 1;
ROTEAMENTO_CONNECTED = 2;
ROTEAMENTO_BROKER_DISCONNECTED = 3;
ROTEAMENTO_BROKER_CONNECTING = 4;
ROTEAMENTO_BROKER_CONNECTED = 5;
Given that the type nConnStateType received is one of the values of CONNECTION_STATE, and nResult is the
login state of the specific service. The correct values for a valid connection are:
nConnStateType = CONNECTION_STATE_LOGIN
nResult = LOGIN_CONNECTED
nConnStateType = CONNECTION_STATE_ROTEAMENTO
nResult = ROTEAMENTO_CONNECTED
nConnStateType = CONNECTION_STATE_MARKET_DATA
nResult = MARKET_CONNECTED
nConnStateType = CONNECTION_STATE_MARKET_LOGIN
nResult = CONNECTION_ACTIVATE_VALID
TNewTradeCallback
Corresponds to the callback to inform a new trade, received after subscribing to this asset (according to the
previously specified SubscribeTicker function). The nTradeNumber is the unique identifier of the trade per
trading session. bEdit indicates whether the received trade is an edit (information from the exchange) or an
addition. The ID to identify an edited trade is pwcDate. tradeType indicates the type of trade according to
the table below:"
1. Cross trade
2. Agressive Buy
3. Agressive Sell
4. Auction
5. Surveillance
6. Expit
7. Options Exercise
8. Over the counter
9. Derivative Term
10. Index
11. BTC
12. On Behalf
13. RLP
32. Unknown
TNewDailyCallback
Corresponds to the callback to provide a new quotation with aggregated information from the trading day.
TPriceBookCallback
Corresponds to the callback to provide an update in the price market depth. The parameters are valid or not
according to the value of nAction, described below in detail:
rAssetID: Ticker;
nAction: (atAdd = 0, atEdit = 1, atDelete = 2, atDeleteFrom = 3, atFullBook = 4);
nPosition: Position in the grid; (Valid in atAdd, atEdit, atDelete and atDeleteFrom).
Side: Buy or sell; (Always valid).
nQtds: Quantity sold/bought; (Valid in atAdd and atEdit).
nCount: Number of offers sold/bought; (Valid in atAdd and atEdit).
dPrice: Price; (Valid in atAdd).
This callback was designed to maintain separate lists of buy and sell offers. Therefore, each nAction received
must be handled to modify these lists, depending on the side received in nSide, as described below. All
adjustments depending on nPosition refer to the position from the end of the list (in lists starting at 0, size -
nPosition - 1).
These details are received through the pArrayBuy and pArraySell parameters. For creating the list, when
receiving atFullBook, both pArrayBuy and pArraySell arrays have the following layout in memory:
Header
For more details on how to correctly assemble the market depth, refer to the examples in C++ and Delphi.
TPriceBookCallbackV2
Corresponds to the callback to provide an update in the price market depth. The parameters are valid or not
according to the value of nAction, described below in detail:
rAssetID: Ticker;
nAction: (atAdd = 0, atEdit = 1, atDelete = 2, atDeleteFrom = 3, atFullBook = 4);
nPosition: Position in the grid; (Valid in atAdd, atEdit, atDelete, and atDeleteFrom).
Side: Buy or sell; (Always valid).
nQtds: Quantity sold/bought; (Valid in atAdd and atEdit).
nCount: Number of offers sold/bought; (Valid in atAdd and atEdit).
dPrice: Price; (Valid in atAdd).
This callback was designed to maintain separate lists of buy and sell offers. Therefore, each nAction received
must be handled to modify these lists, depending on the side received in nSide, as described below. All
adjustments depending on nPosition refer to the position from the end of the list (in lists starting at 0, size -
nPosition - 1).
These details are received through the pArrayBuy and pArraySell parameters. For creating the list, when
receiving atFullBook, both pArrayBuy and pArraySell arrays have the following layout in memory:
Header
For more details on how to correctly assemble the market depth, refer to the examples in C++ and Delphi.
TOfferBookCallback
The callback is handled following the same specification as TPriceBookCallback, except for the layout of the
pArrayBuy and pArraySell arrays:
Header
TOfferBookCallbackV2
The callback is handled following the same specification as TPriceBookCallbackV2, except for the layout of
the pArrayBuy and pArraySell arrays:
Header
THistoryTradeCallback
Corresponds to the callback for trades that were requested via the GetHistoryTrades function.
TProgressCallback
TTinyBookCallback
Corresponds to the top of the market depth callback. rAssetID indicates which asset the offer belongs to
according to the TAssetIDRec structure already specified. dPrice: Price; nQtd: Sell/Buy quantity; nSide: Order
side (Buy=0, Sell=1).
The callbacks described below are only available after initialization using the DLLInitializeLogin function,
therefore only for initialization with routing.
TAccountCallback
Corresponds to the callback to provide information on existing accounts. It is possible to verify if the account
is a simulation through the broker's name or identifier.
TOrderChangeCallback
THistoryCallback
TAssetListCallback
Corresponds to the asset information request callback. It is necessary to use the SetAssetListCallback
function for this callback to receive data.
TAssetListInfoCallback
Corresponds to the asset information callback. The stSecurityType field represents the asset type returned,
which can be one of the following:
* Asset Type
0. stFuture
1. stSpot
2. stSpotOption
3. stFutureOption
4. stDerivativeTerm
5. stStock
6. stOption
7. stForward
8. stETF
9. stIndex
10. stOptionExercise
11. stUnknown
12. stEconomicIndicator
13. stMultilegInstrument
14. stCommonStock
15. stPreferredStock
16. stSecurityLoan
17. stOptionOnIndex
18. stRights
19. stCorporateFixedIncome
255. stNelogicaSyntheticAsset
The ssSecuritySubType field is a specification within the type and can be one of the following:
** Asset Subtype
0. ssFXSpot
1. ssGold
2. ssIndex
3. ssInterestRate
4. ssFXRate
5. ssForeignDebt
6. ssAgricultural
7. ssEnergy
8. ssEconomicIndicator
9. ssStrategy
10. ssFutureOption
11. ssVolatility
12. ssSwap
13. ssMiniContract
14. ssFinancialRollOver
15. ssAgriculturalRollOver
16. ssCarbonCredit
17. ssUnknown
18. ssFractionary
19. ssStock
20. ssCurrency
21. ssOTC // OTC Over-the-Counter Market
22. ssFII // FII Real Estate Investment Fund
63. ssFixedIncomeETF
64. ssNontradableFixedIncomeETF
65. ssOutrightPurchase
66. ssSpecificCollateralRepo
67. ssDebenture
68. ssRealStateReceivableCertificate
69. ssAgribusinessReceivableCertificate
70. ssPromissoryNote
71. ssLetraFinanceira
72. ssAmericanDepositaryReceipt
73. ssUnitInvestmentFund
74. ssReceivableInvestmentFund
75. ssOutrightTPlus1
76. ssRepoTPlus1
77. ssNonTradableGrossSettlement
78. ssNonTradableNetSettlement
79. ssETFPrimaryMarket
80. ssSharesPrimaryMarket
81. ssRightsPrimaryMarket
82. ssUnitPrimaryMarket
83. ssFundPrimaryMarket
84. ssForeignIndexETFPrimaryMarket
85. ssWarrantPrimaryMarket
86. ssReceiptPrimaryMarket
87. ssGermanPublicDebts
88. ssStockRollover
93. ssStrategySpotDollar
94. ssTargetRate
95. ssTradableETFRealState
96. ssNonTradableETFRealEstate
254. ssDefault
TAssetListInfoCallbackV2
Extension of the TAssetListInfoCallback callback, only adding the fields sector, subsector, and segment.
TTheoreticalPriceCallback
Corresponds to the callback for returning the theoretical price and quantities during an asset auction.
TAdjustHistoryCallback
Corresponds to the asset adjustment callback. To use this callback, it must be sent to the DLL through the
SetAdjustHistoryCallback function. It is preferable to use the SetAdjustHistoryCallbackV2 function,
which provides a more detailed description of how to calculate the adjustment.
* Adjustment Type
'None'
'Unknown'
'JurosRF'
'Dividendo'
'Rendimento'
'Subscricao'
'Desdobramento'
'ResgateTotalRF'
'ResgateTotalRV'
'AmortizacaoRF'
'JurosCapProprio'
'SubsComRenuncia'
'Bonificacao'
'Grupamento'
'JuncaoSerie'
'Cisao'
'Unknown'
TAdjustHistoryCallbackV2
Corresponds to the asset adjustment callback. To use this callback, it must be sent to the DLL through the
SetAdjustHistoryCallbackV2 function. nFlags is a bit field from b0 to b31, where bit 0 (least significant)
indicates whether the adjustment affects the price, and bit 1 indicates if it is a sum adjustment. dMult is the
pre-computed value that should be multiplied by the price to apply the adjustment. It is only used if the
adjustment is not a sum adjustment and affects the price, as indicated in the nFlags field. A dMult value of
-9999 indicates that it is invalid and should not be used. If dMult is invalid, dValue is used for the calculation,
where subtraction is performed for sum adjustments and division otherwise.
When dMult is a valid value, the adjustment is made by multiplying the price by this value.
When the sum flag is set, the adjustment value is subtracted from the price
When the sum flag is not set, the price is divided by the adjustment value.
Pseudocode:
TChangeCotation
Name Type Description
nTradeNumber Cardinal Sequential number of the trade in which the change occurred
This callback is used to report when a price modification occurs for the asset, providing the last price and time
of the trade. To use this callback, it must be sent to the DLL through the SetChangeCotationCallback
function.
TChangeStateTicker
Corresponds to the callback for identifying an asset's state change. The provided date is when the state
modification occurred, but only some states show the date. The possible states are listed below:
THistoryCallbackV2
Corresponds to the secondary (optional) callback for the order history request. To use this callback, it must be
sent to the DLL through the SetHistoryCallbackV2 function, and it will be called under the same conditions
as THistoryCallback. The history corresponds only to orders from the current day. The nValidity field
represents the order validity type, which can be one of the following values:
TOrderChangeCallbackV2
Corresponds to the secondary (optional) callback for reporting order modifications sent by an account. To use
this callback, it must be sent to the DLL through the SetOrderChangeCallbackV2 function, and it will be
called under the same conditions as TOrderChangeCallback. The nValidity field represents the order
validity type, and the possible values can be checked in the THistoryCallbackV2 documentation.
4. Product Usage
Initializing with Routing
To use the library, it is essential to initialize the services through the initialization functions. More specifically, if
routing services are to be used, the DLLInitializeLogin function must be used, which will establish a
connection to the routing and market data servers.
This function is described in the exposed functions section and requires an activation code provided at the
time of product purchase, as well as a username and password to log into the authentication server. The other
parameters are mandatory callbacks that will be called by the DLL during use and need to be specified at the
time of initialization.
It is important to note that all callbacks occur in a thread called ConnectorThread and, therefore, happen
simultaneously with the client application. The client application should process the data provided through
the callbacks as data to be consumed from another thread. If necessary, the handling of writing this data
should be done with critical sections or mutexes.
The data received via callbacks is stored in a single data queue, so any lengthy processing within the callback
functions may delay the internal message processing queue of the DLL and cause delays in receiving trades or
other information. To avoid this, the data should be processed and passed to other application threads
immediately, or perform the minimum processing possible. Database accesses or disk writes should be
avoided during the processing of a callback.
Finally, it is important to note that callbacks are designed only to receive data. Therefore, request functions to
the DLL or any other function from the DLL interface should not be called within a callback, as this may cause
unexpected exceptions and undefined behavior.
The Market Data initialization process is analogous to the Routing initialization, with the difference being the
initialization function DLLInitializeMarketLogin and a reduction in the callbacks passed as parameters, as they
are related to routing orders or accounts.
Data Types
All types mentioned in this document are types specified in the Delphi language. Below are some links for
conversion or mapping of these types to the languages used in the examples.
https://docwiki.embarcadero.com/RADStudio/Tokyo/en/Delphi_to_C%2B%2B_types_mapping
https://docs.python.org/2/library/ctypes.html
http://www.netcoole.com/delphi2cs/datatype.htm
32-bit Linkage
To use the library in 32-bit mode, the application must also be compiled in 32 bits. Since it operates in 32 bits,
there is a 4GB memory limitation, which will be shared between the library and the client application.
Therefore, it is not recommended to request large amounts of data in a single request, as this could exceed
the process's memory limit.
C#
Using Visual Studio, it is necessary to change the target platform in the Configuration Manager
from Any CPU to x86.
Python
The python.exe interpreter must also be 32-bit. Additionally, there is a bug in 32-bit Python
where a callback containing a type larger than 32 bits fails and causes an exception. Follow the
issue here: https://bugs.python.org/issue41021. Therefore, we recommend that clients who wish
to use 32-bit Python use version 3.6.2, which was tested by the Nelogica team and does not have
this issue.
For other languages, it is only necessary to switch the compilation mode to 32 bits.
64-bit Linkage
To use the library in 64-bit mode, the application must also be compiled in 64 bits. The calling convention
remains stdcall, just like in the 32-bit version. There are no known issues with the example languages in the
64-bit version, so there is no recommended version; the latest versions of each language can be used.
The 64-bit version does not have a memory limitation and can therefore use the maximum available memory
in the system, allowing larger data requests in a single request, limited by the amount of available RAM.