MasterACE14 Posted May 20, 2007 Share Posted May 20, 2007 How would you go about creating a Simulation Stock Exchange? I basicly just want, a few companies(made up), and they all have a starting rate of $2.00 , and some how code it so it increases or decreases at a maximum of $2 difference, and is updated say every 10 minutes. and would you need a database for this to work? Quote Link to comment https://forums.phpfreaks.com/topic/52201-solved-creating-the-stock-exchange/ Share on other sites More sharing options...
trq Posted May 20, 2007 Share Posted May 20, 2007 Your question is way to vague to answer. Most likely this would be easiest achieved with a database and a cronjob to run the updates, but really we need allot more detail. Quote Link to comment https://forums.phpfreaks.com/topic/52201-solved-creating-the-stock-exchange/#findComment-257445 Share on other sites More sharing options...
MasterACE14 Posted May 20, 2007 Author Share Posted May 20, 2007 ok, you would have for example 3 companies, and probably have them in an array. for this example lets say the 3 company names are, bobs steel. Rocket. and FI(farming Industry)(all made up). ok, so you got them on a single page, displayed like so. Companies - Rates - Date Bob's Steel - $2.00 20/5 Rocket - $2.00 20/5 FI - $2.00 20/5 Have them in a table format like that. Now you have a script, that is run by cron every 10 minutes or so. The script, first choose's 1 of the 4 prime mathematical operators.( - + * / ) and then have 2 randomly generated numbers, within 2 of the initial value of the companies rate. and then place the first random number, followed by the randomly chosen mathematical operator, which is followed by the second chosen number. $math = ("$randnum1 $randop $randnum2"); something like that. it does that, and then displays the new number in the table for each company. so then the table may look like this for example. Companies - Rates - Date Bob's Steel - $2.23 20/5 Rocket - $1.78 20/5 FI - $2.04 20/5 and it keeps running the cron job every 10 minutes or whatever. and what I mean by within $2 difference, I mean whatever the math equation above does, it can't go higher or lower then $2 each way of the current rate for that company. I hope you have a better understanding now. Thanks in advance Regards MasterACE14 Quote Link to comment https://forums.phpfreaks.com/topic/52201-solved-creating-the-stock-exchange/#findComment-257453 Share on other sites More sharing options...
trq Posted May 20, 2007 Share Posted May 20, 2007 What is your question? What exactly are you stuck with? Quote Link to comment https://forums.phpfreaks.com/topic/52201-solved-creating-the-stock-exchange/#findComment-257454 Share on other sites More sharing options...
MasterACE14 Posted May 20, 2007 Author Share Posted May 20, 2007 I need to know how I would start this lol, What would I need to do first? and is their any good tutorials on the net that might help me? Quote Link to comment https://forums.phpfreaks.com/topic/52201-solved-creating-the-stock-exchange/#findComment-257870 Share on other sites More sharing options...
Glyde Posted May 20, 2007 Share Posted May 20, 2007 This is actually quite a simple job. Since you don't want it to shift more than $2, you should first of all only use + or - in your mathematical operations. You will also want a database for this, seeing as it would be easier. But this is pretty much all you need to have in your cronjob file: <?php // Connect to your database $math = array("+", "-"); $result = mysql_query("SELECT * FROM stocks ORDER BY RAND()"); while ($row = mysql_fetch_assoc($result)) { $randOp = $math[array_rand($math)]; $amount = rand(1, 200) / 100; $newAmount = eval("return {$row['amount']} $randOp $amount"); while ($newAmount <= 0) { $randOp = $math[array_rand($math)]; $amount = rand(1, 200) / 100; $newAmount = eval("return {$row['amount']} $randOp $amount"); } mysql_query("UPDATE stocks SET amount='{$newAmount}' WHERE id='{$row['stock_id']}"); } ?> From that you should be able to figure out what your table structure should be like. Please note that's an absolutely rough script and shouldn't be copied and pasted...it should be used as a reference. The way above is very inefficient. Quote Link to comment https://forums.phpfreaks.com/topic/52201-solved-creating-the-stock-exchange/#findComment-257890 Share on other sites More sharing options...
MasterACE14 Posted May 21, 2007 Author Share Posted May 21, 2007 ok, thankyou, that was the sort of example I needed just to get my bearings Thanks. That will help me heaps Regards MasterACE14 Quote Link to comment https://forums.phpfreaks.com/topic/52201-solved-creating-the-stock-exchange/#findComment-258001 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.