From 548591c6e6545095d39912372cbf12e19c6826f5 Mon Sep 17 00:00:00 2001 From: Joe Tretter Date: Mon, 21 Apr 2025 09:31:31 -0500 Subject: [PATCH] Flexibility changes in generic Long call trader --- autoTradeGenericLongCall.sh | 42 ++++++++++++++++++++++++------------- crontabExport.txt | 9 ++++---- getMarketHours.sh | 1 + 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/autoTradeGenericLongCall.sh b/autoTradeGenericLongCall.sh index 5deae74..19303af 100755 --- a/autoTradeGenericLongCall.sh +++ b/autoTradeGenericLongCall.sh @@ -4,15 +4,21 @@ IFS=$'\0' . helpers.sh + +msg=$(echo "Called with parameters: _$@_") +log "$msg" info + Symbol="$1" if [[ -z ${Symbol} ]]; then throw "A Stock symbol must be given as first parameter. exiting." err 2 fi +shift -AccountName="$2" +AccountName="$1" if [[ -z ${AccountName} ]]; then throw "An Account name must be given as first parameter. exiting." err 2 fi +shift if [[ -z $(./getAccountNumbers.sh "${AccountName}") ]]; then throw "An the account with name _${AccountName}_ doesn't exist. exiting." err 2 @@ -23,16 +29,23 @@ if [[ ${marketOpen} == false ]]; then throw "The market is closed, exiting." info 2 fi +#Trade variables - overwrite with -VAR_= daysOutMin=87 daysOutMax=91 deltaMin=0.35 deltaMax=0.40 +priceOffset=0.0 +checkPositionExists=true -marketOpen=$([[ $(./getMarketHours.sh | jq '.option[].isOpen' | grep true | wc -l) -ne 0 ]] && echo true || echo false) -if [[ ${marketOpen} == false ]]; then - throw "The market is closed, exiting." info 2 -fi - +#Allow to overwrite any variable by a commandline parameter with the name of the variable: +while [[ $# -gt 0 ]] +do + if [[ ${1:0:5} == "-VAR_" ]]; then + log "Setting Variable: ${1:5}" info + eval ${1:5} + fi + shift +done inputFile=temp/orderInputFile.$$.json ./getOptionChain.sh ''${Symbol}'' fromDate $(date "+%Y-%m-%d" -d "+${daysOutMin} days") toDate $(date "+%Y-%m-%d" -d "+${daysOutMax} days") > "${inputFile}" @@ -65,15 +78,16 @@ longAsk=$(jq -r '.ask' < temp/longLeg.json) longSymbol=$(jq -r '.symbol' < temp/longLeg.json) log "Long Symbol: _${longSymbol}_ Strike: _${longStrike}_ Bid: _${longBid}_ Ask: _${longAsk}_" info -#Check if this order has already been submitted. -./getOrders.sh | grep '\(WORKING\|FILLED\),'"${longSymbol:0:12}" > temp/existingOrders.$$ -if [[ $(wc -l < temp/existingOrders.$$) -eq 0 ]];then - log "Not Yet traded, continuing" info -else - throw "Already traded, exiting" info -fi +if [[ "${checkPositionExists}" = true ]]; then + #Check if this order has already been submitted. + ./getOrders.sh | grep '\(WORKING\|FILLED\),'"${longSymbol:0:12}" > temp/existingOrders.$$ + if [[ $(wc -l < temp/existingOrders.$$) -eq 0 ]];then + log "Not Yet traded, continuing" info + else + throw "Already traded, exiting" info + fi +fi -priceOffset=0.0 # Get the Middle price... price=$(echo "scale=2; ((${longBid}+${longAsk})/2) + ${priceOffset}" | bc) diff --git a/crontabExport.txt b/crontabExport.txt index 92f7677..fc4494b 100644 --- a/crontabExport.txt +++ b/crontabExport.txt @@ -27,7 +27,7 @@ noconfirm=true # m h dom mon dow command # Export crontab to have it in version control too -30 9 * * 1-5 crontab -l > ~/OptionRecorderSchwab/crontabExport.txt +29 8 * * 1-5 crontab -l > ~/OptionRecorderSchwab/crontabExport.txt # Recording */15 8-15 * * 1-5 cd ~/OptionRecorderSchwab && ./recordAllSymbolsSingleRun.sh @@ -35,12 +35,13 @@ noconfirm=true ##Auto-trading # Weekly put credit spreads -35 10 * * 4 cd ~/OptionRecorderSchwab && ./autoTradeSPXPutCreditSpread.sh +# Paused, too many outstanding contracts 35 10 * * 4 cd ~/OptionRecorderSchwab && ./autoTradeSPXPutCreditSpread.sh # Weekly long SPY position -37 10 * * 4 cd ~/OptionRecorderSchwab && ./autoTradeGenericLongCall.sh SPY Roth -VAR_checkPositionExists=flase -VAR_daysOutMax=120 +#Paused, market downturn might take long... 37 10 * * 4 cd ~/OptionRecorderSchwab && ./autoTradeGenericLongCall.sh SPY Roth -VAR_checkPositionExists=flase -VAR_daysOutMax=120 # 90 day out trades as soon as those options pop up 36 10 * * 1-5 cd ~/OptionRecorderSchwab && ./autoTradeGenericLongCall.sh QQQ IRA -38 10 * * 1-5 cd ~/OptionRecorderSchwab && ./autoTradeGenericLongCall.sh DIA IRA +37 10 * * 1-5 cd ~/OptionRecorderSchwab && ./autoTradeGenericLongCall.sh SPY Roth +38 10 * * 1-5 cd ~/OptionRecorderSchwab && ./autoTradeGenericLongCall.sh DIA IRA -VAR_daysOutMin=85 #1DTE SPX trading every day right after the market closes. #59 14 * * 1-5 cd ~/OptionRecorderSchwab && ./autoTradeSPX_IB_1DTE.sh diff --git a/getMarketHours.sh b/getMarketHours.sh index dccbfc6..9d410ec 100755 --- a/getMarketHours.sh +++ b/getMarketHours.sh @@ -26,6 +26,7 @@ fi cacheFileName=temp/marketHours.`date +%Y%m%d`.${markets//&markets=/_}.tmp if [[ -f ${cacheFileName} ]]; then + log "Answering from cache file _${cacheFileName}_ query string: _${queryString}_" debug jq < ${cacheFileName} exit 0 fi