store Open High Low Last every x time interval

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

store Open High Low Last every x time interval

Post by inosent1 »

Hi

I am using code that captures in real time stock index prices changing, tick by tick, while the session is open.

That data comes in as a variable. i'll call it $price

the code then inputs the new price into a MySQL table called price.

but all i am doing is creating a zillion records each session and they are not organized into 5, 10, 30, 60 minute intervals

what i am trying to figure out is how to store the prices temporarily and then at a certain time interval, then input to the DB

example, the session begins at 10 AM:

$price @ 10:00:00 am = 11000

store: $open = 11000 $high = 11000 low = 11000 last = 11000

$price @ 10:00:30 am = 11010

store: $open = 11000 $high = 11010 low = 11000 last = 11010

$price @ 10:01:00 am = 10990

store: $open = 11000 $high = 11010 low = 10990 last = 10990

etc

so i need to find a way to compare $price to the first $price at the start of the time interval, and then at, for example, in a 60 minute interval, at 10:59:59 AM upload the OHLC for that hour to the DB

to make it easier the start time can be whenever the page is opened
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: store Open High Low Last every x time interval

Post by maxx99 »

inosent1 wrote: ...
but all i am doing is creating a zillion records each session and they are not organized into 5, 10, 30, 60 minute intervals
...
Easy way
- create a simple script adding current value to DB ("table1")
- add a CRON job (run the script e.g. each minute)
- create another script to view statistics - browser use - do the math (OHLC) for selected time period on this side

You can reduce record count in "table1" storing recalculacted data in "table2" and flushing "table1" :)
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

Re: store Open High Low Last every x time interval

Post by inosent1 »

thanks for the input. i have it working now
Post Reply