-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriggerfuncs.py
More file actions
executable file
·53 lines (44 loc) · 1.16 KB
/
triggerfuncs.py
File metadata and controls
executable file
·53 lines (44 loc) · 1.16 KB
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
# trigger functions
##
import yfinance as yfinance
def test_oncall():
print 'trigger called'
return (10,1) # every time it's triggered we get +10 shares
def get_price(ticker,d):
if d == 'realtime':
return yfinance.get_price(ticker)
print 'updating price'
return yfinance.get_historical(ticker, d)
def buy_stock(ticker,amount,type,cash):
"""
ticker: stock ticker
amount: quantity
type: 'SHARES' or 'DOLLARS'
"""
value = yfinance.get_price(ticker)
value = float(value)
amount = int(amount)
if type == 'DOLLARS':
amount //= value
if (amount*value) < cash[-1]:
print 'you bought: ', value*amount
cash[-1] -= value*amount
return (amount,value)
return (1,1)
def sell_stock(ticker,amount,type,cash):
"""
ticker: stock symbol
amount: quantity
type: 'SHARES' or 'DOLLARS'
this is also used for selling short
"""
value = yfinance.get_price(ticker)
if type == 'DOLLARS':
amount //= value # you can only sell amount many shares
cash[-1] += value*amount
return (-amount,value) # you sold it dingus!
"""
Sell_stock and sell_short are identical
"""
def sell_short(ticker, amount, type, cash):
return sell_stock(ticker, amount, type, cash);