change the access token to be cached
This commit is contained in:
@@ -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 $(<access_token.dat)" \
|
||||
-H "Authorization: Bearer $(./getNewAccessToken.sh)" \
|
||||
-H 'accept: */*' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "${orderJson}"
|
||||
|
||||
@@ -4,8 +4,6 @@ set -e
|
||||
IFS=$'\0'
|
||||
myPID=$$
|
||||
. helpers.sh
|
||||
./getNewAccessToken.sh
|
||||
|
||||
|
||||
marketOpen=$([[ $(./getMarketHours.sh | jq '.option[].isOpen' | grep true | wc -l) -ne 0 ]] && echo true || echo false)
|
||||
if [[ ${marketOpen} == false ]]; then
|
||||
@@ -90,7 +88,7 @@ fi
|
||||
|
||||
curl -s -X POST \
|
||||
"https://api.schwabapi.com/trader/v1/accounts/$(./getAccountNumbers.sh Regular)/orders" \
|
||||
-H "Authorization: Bearer $(<access_token.dat)" \
|
||||
-H "Authorization: Bearer $(./getNewAccessToken.sh)" \
|
||||
-H 'accept: */*' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "${orderJson}"
|
||||
|
||||
@@ -4,8 +4,6 @@ set -e
|
||||
IFS=$'\0'
|
||||
myPID=$$
|
||||
. helpers.sh
|
||||
./getNewAccessToken.sh
|
||||
|
||||
|
||||
marketOpen=$([[ $(./getMarketHours.sh | jq '.option[].isOpen' | grep true | wc -l) -ne 0 ]] && echo true || echo false)
|
||||
if [[ ${marketOpen} == false ]]; then
|
||||
@@ -178,7 +176,7 @@ fi
|
||||
|
||||
curl -s -X POST \
|
||||
"https://api.schwabapi.com/trader/v1/accounts/$(./getAccountNumbers.sh Regular)/orders" \
|
||||
-H "Authorization: Bearer $(<access_token.dat)" \
|
||||
-H "Authorization: Bearer $(./getNewAccessToken.sh)" \
|
||||
-H 'accept: */*' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "${orderJson}"
|
||||
|
||||
@@ -5,8 +5,6 @@ IFS=$'\0'
|
||||
myPID=$$
|
||||
. helpers.sh
|
||||
|
||||
./getNewAccessToken.sh
|
||||
|
||||
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
|
||||
@@ -134,7 +132,7 @@ fi
|
||||
|
||||
curl -s -X POST \
|
||||
"https://api.schwabapi.com/trader/v1/accounts/$(./getAccountNumbers.sh Regular)/orders" \
|
||||
-H "Authorization: Bearer $(<access_token.dat)" \
|
||||
-H "Authorization: Bearer $(./getNewAccessToken.sh)" \
|
||||
-H 'accept: */*' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "${orderJson}"
|
||||
|
||||
@@ -3,10 +3,8 @@ set -x
|
||||
IFS=$'\0'
|
||||
|
||||
. helpers.sh
|
||||
./getNewAccessToken.sh
|
||||
|
||||
|
||||
daysOutMin=90
|
||||
daysOutMin=87
|
||||
daysOutMax=95
|
||||
deltaMin=0.35
|
||||
deltaMax=0.40
|
||||
@@ -91,9 +89,9 @@ if [[ "${noconfirm}" != "true" ]]; then
|
||||
read
|
||||
fi
|
||||
|
||||
echo curl -s -X POST \
|
||||
curl -s -X POST \
|
||||
"https://api.schwabapi.com/trader/v1/accounts/$(./getAccountNumbers.sh Roth)/orders" \
|
||||
-H "Authorization: Bearer $(<access_token.dat)" \
|
||||
-H "Authorization: Bearer $(./getNewAccessToken.sh)" \
|
||||
-H 'accept: */*' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "${orderJson}"
|
||||
|
||||
@@ -4,7 +4,7 @@ mkdir -p temp
|
||||
|
||||
tempFile=temp/accountNumbers.tmp.$$.json
|
||||
tempFlatFile=temp/accountNumbers.flat.$$.tsv
|
||||
curl -s -X GET "https://api.schwabapi.com/trader/v1/accounts/accountNumbers" -H "Authorization: Bearer $(<access_token.dat)" > ${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}
|
||||
|
||||
@@ -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 $(<access_token.dat)" > ${cacheFileName}
|
||||
-H "Authorization: Bearer $(./getNewAccessToken.sh)" > ${cacheFileName}
|
||||
|
||||
|
||||
marketsCheck=$(jq -e -r '.. | .isOpen?' ${cacheFileName} | grep -v null | wc -l)
|
||||
|
||||
@@ -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 $(<appCredentials.dat)" \
|
||||
-H 'Content-Type: application/x-www-form-urlencoded' \
|
||||
-d "grant_type=refresh_token&refresh_token=$(<refresh_token.dat)" > 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)" err
|
||||
#Cache the last token for 10 min.
|
||||
if [[ ${ageInSec} -gt 600 ]]; then
|
||||
curl -s -X POST https://api.schwabapi.com/v1/oauth/token \
|
||||
-H "Authorization: Basic $(<appCredentials.dat)" \
|
||||
-H 'Content-Type: application/x-www-form-urlencoded' \
|
||||
-d "grant_type=refresh_token&refresh_token=$(<refresh_token.dat)" > 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)" err
|
||||
fi
|
||||
fi
|
||||
#echo Access Token: $(<access_token.dat)
|
||||
echo -n -e "$(<access_token.dat)"
|
||||
|
||||
## I found the refresh token to be empty after the network is unreachable, therefore I don't handle the refresh token here...
|
||||
## I have not seen it change, but let's see if they give us a new one before expiry...
|
||||
|
||||
@@ -25,7 +25,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 $(<access_token.dat)" > 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)
|
||||
|
||||
@@ -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 $(<access_token.dat)" > ${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}
|
||||
|
||||
@@ -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 $(<access_token.dat)" > ${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}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 $(<access_token.dat)" > 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)
|
||||
|
||||
@@ -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 $(<access_token.dat)" > 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)
|
||||
|
||||
@@ -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 $(<access_token.dat)" > 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)
|
||||
|
||||
Reference in New Issue
Block a user