ASPEN_ReplaceTicks

 

Related Topics

 

 

Purpose

Replace or append a financial instrument’s existing historical ticks with new historical ticks for particular minute.

 

 

Call Syntax

#include <aspen.h>

AspenRequest(GLOBAL_session, ASPEN_ReplaceTicks, &input, NULL);

 

 

Parameters

Input

An ASPEN_REPLACETICKS_INPUT structure.

 

Output

None.

 

 

Structures

typedef struct

{

   ASPEN_INUM inum;

   int        num_ticks;

   ASPEN_TICK *ticks;

}ASPEN_REPLACETICKS_INPUT;

 

 

Remarks

By definition, a tick is a price (and volume, and bate) in time (to the minute). Therefore, ASPEN_PutTick requires

 

  • A symbol’s inum (ASPEN_INUM), or instrument number

  • The number of ticks you intend to place

  • An array (ASPEN_TICK) containing the ticks you intend to place

 

Call AspenRequest() with either ASPEN_GetInstrumentNumber or ASPEN_GetInstrumentInfo to get a symbol’s inum.

 

ASPEN_ReplaceTicks overwrites all the prices in a minute. To add prices to a minute, first get existing historical data from the Server by calling AspenRequest() with the ASPEN_GetTickHistory service and place the data returned in the *ticks array. Then add the prices you want to append to the *ticks array.

 

To replace data using ASPEN_ReplaceTicks, you must first have prices to substitute for the ticks in a given minute for a financial instrument (a tick is a price (and its volume, and bate) in time (to the minute)). Substitute prices can come from a variety of sources:

 

  • An Aspen Server

  • The internet

  • Ticks from several financial instruments processed to create a synthetic instrument

 

Ticks collected by an Aspen Server are prices as reported by the data feed, which makes the purpose of ASPEN_ReplaceTicks on Server data largely custodial. The principal reason to replace ticks in the Server database is to identify and correct an erroneous price, bate, or volume reported by the data feed (or trading floor). Call AspenRequest() with the ASPEN_GetTickHistory service to retrieve ticks for a specific minute or time span.

 

Great care should be taken when collecting tick data from internet sources. While price data may be correct, please ensure that volume and bate data are also correct. Neglecting to do so can cause correct volume and bate information to be overwritten.

 

When creating a synthetic instrument, remember that in addition to price, bate and volume data are available for consideration.

 

This service should be used with great caution. It will replace all ticks for a given minute with the replacement ticks you have placed in the *ticks array.

 

If there are no existing ticks for a given time, which may mean there was no trading activity in that minute, the ticks in the *ticks array will nevertheless be inserted.

 

Tick replacement may span several minutes; however, the insertion must occur continuously. It helps to sort the *ticks array ascending.

 

No more than 1000 ticks may be defined for any given minute.

 

Large tick replacements may degrade Server performance.

 

 

Return Value

ASPEN_OK

if the ticks were successfully replaced on the Server.

ASPEN_SV_INTERNAL_ERROR

The memory allocated is greater than the allocation required to satisfy the tick replacement.

ASPEN_FN_ALLOC_ERROR

The memory allocation required to satisfy the tick replacement is greater than allocated memory.

 

 

See Also

AspenRequest()

ASPEN_GetTickHistory

ASPEN_INUM

ASPEN_TICK

ASPEN_REPLACETICKS_INPUT

 

 

Example

int CAspenRequestDlg::DoASPEN_ReplaceTicks()

