diff --git a/autoTradeSPX_IB_1DTE.sh b/autoTradeSPX_IB_1DTE.sh index b2c3022..63a6936 100755 --- a/autoTradeSPX_IB_1DTE.sh +++ b/autoTradeSPX_IB_1DTE.sh @@ -13,7 +13,7 @@ fi inputFile="$1" if [[ "" == "$inputFile" ]]; then inputFile=temp/orderInputFile.$$.json - ./getOptionChain.sh '$SPX' fromDate $(date "+%Y-%m-%d" -d "+1 days") toDate $(date "+%Y-%m-%d" -d "+1 days") > "${inputFile}" + ./getOptionChain.sh '$SPX' fromDate $(date "+%Y-%m-%d" -d "+1 days") toDate $(date "+%Y-%m-%d" -d "+4 days") > "${inputFile}" fi if [[ ! -f "${inputFile}" ]]; then throw "ERROR: Input file _${inputFile}_ does not exist." err 1 @@ -23,9 +23,9 @@ dateKey=$(jq -r '.putExpDateMap | keys | .[]' "${inputFile}" | head -n 1) log "Date-Key: _${dateKey}_" debug underlyingPrice=$(jq ".underlyingPrice" "${inputFile}") +log "Underlying Price: _${underlyingPrice}_" debug atmStrike=$(jq -r '.callExpDateMap[]|keys[]' "${inputFile}" | sort -n | awk -e '{lastStrike=$1; if ($1 > '${underlyingPrice}') {print $1; exit } }') - optionRoot=SPXW #I only want the PM expiry (SPX without the W is AM expiry) jq '.putExpDateMap."'${dateKey}'"[]|map({symbol,delta,strikePrice,bid,ask,optionRoot}) |.[] | select(.optionRoot == "'${optionRoot}'" and .strikePrice=='${atmStrike}') ' "${inputFile}" | tail -n 8 > temp/shortLegP.json diff --git a/getMarketHours.sh b/getMarketHours.sh index 40e7b4c..ff94c29 100755 --- a/getMarketHours.sh +++ b/getMarketHours.sh @@ -23,6 +23,13 @@ if [[ -z "${markets}" ]]; then markets="equity&markets=option&markets=bond&markets=future&markets=forex" fi +cacheFileName=temp/marketHours.`date +%Y%m%d`.${markets//&markets=/_}.tmp + +if [[ -f ${cacheFileName} ]]; then + jq < ${cacheFileName} + exit 0 +fi + queryString="?markets=${markets}" while [[ $# -gt 0 ]]; do @@ -33,12 +40,13 @@ done log "Querying for markets: _${markets}_ query string: _${queryString}_" debug curl -s -X GET "https://api.schwabapi.com/marketdata/v1/markets${queryString}" \ - -H "Authorization: Bearer $( temp/markets.tmp.$$.json + -H "Authorization: Bearer $( ${cacheFileName} -marketsCheck=$(jq -e -r '.. | .isOpen?' temp/markets.tmp.$$.json | grep -v null | wc -l) +marketsCheck=$(jq -e -r '.. | .isOpen?' ${cacheFileName} | grep -v null | wc -l) if [[ ${marketsCheck} -eq 0 ]]; then - errMsg="ERROR: THE RESPONSE IS INCORRECT! markets: _${markets}_ Check: _${marketsCheck}_ check file _temp/markets.tmp.$$.json_" + errMsg="ERROR: THE RESPONSE IS INCORRECT! markets: _${markets}_ Check: _${marketsCheck}_ check file _${cacheFileName}_" + rm ${cacheFileName} if [[ "${ErrorLogLevel}" == "err" ]]; then throw "${errMsg}" ${ErrorLogLevel} 2 else @@ -46,8 +54,7 @@ if [[ ${marketsCheck} -eq 0 ]]; then exit 2 fi else - jq < temp/markets.tmp.$$.json - rm temp/markets.tmp.$$.json + jq < ${cacheFileName} fi diff --git a/getOrders.sh b/getOrders.sh index 983cb35..bc1d00d 100755 --- a/getOrders.sh +++ b/getOrders.sh @@ -21,6 +21,4 @@ echo $fromEnteredTime ./getNewAccessToken.sh curl -s -X GET "https://api.schwabapi.com/trader/v1/orders?fromEnteredTime=${fromEnteredTime}&toEnteredTime=${toEnteredTime}" -H "Authorization: Bearer $( ${tempFile} -#jq -r 'map(.enteredTime)[]' < ${tempFile} -#jq -r '.[].orderLegCollection[].instrument.symbol' < ${tempFile} jq -r '.[] | [.orderId | tostring][0] + "," + .status + "," + .orderLegCollection[].instrument.symbol' < ${tempFile}