|
1 |
| -r""" |
2 |
| -The stock_alerter module allows you to setup rules and get alerted when |
3 |
| -those rules are met. |
4 |
| -
|
5 |
| ->>> from datetime import datetime |
6 |
| -
|
7 |
| -First, we need to setup an exchange which contains all the stocks that |
8 |
| -are going to be processed. A simple dictionary will do. |
9 |
| -
|
10 |
| ->>> from stock_alerter.stock import Stock |
11 |
| ->>> exchange = {"GOOG": Stock("GOOG"), "AAPL": Stock("AAPL")} |
12 |
| -
|
13 |
| -Next, we configure the reader. The reader is the source from where the |
14 |
| -stock updates are coming. The module provides two readers out of the |
15 |
| -box: A FileReader for reading updates from a comma separated file, |
16 |
| -and a ListReader to get updates from a list. You can create other |
17 |
| -readers, such as an HTTPReader to get updates from a remote server. |
18 |
| -Here we create a simple ListReader by passing in a list of 3-tuples |
19 |
| -containing the stock symbol, timestamp and price. |
20 |
| -
|
21 |
| ->>> from stock_alerter.reader import ListReader |
22 |
| ->>> reader = ListReader([("GOOG", datetime(2014, 2, 8), 5)]) |
23 |
| -
|
24 |
| -Next, we setup an Alert. We give it a rule, and an action to be taken |
25 |
| -when the rule is fired. |
26 |
| -
|
27 |
| ->>> from stock_alerter.alert import Alert |
28 |
| ->>> from stock_alerter.rule import PriceRule |
29 |
| ->>> from stock_alerter.action import PrintAction |
30 |
| ->>> alert = Alert("GOOG > $3", PriceRule("GOOG", lambda s: s.price > 3),\ |
31 |
| -... PrintAction()) |
32 |
| -
|
33 |
| -Connect the alert to the exchange |
34 |
| -
|
35 |
| ->>> alert.connect(exchange) |
36 |
| -
|
37 |
| -Now that everything is setup, we can start processing the updates |
38 |
| -
|
39 |
| ->>> from stock_alerter.processor import Processor |
40 |
| ->>> processor = Processor(reader, exchange) |
41 |
| ->>> processor.process() |
42 |
| -GOOG > $3 |
43 |
| -""" |
44 |
| - |
45 | 1 | if __name__ == "__main__":
|
46 | 2 | import doctest
|
47 |
| - doctest.testmod() |
| 3 | + doctest.testfile("readme.txt") |
0 commit comments