Home arrow PHP arrow Page 2 - Building an E-mini Trading System Using PHP and Advanced MySQL Queries

Implementation, steps 1 through 5 - PHP

This article shows illustrative examples of how PHP and some advanced MySQL queries can be used to build an online trading system. For simplicity, we will be featuring one of the most common stock indexes: the S&P 500 index.

TABLE OF CONTENTS:
  1. Building an E-mini Trading System Using PHP and Advanced MySQL Queries
  2. Implementation, steps 1 through 5
  3. Implementation, steps 6 through 13
  4. Implementation, steps 14 and 15
By: Codex-M
Rating: starstarstarstarstar / 4
November 10, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Step 1: Download raw S&P 500 index data from http://finance.yahoo.com/q/hp?s=%5EGSPC and format the Excel table to look like the image below (delete unneeded columns like trading volumes and add the new column “entry”):

Your MySQL table should look like the one above. However, the above screen shot is still in .csv format

Step 2: Convert the .csv to .sql and upload to your MySQL server. You can read an article that explains how to convert your Excel worksheet

Step 3: It's time to write the PHP script. First we connect to the database using the script below:

//connect to mysql database

$username = "your mysql username";

$password = "your mysql password";

$hostname = "your mysql hostname";

$database = "your mysql database";

$dbhandle = mysql_connect($hostname, $username, $password)

or die("Unable to connect to MySQL");

//select a database to work with

$selected = mysql_select_db($database,$dbhandle)

or die("Could not select $database");

Step 4: In order to know how many rows are in the database, which is a value that will be used in our computation, we will query MySQL:

//count the number of rows in the database including the latest entry

$result1 = mysql_query("SELECT * FROM `sp500`")

or die(mysql_error());

// store the record of the "example" table into $row

$row1 = mysql_num_rows($result1)

or die("Invalid query: " . mysql_error());

// Print out the contents of the entry

$numberofentries = $row1;

The $numberofentries contains the maximum number of rows in the MySQL table (in the above screenshot it is 15020). The data in the MySQL table will be arranged from the latest entries all the way down to old entries. Refer to the screenshot above.

The mysql_num_rows will be used to count the number of rows in the table SP500.

Step 5: Compute the last entry to be shown in the HTML table. Since we will be showing only the latest 50 rows, the following will be used:

$lastentry = $numberofentries -50 +1;

This means that, for example, we have 15020 entries in the table; we would like to show them starting from Entry # 15020 to (15020-50+1) or Entry # 14971. This value, as well as the maximum entry above, will change as trading days goes by.



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: