This is the Personal Stock Monitor scripting developers forum.
Subscribe to RSS Feed
Developing Custom Stock Market Software using PSM -> Problems with obtaining HistoryStart/EndDate
Not logged in.
2010-11-26 00:29:31
1 of 14
#2565
Am having problems with obtaining the current values of HistoryStartDate and HistoryEndDate ...

I've tried two different ways but BOTH return "12:00:00 AM", without a DATE ...

dHistoryStartDate = ticker.GetProperty("HistoryStart")
dHistoryEndDate = ticker.GetProperty("HistoryEnd")

dHistoryStartDate = DateValue( ticker.GetProperty("HistoryStart") )
dHistoryEndDate = DateValue( ticker.GetProperty("HistoryEnd") )

How do I obtain the current values of HistoryStartDate and HistoryEndDate?

I'm trying to validate what PSM downloaded via DownloadHistoryData as shown in the code box below.

Thank you,

-Don


ticker.DownloadHistoryData HistoryStartDate, HistoryEndDate
On Error Goto 0  ' De-Activate error handling

' Make sure the download worked ...
  Set HistoryRecs = ticker.HistoryData
  If ( (Not ticker.HistoryData Is Nothing) And (HistoryRecs.Count > 0) ) Then
    dHistoryStartDate = ticker.GetProperty("HistoryStart")
    dHistoryEndDate = ticker.GetProperty("HistoryEnd")
    MsgBox "HistoryRecs.Count: " & HistoryRecs.Count, vbOKOnly, "User Entry Form"
    MsgBox "Got downloaded history data for " & ticker.GetProperty("Symbol") _
      & chr(13) & chr(10) _
      & "HistoryStartDate: " & dHistoryStartDate & chr(13) & chr(10) _
      & "HistoryEndDate: " & dHistoryEndDate, vbOKOnly, "User Entry Form"

Posted by: dgoyette
2010-11-27 15:54:59
2 of 14
#2578
in reply to #2565
I'll have to test this, but I believe the code should return the full date.

BTW, keep in mind that DownloadHistoryData executes asynchronously. You have to wait for the OnHistoryUpdated event to actually retrieve the historical data.
Posted by: Anatoly
2010-11-27 20:38:46
3 of 14
#2591
in reply to #2578
This is the reason for my OnHistoryUpdated question here I don't want PSM internal code executing MY code in OnHistoryUpdated, which it seems to do. A MsgBox in MY code is displayed when I display a chart in PSM, manually.
Posted by: dgoyette
2010-11-27 20:58:10
4 of 14
#2594
in reply to #2578

Anatoly wrote
You have to wait for the OnHistoryUpdated event to actually retrieve the historical data.


Moving the MsgBox into the OnHistoryUpdated event code still displays only "12:00:00 AM".
Posted by: dgoyette
2010-11-27 21:28:14
5 of 14
#2596
in reply to #2578
Anatoly wrote
BTW, keep in mind that DownloadHistoryData executes asynchronously. You have to wait for the OnHistoryUpdated event to actually retrieve the historical data.


How do I "wait" for the OnHistoryUpdated event?

How should a ticker.DownloadHistoryData process be coded? Am I doing it correctly (below)?

...
MsgBox "Downloading history data...", vbOKOnly, "Update 1-Share Transactions"
On Error Resume Next  ' Activate error handling
  ticker.DownloadHistoryData HistoryStartDate, HistoryEndDate
On Error Goto 0  ' De-Activate error handling

' Check the download results ...
  If ( (Not ticker.HistoryData.Count > 0) Or (ticker.HistoryData Is Nothing) ) Then
' History download failed ...
    MsgBox "Unable to download historical data. This ticker will be skipped.", vbOKOnly, "Update 1-Share Transactions"
...
' We have history records to process ...
  Set HistoryRecs = ticker.HistoryData
...
Posted by: dgoyette
2010-11-30 21:06:45
6 of 14
#2606
in reply to #2596
Is this code in a standalone script or an extension? It must be in an extension, because you can not receive events (such as OnHistoryUpdated) in a standalone script, since it just runs and exits.

SO if you're in an extension, you create your own handler class such as

<code>
class MyEventHandler

   public Function OnHistoryUpdated ( Ticker )
      ' do something here
   End Function
   
end Class
</code>

and you register it with the application like this:

<code>
Dim handler
Set handler = new MyEventHandler

Set EventManager = Application.GetObject("EventManager")

