-
Notifications
You must be signed in to change notification settings - Fork 24
/
friartuck_example.py
101 lines (82 loc) · 3.52 KB
/
friartuck_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""
MIT License
Copyright (c) 2017 Code Society
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
from friartuck.api import FriarTuckLive, OrderType
import logging
log = logging.getLogger("friar_tuck")
def initialize(context):
log.info("hello, I am in initialize")
context.aapl = friarTuck.lookup_security("AAPL")
context.wtw = friarTuck.lookup_security("WTW")
log.info(context.account)
log.info(context.portfolio)
log.info("pnl(%s)" % context.portfolio.pnl)
for sec in context.portfolio.positions:
log.info("symbol(%s) pos(%s) " % (sec.symbol, context.portfolio.positions[sec]))
def handle_data(context, data):
log.info("hello, I am in handle_data")
current_quote = data.current(context.aapl, field=['close', 'open'])
log.debug(current_quote)
current_quote = data.current(context.wtw, field='close')
log.debug(current_quote)
current_quote = friarTuck.current([context.aapl, context.wtw], field='close')
log.debug(current_quote)
"""Start Shell Setup"""
friarTuck = FriarTuckLive(user_name="[email protected]", password="Abs0lut3ly")
class AlgoShell:
def initialize(self, context):
initialize(context)
def handle_data(self, context, data):
handle_data(context, data)
my_algo = AlgoShell()
friarTuck.active_algo = my_algo
#friarTuck.run_engine(block=True)
"""End Shell Setup"""
sec2 = friarTuck.fetch_and_build_security("GRPN")
log.debug(sec2)
current_data = friarTuck._current(sec2, field=['close','price','high'])
log.debug(current_data['high'])
"""order_id = friarTuck.order(sec2, 1, order_type=OrderType(stop_price=6.40), time_in_force='gtc')
log.info("order_id=%s" % order_id)
#order_id="c853b2b2-a60a-4358-96be-65a8a2d17bf2"
order = friarTuck.get_order(order_id)
log.info("order=%s" % order)
open_orders = friarTuck.get_open_orders(sec2)
log.info("FIT open_orders=%s" % open_orders)
open_orders = friarTuck.get_open_orders()
log.info("ALL open_orders=%s" % open_orders)
friarTuck.cancel_order(order_id)
"""
#friarTuck.__load_market_info()
#friarTuck.__load_profile_info()
#log.info(friarTuck.context.account)
"""
sec = friarTuck.lookup_security("AAPL")
log.debug(sec)
sec2 = friarTuck.lookup_security("WTW")
log.debug(sec2)
history_data = friarTuck.history(sec, bar_count=400, frequency="1h", field=['close','open'])
#log.debug(history_data)
current_quote = friarTuck.current(sec, field=['close','open'])
log.debug(current_quote)
current_quote = friarTuck.current(sec, field='close')
log.debug(current_quote)
current_quote = friarTuck.current([sec,sec2], field='close')
log.debug(current_quote)
"""