diff --git a/autoTradeQQQLongCall.sh b/autoTradeQQQLongCall.sh index 9787206..d27fb36 100755 --- a/autoTradeQQQLongCall.sh +++ b/autoTradeQQQLongCall.sh @@ -4,9 +4,7 @@ IFS=$'\0' . helpers.sh -./getNewAccessToken.sh - -daysOutMin=90 +daysOutMin=87 daysOutMax=91 deltaMin=0.35 deltaMax=0.40 @@ -88,7 +86,7 @@ fi curl -s -X POST \ "https://api.schwabapi.com/trader/v1/accounts/$(./getAccountNumbers.sh IRA)/orders" \ - -H "Authorization: Bearer $( ${tempFile} +curl -s -X GET "https://api.schwabapi.com/trader/v1/accounts/accountNumbers" -H "Authorization: Bearer $(./getNewAccessToken.sh)" > ${tempFile} (jq -r '.[] | [.accountNumber, .hashValue ] | @tsv' < ${tempFile} | while read accNo accHash; do read accInfo <<< $(grep ${accNo} accountNumberNameMapping.dat; echo ${accNo}) echo ${accInfo} ${accHash} diff --git a/getMarketHours.sh b/getMarketHours.sh index ff94c29..dccbfc6 100755 --- a/getMarketHours.sh +++ b/getMarketHours.sh @@ -40,7 +40,7 @@ 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 $( ${cacheFileName} + -H "Authorization: Bearer $(./getNewAccessToken.sh)" > ${cacheFileName} marketsCheck=$(jq -e -r '.. | .isOpen?' ${cacheFileName} | grep -v null | wc -l) diff --git a/getNewAccessToken.sh b/getNewAccessToken.sh index 6113ff7..d07d236 100755 --- a/getNewAccessToken.sh +++ b/getNewAccessToken.sh @@ -2,17 +2,21 @@ #set -x mkdir -p temp +ageInSec=$(($(date +%s) - $(date +%s -r "access_token.dat"))) -curl -s -X POST https://api.schwabapi.com/v1/oauth/token \ - -H "Authorization: Basic $( temp/accessTokenReqResp.$$.json -jq -e -r .access_token temp/accessTokenReqResp.$$.json > access_token.dat -if [[ $? -ne 0 ]]; then - curl -d "" -X POST "https://deadswitch.kawomi.com/api/v1?topic=trade.schwab.error.getNewAccessToken&secs=1&email=joe@kawomi.com" - throw "ERROR: GETTING THE ACCESS TOKEN FAILED! $( temp/accessTokenReqResp.$$.json + jq -e -r .access_token temp/accessTokenReqResp.$$.json > access_token.dat + if [[ $? -ne 0 ]]; then + curl -d "" -X POST "https://deadswitch.kawomi.com/api/v1?topic=trade.schwab.error.getNewAccessToken&secs=1&email=joe@kawomi.com" + throw "ERROR: GETTING THE ACCESS TOKEN FAILED! $( temp/optionChain.${symbol}.tmp.$$.json + -H "Authorization: Bearer $(./getNewAccessToken.sh)" > temp/optionChain.${symbol}.tmp.$$.json jqQuery=".symbol" symbolCheck=$(jq -r ${jqQuery} < temp/optionChain.${symbol}.tmp.$$.json) diff --git a/getOrders.sh b/getOrders.sh index bc1d00d..91c5ae1 100755 --- a/getOrders.sh +++ b/getOrders.sh @@ -18,7 +18,5 @@ done echo $fromEnteredTime -./getNewAccessToken.sh - -curl -s -X GET "https://api.schwabapi.com/trader/v1/orders?fromEnteredTime=${fromEnteredTime}&toEnteredTime=${toEnteredTime}" -H "Authorization: Bearer $( ${tempFile} +curl -s -X GET "https://api.schwabapi.com/trader/v1/orders?fromEnteredTime=${fromEnteredTime}&toEnteredTime=${toEnteredTime}" -H "Authorization: Bearer $(./getNewAccessToken.sh)" > ${tempFile} jq -r '.[] | [.orderId | tostring][0] + "," + .status + "," + .orderLegCollection[].instrument.symbol' < ${tempFile} diff --git a/getPositions.sh b/getPositions.sh index fb3d746..9e8fb5e 100755 --- a/getPositions.sh +++ b/getPositions.sh @@ -2,9 +2,7 @@ #set -x mkdir -p temp -./getNewAccessToken.sh - tempFile=temp/accountPositions.tmp.$$.json -curl -s -X GET "https://api.schwabapi.com/trader/v1/accounts/?fields=positions" -H "Authorization: Bearer $( ${tempFile} +curl -s -X GET "https://api.schwabapi.com/trader/v1/accounts/?fields=positions" -H "Authorization: Bearer $(./getNewAccessToken.sh)" > ${tempFile} jq -e '{ accountNumber:.[].securitiesAccount.accountNumber, positions:.[].securitiesAccount.positions}' < ${tempFile} diff --git a/recordAllSymbolsSingleRun.sh b/recordAllSymbolsSingleRun.sh index f8a24ce..27d1f0c 100755 --- a/recordAllSymbolsSingleRun.sh +++ b/recordAllSymbolsSingleRun.sh @@ -5,7 +5,6 @@ log "Started" -./getNewAccessToken.sh if [[ $? -ne 0 ]]; then throw "Child process to get access token reported error. Exiting." err 1 fi diff --git a/recordOptionChainSingleSymbolSingleRun.sh b/recordOptionChainSingleSymbolSingleRun.sh index 2ffdafc..81baf8e 100755 --- a/recordOptionChainSingleSymbolSingleRun.sh +++ b/recordOptionChainSingleSymbolSingleRun.sh @@ -27,7 +27,7 @@ done log "Querying for Symbol: _${symbol}_ query string: _${queryString}_" debug curl -s -X GET "https://api.schwabapi.com/marketdata/v1/chains${queryString}" \ - -H "Authorization: Bearer $( temp/optionChain.${symbol}.tmp.$$.json + -H "Authorization: Bearer $(./getNewAccessToken.sh)" > temp/optionChain.${symbol}.tmp.$$.json jqQuery=".symbol" symbolCheck=$(jq -r ${jqQuery} < temp/optionChain.${symbol}.tmp.$$.json) diff --git a/recordOptionChainSingleSymbolSpecialRun.sh b/recordOptionChainSingleSymbolSpecialRun.sh index 2acba46..9106b60 100755 --- a/recordOptionChainSingleSymbolSpecialRun.sh +++ b/recordOptionChainSingleSymbolSpecialRun.sh @@ -24,7 +24,7 @@ for range in ITM OTM NTM; do log "Querying for Symbol: _${symbol}_ query string: _${queryString}&range=${range}_" debug curl -s -X GET "https://api.schwabapi.com/marketdata/v1/chains${queryString}&range=${range}" \ - -H "Authorization: Bearer $( temp/optionChain.${symbol}.${range}.tmp.$$.json + -H "Authorization: Bearer $(./getNewAccessToken.sh)" > temp/optionChain.${symbol}.${range}.tmp.$$.json jqQuery=".symbol" symbolCheck=$(jq -r ${jqQuery} < temp/optionChain.${symbol}.${range}.tmp.$$.json) diff --git a/recordQuoteSingleSymbolSingleRun.sh b/recordQuoteSingleSymbolSingleRun.sh index 437a1d5..ab0c683 100755 --- a/recordQuoteSingleSymbolSingleRun.sh +++ b/recordQuoteSingleSymbolSingleRun.sh @@ -8,7 +8,7 @@ mkdir -p "${outDir}" mkdir -p temp curl -s -X GET "https://api.schwabapi.com/marketdata/v1/${symbol}/quotes?fields=quote%2Creference" \ - -H "Authorization: Bearer $( temp/quote.${symbol}.tmp.$$.json + -H "Authorization: Bearer $(./getNewAccessToken.sh)" > temp/quote.${symbol}.tmp.$$.json jqQuery=".\"${symbol}\".symbol" symbolCheck=$(jq -r ${jqQuery} < temp/quote.${symbol}.tmp.$$.json)