Flexibility changes in generic Long call trader
This commit is contained in:
@@ -4,15 +4,21 @@ IFS=$'\0'
|
|||||||
|
|
||||||
. helpers.sh
|
. helpers.sh
|
||||||
|
|
||||||
|
|
||||||
|
msg=$(echo "Called with parameters: _$@_")
|
||||||
|
log "$msg" info
|
||||||
|
|
||||||
Symbol="$1"
|
Symbol="$1"
|
||||||
if [[ -z ${Symbol} ]]; then
|
if [[ -z ${Symbol} ]]; then
|
||||||
throw "A Stock symbol must be given as first parameter. exiting." err 2
|
throw "A Stock symbol must be given as first parameter. exiting." err 2
|
||||||
fi
|
fi
|
||||||
|
shift
|
||||||
|
|
||||||
AccountName="$2"
|
AccountName="$1"
|
||||||
if [[ -z ${AccountName} ]]; then
|
if [[ -z ${AccountName} ]]; then
|
||||||
throw "An Account name must be given as first parameter. exiting." err 2
|
throw "An Account name must be given as first parameter. exiting." err 2
|
||||||
fi
|
fi
|
||||||
|
shift
|
||||||
|
|
||||||
if [[ -z $(./getAccountNumbers.sh "${AccountName}") ]]; then
|
if [[ -z $(./getAccountNumbers.sh "${AccountName}") ]]; then
|
||||||
throw "An the account with name _${AccountName}_ doesn't exist. exiting." err 2
|
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
|
throw "The market is closed, exiting." info 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#Trade variables - overwrite with -VAR_<variable name>=<value>
|
||||||
daysOutMin=87
|
daysOutMin=87
|
||||||
daysOutMax=91
|
daysOutMax=91
|
||||||
deltaMin=0.35
|
deltaMin=0.35
|
||||||
deltaMax=0.40
|
deltaMax=0.40
|
||||||
|
priceOffset=0.0
|
||||||
|
checkPositionExists=true
|
||||||
|
|
||||||
marketOpen=$([[ $(./getMarketHours.sh | jq '.option[].isOpen' | grep true | wc -l) -ne 0 ]] && echo true || echo false)
|
#Allow to overwrite any variable by a commandline parameter with the name of the variable:
|
||||||
if [[ ${marketOpen} == false ]]; then
|
while [[ $# -gt 0 ]]
|
||||||
throw "The market is closed, exiting." info 2
|
do
|
||||||
|
if [[ ${1:0:5} == "-VAR_" ]]; then
|
||||||
|
log "Setting Variable: ${1:5}" info
|
||||||
|
eval ${1:5}
|
||||||
fi
|
fi
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
inputFile=temp/orderInputFile.$$.json
|
inputFile=temp/orderInputFile.$$.json
|
||||||
./getOptionChain.sh ''${Symbol}'' fromDate $(date "+%Y-%m-%d" -d "+${daysOutMin} days") toDate $(date "+%Y-%m-%d" -d "+${daysOutMax} days") > "${inputFile}"
|
./getOptionChain.sh ''${Symbol}'' fromDate $(date "+%Y-%m-%d" -d "+${daysOutMin} days") toDate $(date "+%Y-%m-%d" -d "+${daysOutMax} days") > "${inputFile}"
|
||||||
@@ -65,6 +78,7 @@ longAsk=$(jq -r '.ask' < temp/longLeg.json)
|
|||||||
longSymbol=$(jq -r '.symbol' < temp/longLeg.json)
|
longSymbol=$(jq -r '.symbol' < temp/longLeg.json)
|
||||||
log "Long Symbol: _${longSymbol}_ Strike: _${longStrike}_ Bid: _${longBid}_ Ask: _${longAsk}_" info
|
log "Long Symbol: _${longSymbol}_ Strike: _${longStrike}_ Bid: _${longBid}_ Ask: _${longAsk}_" info
|
||||||
|
|
||||||
|
if [[ "${checkPositionExists}" = true ]]; then
|
||||||
#Check if this order has already been submitted.
|
#Check if this order has already been submitted.
|
||||||
./getOrders.sh | grep '\(WORKING\|FILLED\),'"${longSymbol:0:12}" > temp/existingOrders.$$
|
./getOrders.sh | grep '\(WORKING\|FILLED\),'"${longSymbol:0:12}" > temp/existingOrders.$$
|
||||||
if [[ $(wc -l < temp/existingOrders.$$) -eq 0 ]];then
|
if [[ $(wc -l < temp/existingOrders.$$) -eq 0 ]];then
|
||||||
@@ -72,8 +86,8 @@ if [[ $(wc -l < temp/existingOrders.$$) -eq 0 ]];then
|
|||||||
else
|
else
|
||||||
throw "Already traded, exiting" info
|
throw "Already traded, exiting" info
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
priceOffset=0.0
|
|
||||||
# Get the Middle price...
|
# Get the Middle price...
|
||||||
price=$(echo "scale=2; ((${longBid}+${longAsk})/2) + ${priceOffset}" | bc)
|
price=$(echo "scale=2; ((${longBid}+${longAsk})/2) + ${priceOffset}" | bc)
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ noconfirm=true
|
|||||||
# m h dom mon dow command
|
# m h dom mon dow command
|
||||||
|
|
||||||
# Export crontab to have it in version control too
|
# 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
|
# Recording
|
||||||
*/15 8-15 * * 1-5 cd ~/OptionRecorderSchwab && ./recordAllSymbolsSingleRun.sh
|
*/15 8-15 * * 1-5 cd ~/OptionRecorderSchwab && ./recordAllSymbolsSingleRun.sh
|
||||||
@@ -35,12 +35,13 @@ noconfirm=true
|
|||||||
|
|
||||||
##Auto-trading
|
##Auto-trading
|
||||||
# Weekly put credit spreads
|
# 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
|
# 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
|
# 90 day out trades as soon as those options pop up
|
||||||
36 10 * * 1-5 cd ~/OptionRecorderSchwab && ./autoTradeGenericLongCall.sh QQQ IRA
|
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.
|
#1DTE SPX trading every day right after the market closes.
|
||||||
#59 14 * * 1-5 cd ~/OptionRecorderSchwab && ./autoTradeSPX_IB_1DTE.sh
|
#59 14 * * 1-5 cd ~/OptionRecorderSchwab && ./autoTradeSPX_IB_1DTE.sh
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ fi
|
|||||||
cacheFileName=temp/marketHours.`date +%Y%m%d`.${markets//&markets=/_}.tmp
|
cacheFileName=temp/marketHours.`date +%Y%m%d`.${markets//&markets=/_}.tmp
|
||||||
|
|
||||||
if [[ -f ${cacheFileName} ]]; then
|
if [[ -f ${cacheFileName} ]]; then
|
||||||
|
log "Answering from cache file _${cacheFileName}_ query string: _${queryString}_" debug
|
||||||
jq < ${cacheFileName}
|
jq < ${cacheFileName}
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user