Skip to content

Commit

Permalink
fixes shrt, geeks
Browse files Browse the repository at this point in the history
  • Loading branch information
AdoNunes committed Apr 13, 2024
1 parent ac7df27 commit a2448a1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 14 deletions.
27 changes: 19 additions & 8 deletions DiscordAlertsTrader/alerts_trader.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,21 @@ def short_orders(self, order, pars):
self.queue_prints.put([str_msg, "", "red"])
return "no", order, False

if self.cfg['shorting']['STO_trailingstop'] != "":
# first check price ask
order["price_actual"] = self.price_now(order['Symbol'], 'BTO', 1 )
pdiff = round((order['price']-order["price_actual"])/order['price']*100,1)

# use current price as ask, bid or last, or alerted
sto_price = cfg['shorting']['STO_price']
check_price = True
if sto_price == 'alert':
check_price = False
ptype = "BTO" if sto_price == "ask" else "last" if sto_price == "last" else "STO"
if check_price:
order["price_actual"] = self.price_now(order['Symbol'], ptype, 1 )
else:
order["price_actual"] = order['price']
pdiff = round((order['price']-order["price_actual"])/order['price']*100,1)

if self.cfg['shorting']['STO_trailingstop'] != "":
# if pdiff too large, trigger trailing only when price target
if pdiff >= eval(self.cfg['shorting']['max_price_diff']):
if pdiff > eval(self.cfg['shorting']['max_price_diff']):
order['price_trigger'] = order["price_actual"]
str_msg = f"STO alert price diff too high: {pdiff}% at {order['price_actual']}, trailing will trigger at {order['price']}"
print(Back.GREEN + str_msg)
Expand All @@ -271,9 +279,11 @@ def short_orders(self, order, pars):

else:
# if price diff not too high, use current price
pdiff = round((order['price']-order["price_actual"])/order['price']*100,1)
if pdiff < eval(self.cfg['shorting']['max_price_diff']):
order['price'] = self.price_now(order['Symbol'], 'BTO', 1 )
if check_price:
order['price'] = self.price_now(order['Symbol'], ptype, 1 )
else:
order['price'] = order['price_actual']
else:
str_msg = f"STO alert price diff too high: {pdiff}% at {order['price_actual']}, keeping original price of {order['price']}"
print(Back.GREEN + str_msg)
Expand Down Expand Up @@ -309,6 +319,7 @@ def short_orders(self, order, pars):
return "yes", order, False
# decide if do BTC based on alert
elif order['action'] == "BTC":

return "yes", order, False
else:
return "no", order, False
Expand Down
3 changes: 2 additions & 1 deletion DiscordAlertsTrader/calc_strat.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ def calc_returns(fname_port= cfg['portfolio_names']['tracker_portfolio_name'],
for ipt in pt:
roi_actual, = calc_roi(bid.loc[trigger_index:], PT=ipt, TS=ts, SL=sl, do_plot=False,
initial_prices=price_curr,sl_update=sl_update, avgdown=avg_down_,
pt_update=pt_update, last=last, ask=ask, action=port.loc[idx, 'Type'])
pt_update=pt_update, last=last.loc[trigger_index:], ask=ask.loc[trigger_index:],
action=port.loc[idx, 'Type'])
rois.append(roi_actual)

rois_r = np.array(rois)
Expand Down
2 changes: 2 additions & 0 deletions DiscordAlertsTrader/config_example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ accountId =
DO_STO_TRADES = false
# if shorting, let alerts close the price (better let SL and PT), can be true or false
DO_BTC_TRADES = false
# DEFINE PRICE, either ask, bit, last or alert
STO_price = ask
# if True, repeated alerts will buy again. Set to False if you want to buy only once [safer option]
accept_repeated_sto_alerts = False
# if current price, accept trade if price difference smaller than percent
Expand Down
2 changes: 1 addition & 1 deletion DiscordAlertsTrader/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def fit_table_elms(Widget_element):
]
layout += gl.trigger_alerts_layout()
print(3)
window = sg.Window('Discord Alerts Trader', layout,size=(100, 800), # force_toplevel=True,
window = sg.Window(f'Discord Alerts Trader - with broker {bksession.name}', layout,size=(100, 800), # force_toplevel=True,
auto_size_text=True, resizable=True)
print(4)
def mprint_queue(queue_item_list, subscribed_author=False):
Expand Down
5 changes: 3 additions & 2 deletions DiscordAlertsTrader/marketdata/load_chn_hist(1).py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
get_date_after_from_port = True
re_download = False
delete_port = False
author = "EM"
author = "moneymotiveA+"


def get_timestamp(row):
Expand Down Expand Up @@ -83,6 +83,7 @@ def save_or_append_quote(quotes, symbol, path_quotes, overwrite=False):
"gianni": 1209992523083415603,
"og-alerts": 1207717868716826645,
"EM": 1126325195301462117,
"vader-swings":1223379548675117088,
}
chan_id = chan_ids[author]
if not use_theta_rest_api:
Expand Down Expand Up @@ -254,7 +255,7 @@ def save_or_append_quote(quotes, symbol, path_quotes, overwrite=False):
if resp == "STCwithout BTO":
print("STC without BTO", order["Symbol"], order["Date"])

tracker.portfolio['spread'] = 100*(tracker.portfolio['bid']-tracker.portfolio['Price-actual'])/tracker.portfolio['Price-actual']
tracker.portfolio['spread'] = 100*(tracker.portfolio['price_actual_bid']-tracker.portfolio['Price-actual'])/tracker.portfolio['Price-actual']
# tracker.portfolio = tracker.portfolio[tracker.portfolio['spread'].abs()<15]
# tracker.portfolio['ask'] = tracker.portfolio['Price-actual']
# tracker.portfolio['Price-actual'] = tracker.portfolio['bid']
Expand Down
9 changes: 8 additions & 1 deletion DiscordAlertsTrader/marketdata/thetadata_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def get_hist_trades(self, symbol: str, date_range: List[date], interval_size: in
def get_geeks(self, symbol: str, date_range: List[date], interval_size: int=1000):
"""send request and get historical trades for an option symbol"""

# symbol = "ACB_040524C6.5"
# date_range = [date(2024, 4, 5), date(2024, 4, 5)]
symb_info = parse_symbol(symbol)
expdate = date(symb_info['exp_year'], symb_info['exp_month'], symb_info['exp_day']).strftime("%Y%m%d")
root = symb_info['symbol']
Expand All @@ -114,7 +116,12 @@ def get_geeks(self, symbol: str, date_range: List[date], interval_size: int=1000
df_q = pd.read_csv(io.StringIO(response.content.decode('utf-8')))
df_q['timestamp'] = df_q.apply(get_timestamp_, axis=1)

return df_q
trades = self.get_hist_trades( symbol, date_range, interval_size)
merged_df = pd.merge(trades[['timestamp', 'last', 'volume']], df_q, on='timestamp', how='right')
df = merged_df[['timestamp', 'bid', 'ask', 'last', 'volume', 'delta', 'theta',
'vega', 'lambda', 'implied_vol', 'underlying_price']]
# df.to_csv(symbol+".csv")
return df

def get_hist_quotes(self, symbol: str, date_range: List[date], interval_size: int=1000):
"""send request and get historical quotes for an option symbol"""
Expand Down
2 changes: 1 addition & 1 deletion DiscordAlertsTrader/server_alert_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def server_formatting(message):
message = xtrades_formatting(message)
elif message.guild.id == 836435995854897193:
message = tradeproelite_formatting(message)
elif message.channel.id in [1144658745822035978, 1196385162490032128, 1176558956123013230, 1213995695237763145]:
elif message.channel.id in [1144658745822035978, 1196385162490032128, 1176558956123013230, 1213995695237763145, 1224336566907044032]:
message = eclipse_alerts(message)
elif message.channel.id in [1005221780941709312, 1176559103431168001]:
message = oculus_alerts(message)
Expand Down

0 comments on commit a2448a1

Please sign in to comment.