Skip to content

Commit

Permalink
Changed displayHeartBeat flag as an option
Browse files Browse the repository at this point in the history
  • Loading branch information
bcui committed Mar 21, 2014
1 parent abd9cb8 commit 3adaea6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Update the following information in connect_to_stream method in streaming.py:

To execute, run the following command:

python streaming.py [DisplayHeartbeat]
python streaming.py [options]

where DisplayHeartbeat is a flag to determine whether heartbeat will be displayed.
options:

To show heartbeat, replace [DisplayHeartbeat] with "showhb"
-b (or --displayHeartBeat): A flag to determine whether HeartBeat will be displayed

### Sample Output

Expand Down
33 changes: 21 additions & 12 deletions streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
To execute, run the following command:
python streaming.py [DisplayHeartbeat]
python streaming.py [options]
where DisplayHeartbeat is a flag to determine whether heartbeat will be displayed.
To show heartbeat, replace [DisplayHeartbeat] with "showhb"
To show heartbeat, replace [options] by -b or --displayHeartBeat
"""

import requests
import json
import sys

from optparse import OptionParser

def connect_to_stream():
"""
For your testing, please use a proper domain (like fxpractice/fxtrade) with your access token and account ID
For your testing, please use a proper domain (like stream-fxpractice/fxtrade) with your access token and account ID
Feel free to include more instruments (10 instruments at most)
"""
Expand Down Expand Up @@ -49,10 +48,20 @@ def demo(displayHeartbeat):
if msg.has_key("instrument"):
print line

if __name__ == "__main__":
argc = len(sys.argv)
def main():
usage = "usage: %prog [options]"
parser = OptionParser(usage)
parser.add_option("-b", "--displayHeartBeat", dest = "verbose", action = "store_true",
help = "Display HeartBeat in streaming data")
displayHeartbeat = False
if argc > 1:
if (sys.argv[1]).lower() == "showhb":
displayHeartbeat = True
demo(displayHeartbeat)

(options, args) = parser.parse_args()
if len(args) > 1:
parser.error("incorrect number of arguments")
if options.verbose:
displayHeartbeat = True
demo(displayHeartbeat)


if __name__ == "__main__":
main()

0 comments on commit 3adaea6

Please sign in to comment.