XML and Scripting Languages
By Parand Tony Darugar2005-05-18
Retrieving the rules
Our buy/sell rules are stored in the following table:
|
symbol is the stock symbol. field describes which field will be used in the criterion (in this case either price or volume). value is the value of field which would trigger an action. action describes the type of action to take (in this case either buy or sell).
Thus the following row from the rules table:
|
means if the price of the IBM stock is greater than 120, issue a buy order. And
|
means if the trading volume of Microsoft stock is over 65000000, issue a sell order.
Retrieving these rules from the database is a simple matter using the Perl DBI/DBD extensions. The connection to the database can be created at the start of processing, and kept open until the end. For each stock, the applicable rules can be retrieved by selecting from the rules tables based on the stock symbol.
The tag stock_quotes is the outermost tag, meaning its start will trigger the first handler callback, and its end the last. This provides the perfect place for establishing and closing the database connection.
|
The rules can be retrieved by selecting based on the stock symbol:
|
Tutorial Pages:
» Converting XML to HTML
» Simple substitution
» Function-based substitution
» Tree-based processing
» Active XML documents
» Storing tag contents
» Retrieving the rules
» Acting on the rules
» Next steps
» Resources
First published by IBM DeveloperWorks
