API Documentation

PriceFormat

Converts an integer price and price type into an Ascii string (like sprintf). Has awareness of instrument-specific price formatting, like for bonds. Allows commas and space-padding.

    #define cszNxCorePriceFormat "sNxCorePriceFormat"
    typedef int (__stdcall *NxCorePriceFormat) (char* szBuff, int lPrice, unsigned char PriceType, int expandWidth/*=0*/, bool bCommas/*=false*/);
    int PriceFormat(
        char*                           szBuff,
        int                             lPrice,
        unsigned char                   PriceType,
        int                             expandWidth=0,
        bool                            bCommas=false
        );

Parameters

szBuffer

Address of a character buffer that will be filled with the formatted text. Make sure the length of the buffer is at least 256 bytes.

Price

Integer representing the price to format.

PriceType

The PriceType that Price is using.

expandWidth

Set to a non-zero value to pad the buffer so that it is at leaset expandWidth characters in length.

bInsertCommas

Set to 1 to format the price using commas to separate thousands.

Return Value

Returns length of the formatted string in szBuff.

Example

Here's an example of converting a price/priceType to a double

#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <stdio.h>
#include "NxCoreAPI.h"
#include "NxCoreAPI_class.h"    
  
NxCoreClass nxCoreClass;    
  
int __stdcall nxCoreCallback(const NxCoreSystem* pNxCoreSys, const NxCoreMessage* pNxCoreMessage)
{
    switch (pNxCoreMessage->MessageType)
    {
        case NxMSG_TRADE:
        {
            const NxCoreTrade& nt = pNxCoreMessage->coreData.Trade;    
  
            char withCommas[32];
            char withoutCommas[32];
            char spacePadded[32];    
  
            nxCoreClass.PriceFormat(withCommas,    nt.Price, nt.PriceType, 0,  true);
            nxCoreClass.PriceFormat(withoutCommas, nt.Price, nt.PriceType, 0,  false);
            nxCoreClass.PriceFormat(spacePadded,   nt.Price, nt.PriceType, 10, false);    
  
            printf("Price With Commas    = %s\n",withCommas);
            printf("Price Without Commas = %s\n",withoutCommas);
            printf("Price Space Padded   = %s\n",spacePadded);
            printf("\n"); 
  
            break;
        }
    }    
  
    return NxCALLBACKRETURN_CONTINUE;
}    
  
int main(int argc, char** argv)
{
    if (!nxCoreClass.LoadNxCore("NxCoreAPI.dll") &&
        !nxCoreClass.LoadNxCore("C:\\Program Files\\Nanex\\NxCoreAPI\\NxCoreAPI.dll"))
    {
        fprintf(stderr, "Can't find NxCoreAPI.dll\n");
        return -1;
    }
    nxCoreClass.ProcessTape(argv[1], 0, NxCF_EXCLUDE_CRC_CHECK, 0, nxCoreCallback);
    return 0;
}