Page 1 of 1

store Open High Low Last every x time interval

Posted: Sun Nov 20, 2011 7:34 pm
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

Re: store Open High Low Last every x time interval

Posted: Mon Nov 21, 2011 1:27 pm
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" :)

Re: store Open High Low Last every x time interval

Posted: Wed Nov 23, 2011 8:54 am
by inosent1
thanks for the input. i have it working now