If Not EventManager Is Nothing Then
   EventManager.RegisterHandlerMethod handler, "OnHistoryUpdated"
Else
   ' error
End If
</code>

So when you call ticker.DownloadHistoryData later, PSM calls your OnHistoryUpdated function when the data is ready to be read, then you can read it and do whatever. You should never be calling OnHistoryUpdate function from your own code.

In the OnHistoryUpdate function, getting the HistoryStart and HistoryEnd properties won't do anything, because those do not indicate what data is available. You set those properties to tell the software what date range to retrieve. Right now I don't know if reading back those properties will give you the correct dates, since I haven't had a chance to test that. But it should.
Posted by: Anatoly
2010-12-01 18:27:36
7 of 14
#2620
in reply to #2606

Anatoly wrote

Is this code in a standalone script or an extension?

This code is in an extension.

Anatoly wrote

In the OnHistoryUpdate function, getting the HistoryStart and HistoryEnd properties won't do anything, because those do not indicate what data is available. You set those properties to tell the software what date range to retrieve.

Right now I don't know if reading back those properties will give you the correct dates, since I haven't had a chance to test that. But it should.

Yes, I SET these dates before calling the history functions.

NO, GET does not return a full date, as indicated in my first message at the top of this thread. Regardless of where in my code I place the GET operation, including in OnHistoryUpdated.
Posted by: dgoyette
2010-12-02 12:10:36
8 of 14
#2631
in reply to #2620
Ok, I had to read the code since I wrote this so long ago. I guess it's undocumented, but what happens is that the HistoryStart and HistoryEnd properties are wiped out after you call ticker.HistoryData, so that's why you're not getting the date (12:00 AM with no date is "zero date"). However if you read those properties before calling ticker.HistoryData, then you will get the date. Yes, there is a reason for it working this way, and no, the behavior can not be changed. So if you need those values somewhere else in your code after calling ticker.HistoryData, you will need to store them separately.
Posted by: Anatoly
2010-12-02 21:56:25
9 of 14
#2637
in reply to #2631
Thank you Anatoly.

No, I don't actually NEED the dates. I was merely trying to find out exactly what DownloadHistoryData and/or HistoryData had returned -- if they used my Start and End Dates.
Posted by: dgoyette
2010-12-03 00:41:49
10 of 14
#2644
in reply to #2637
It should use the dates you set.

I did find out why you get an increasing number of records returned each time, and that is because it actually adds new records for the same date but at a different time. Haven't figured out why exactly that happens yet, but it's fairly easy to deal with the extraneous data in the extension since you're looking for a specific day.
Posted by: Anatoly
2010-12-03 02:38:21
11 of 14
#2652
in reply to #2644
Anatoly wrote
It should use the dates you set.

Yes, it returns data for the Start and End dates I set.


Anatoly wrote
I did find out why you get an increasing number of records returned each time, and that is because it actually adds new records for the same date but at a different time.

That sounds like a fun one to figure out.

Anatoly wrote
Haven't figured out why exactly that happens yet, but it's fairly easy to deal with the extraneous data in the extension since you're looking for a specific day.

Yes, it's easy enough to code a Do...Until...Loop.

Thanks for your research into this one Anatoly.
Posted by: dgoyette
2010-12-03 03:05:47
12 of 14
#2653
in reply to #2631
Anatoly wrote
I guess it's undocumented, but what happens is that the HistoryStart and HistoryEnd properties are wiped out after you call ticker.HistoryData, so that's why you're not getting the date (12:00 AM with no date is "zero date").


YERMO ... would you please add this bit of information to the on-line docs for ticker?

Thank you!
Posted by: dgoyette
2010-12-03 07:52:43
13 of 14
#2658
in reply to #2653
There is actually a good reason why this must work this way, and that is because you have various plugins and extensions all requesting ticker data for various purposes, and they assume that if they don't set the start and end, they will get all available data. So from the perspective of each of those requests, and since the API had already been published and could not be changed, we had to add the start and end properties separately, but they must be reset to zero after you retrieve the ticker data, so that the next request works as expected.
Posted by: Anatoly
2010-12-03 19:48:02
14 of 14
#2681
in reply to #2658
Makes sense, Anatoly. Just wish it had been in the documentation, thus saving both of us a lot of test, research, and message writing time. But, after going through all of this, I will NEVER forget to reset the dates before calling history functions!

Thank you for all your work
Posted by: dgoyette