-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAUTO_orders.py
More file actions
68 lines (52 loc) · 1.95 KB
/
AUTO_orders.py
File metadata and controls
68 lines (52 loc) · 1.95 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import numpy as np
from datetime import datetime, timedelta
import pandas as pd
import os
import yfinance as yf
import triton_config
BASKET_SIZE = 5
STOP_LOSS = 4 # percent below spot
TARGET_GAIN = .9 # of expected gain
FILENAME = triton_config.ORDER_FILE_NAME
logname = triton_config.MAIN_LOG
def main(UNDERLYING = 0, sandbox = True):
os.chdir("/home/nuckchead/Documents/playfair/etrade/")
df = pd.read_csv("./dailyDump.csv")
df.sort_values(by='SR', inplace=True, ascending=False)
today = datetime.now()
tomorrow = (today + timedelta(days=1)).strftime('%Y/%m/%d')
#day = today.strftime('%A')
#if day in ['Saturday', 'Sunday']:
# print("Not a trading day")
# return []
tickers = []
share_prices = []
gains = []
for _, row in df[:BASKET_SIZE].iterrows():
if tomorrow == row['Date']:
ticker = row["Ticker"]
tick_df = yf.download(ticker, period="1d")
if not len(tick_df):
continue
tickers.append(ticker)
share_prices.append(list(tick_df['Close'])[0])
gains.append(row["EWA_Gain"])
underlying_split = UNDERLYING / BASKET_SIZE
multiples = [int(underlying_split/sp) for sp in share_prices]
orders = []
with open(FILENAME, "w") as file:
file.write(f"{(today).strftime('%Y/%m/%d')} BUY_AT_CLOSE\n")
for t, m, sp, g in zip(tickers, multiples, share_prices, gains):
file.write(f"{t} {m} {round(sp, 2)} {round(g, 2)}\n")
if m > 0:
orders.append((t, m))
with open(logname, "a+") as file:
file.write(f"Order generation {datetime.now()}")
if sandbox:
file.write(f" SANDBOX\n")
else:
file.write(f" PROD\n")
for t, m, sp, g in zip(tickers, multiples, share_prices, gains):
file.write(f" {t} {m} {round(sp, 2)} {round(g, 2)}\n")
file.write("\n")
return orders