{

   ASPEN_GETINSTRUMENT_INPUT  input;

   ASPEN_INSTRUMENT           contract;

   ASPEN_GETTICKS_INPUT       tick_input;

   ASPEN_GETTICKS_OUTPUT      tick_output;

   ASPEN_REPLACETICKS_INPUT   repTicksIn;

   ASPEN_TICK                 ticks[ASPEN_MAX_TICKS];

   ASPEN_PRICE                aspenPrice;

   int                        retval,i,j,n;

   long                       whole[250];

   long                       remainder[250],this_volume[250];

   int                        this_bate[250];

   char                       symbol_xlat[256];

   char                       priceBuffer[32],newPrice[20];

   server_list                *slp = list;

   CString                    strText;

   CString                    bateStr;

   FILE                       *getTick;

   HWND hDlg = NULL;

   strcpy(symbol_xlat,strSymb);

   retval = AspenRequest(slp->server_session, ASPEN_GetInstrumentNumber, symbol_xlat, &inum);

   if (ASPEN_OK == retval)

   {        

      input.want_updates = ASPEN_NO;

      input.inum = inum;

      retval = AspenRequest(slp->server_session, ASPEN_GetInstrumentInfo, &input, &contract);

   }

   time_of_day = time(NULL);

   localTime = gmtime(&time_of_day);

   localTime->tm_hour = start_hour;

   localTime->tm_min = start_minute;

   localTime->tm_sec = 0;

   ANSITimeToAspenTime(localTime, localTimeZone, &(tick_input.start_time));

   

   time_of_day = time(NULL);

   localTime = gmtime(&time_of_day);

   localTime->tm_hour = start_hour;

   localTime->tm_min = start_minute + 1;

   localTime->tm_sec = 0;

   ANSITimeToAspenTime(localTime, localTimeZone, &(tick_input.end_time));

   

   tick_input.bates = bates;

   tick_input.prices = prices;

   tick_input.volumes = volumes;

   tick_input.times = times;

   tick_input.inum = input.inum;

   tick_input.max_ticks = ASPEN_MAX_TICKS;

   if( (getTick = fopen("ticksOut.txt","a+")) != NULL)

   {

      retval = AspenRequest(slp->server_session, ASPEN_GetTickHistory, &tick_input, &tick_output);

      while (tick_output.num_ticks != 0)

      {

         for (i = 0; i < tick_output.num_ticks; i++)

         {

            retval = AspenDecodePrice(tick_input.prices[i], contract.quantum, ASPEN_YES, priceBuffer, NULL, NULL, NULL);

            fprintf(getTick,"%s,%d,%d\n",priceBuffer, tick_input.volumes[i],tick_input.bates[i]);

         }

         if (tick_output.next_time==0) break;

         tick_input.start_time=tick_output.next_time;

         retval = AspenRequest(slp->server_session, ASPEN_GetTickHistory, &tick_input, &tick_output);

      }

   // **Note: Output to screen filename and path.

   fclose(getTick);

   strText = "TicksOut.txt created in working directory.";

   m_HistoryEdit.AppendString(strText);

   ShellExecute(hDlg, "open", "ticksOut.txt", NULL, NULL, SW_SHOWMINNOACTIVE);

   MessageBox(_T("The prices you have requested are available for edit in the minimized shell on your taskbar.\nEdit the incorrect prices; save the file; click OK to continue."),

           _T("Instructions"),MB_ICONINFORMATION|MB_OK|MB_DEFBUTTON1);

   }

   

   if( (getTick = fopen("ticksOut.txt","r+")) != NULL)

   {

      i = 0;

      while (fscanf(getTick,"%s",strText) != EOF)

      {  

         strcpy(newPrice,strText);

         whole[i]=atol(&newPrice[0]);

         for (j = 0; j < sizeof (newPrice); j++)

         {

            if ((newPrice[j]==32) || (newPrice[j]==46))

            {

               j++;

               remainder[i] = atol(&newPrice[j]);

               break;

            }

         }

         for (j = 0; j < sizeof (newPrice); j++)

         {

            if (newPrice[j]==44)

            {

               j++;

               this_volume[i] = atol(&newPrice[j]);

               break;

            }

         }

         for (n = j; n < sizeof (newPrice); n++)

         {

            if (newPrice[n]==44)

            {

               n++;

               this_bate[i] = atoi(&newPrice[n]);

               break;

            }

         }

      i++;  

      };

      fclose(getTick);

   }

   else

   {

      strText = "Unable to open ticksOut.txt!";

      m_HistoryEdit.AppendString(strText);

   }

   for(i = 0;i < tick_output.num_ticks; i++)

   {

      retval = AspenEncodePrice(whole[i], remainder[i], contract.quantum, &aspenPrice);

      ticks[i].price = aspenPrice;

      ticks[i].volume = this_volume[i];

      ticks[i].time = tick_input.start_time;

      ticks[i].bate = this_bate[i];

   }

   repTicksIn.inum = tick_input.inum;

   //repTicksIn.inum = 1073796405;

   repTicksIn.num_ticks = tick_output.num_ticks - 1;

   //repTicksIn.num_ticks = 77;

   repTicksIn.ticks = ticks;

   retval = AspenRequest(slp->server_session, ASPEN_ReplaceTicks, &repTicksIn, NULL);

   return retval;

}

 

©2006 Aspen Research Group, Ltd. All rights reserved. Terms of Use.