change the access token to be cached
This commit is contained in:
@@ -4,9 +4,7 @@ IFS=$'\0'
|
|||||||
|
|
||||||
. helpers.sh
|
. helpers.sh
|
||||||
|
|
||||||
./getNewAccessToken.sh
|
daysOutMin=87
|
||||||
|
|
||||||
daysOutMin=90
|
|
||||||
daysOutMax=91
|
daysOutMax=91
|
||||||
deltaMin=0.35
|
deltaMin=0.35
|
||||||
deltaMax=0.40
|
deltaMax=0.40
|
||||||
@@ -88,7 +86,7 @@ fi
|
|||||||
|
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
"https://api.schwabapi.com/trader/v1/accounts/$(./getAccountNumbers.sh IRA)/orders" \
|
"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 'accept: */*' \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
-d "${orderJson}"
|
-d "${orderJson}"
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ set -e
|
|||||||
IFS=$'\0'
|
IFS=$'\0'
|
||||||
myPID=$$
|
myPID=$$
|
||||||
. helpers.sh
|
. helpers.sh
|
||||||
./getNewAccessToken.sh
|
|
||||||
|
|
||||||
|
|
||||||
marketOpen=$([[ $(./getMarketHours.sh | jq '.option[].isOpen' | grep true | wc -l) -ne 0 ]] && echo true || echo false)
|
marketOpen=$([[ $(./getMarketHours.sh | jq '.option[].isOpen' | grep true | wc -l) -ne 0 ]] && echo true || echo false)
|
||||||
if [[ ${marketOpen} == false ]]; then
|
if [[ ${marketOpen} == false ]]; then
|
||||||
@@ -90,7 +88,7 @@ fi
|
|||||||
|
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
"https://api.schwabapi.com/trader/v1/accounts/$(./getAccountNumbers.sh Regular)/orders" \
|
"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 'accept: */*' \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
-d "${orderJson}"
|
-d "${orderJson}"
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ set -e
|
|||||||
IFS=$'\0'
|
IFS=$'\0'
|
||||||
myPID=$$
|
myPID=$$
|
||||||
. helpers.sh
|
. helpers.sh
|
||||||
./getNewAccessToken.sh
|
|
||||||
|
|
||||||
|
|
||||||
marketOpen=$([[ $(./getMarketHours.sh | jq '.option[].isOpen' | grep true | wc -l) -ne 0 ]] && echo true || echo false)
|
marketOpen=$([[ $(./getMarketHours.sh | jq '.option[].isOpen' | grep true | wc -l) -ne 0 ]] && echo true || echo false)
|
||||||
if [[ ${marketOpen} == false ]]; then
|
if [[ ${marketOpen} == false ]]; then
|
||||||
@@ -178,7 +176,7 @@ fi
|
|||||||
|
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
"https://api.schwabapi.com/trader/v1/accounts/$(./getAccountNumbers.sh Regular)/orders" \
|
"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 'accept: */*' \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
-d "${orderJson}"
|
-d "${orderJson}"
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ IFS=$'\0'
|
|||||||
myPID=$$
|
myPID=$$
|
||||||
. helpers.sh
|
. helpers.sh
|
||||||
|
|
||||||
./getNewAccessToken.sh
|
|
||||||
|
|
||||||
marketOpen=$([[ $(./getMarketHours.sh | jq '.option[].isOpen' | grep true | wc -l) -ne 0 ]] && echo true || echo false)
|
marketOpen=$([[ $(./getMarketHours.sh | jq '.option[].isOpen' | grep true | wc -l) -ne 0 ]] && echo true || echo false)
|
||||||
if [[ ${marketOpen} == false ]]; then
|
if [[ ${marketOpen} == false ]]; then
|
||||||
throw "The market is closed, exiting." info 2
|
throw "The market is closed, exiting." info 2
|
||||||
@@ -134,7 +132,7 @@ fi
|
|||||||
|
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
"https://api.schwabapi.com/trader/v1/accounts/$(./getAccountNumbers.sh Regular)/orders" \
|
"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 'accept: */*' \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
-d "${orderJson}"
|
-d "${orderJson}"
|
||||||
|
|||||||
@@ -3,10 +3,8 @@ set -x
|
|||||||
IFS=$'\0'
|
IFS=$'\0'
|
||||||
|
|
||||||
. helpers.sh
|
. helpers.sh
|
||||||
./getNewAccessToken.sh
|
|
||||||
|
|
||||||
|
daysOutMin=87
|
||||||
daysOutMin=90
|
|
||||||
daysOutMax=95
|
daysOutMax=95
|
||||||
deltaMin=0.35
|
deltaMin=0.35
|
||||||
deltaMax=0.40
|
deltaMax=0.40
|
||||||
@@ -91,9 +89,9 @@ if [[ "${noconfirm}" != "true" ]]; then
|
|||||||
read
|
read
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo curl -s -X POST \
|
curl -s -X POST \
|
||||||
"https://api.schwabapi.com/trader/v1/accounts/$(./getAccountNumbers.sh Roth)/orders" \
|
"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 'accept: */*' \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
-d "${orderJson}"
|
-d "${orderJson}"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ mkdir -p temp
|
|||||||
|
|
||||||
tempFile=temp/accountNumbers.tmp.$$.json
|
tempFile=temp/accountNumbers.tmp.$$.json
|
||||||
tempFlatFile=temp/accountNumbers.flat.$$.tsv
|
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
|
(jq -r '.[] | [.accountNumber, .hashValue ] | @tsv' < ${tempFile} | while read accNo accHash; do
|
||||||
read accInfo <<< $(grep ${accNo} accountNumberNameMapping.dat; echo ${accNo})
|
read accInfo <<< $(grep ${accNo} accountNumberNameMapping.dat; echo ${accNo})
|
||||||
echo ${accInfo} ${accHash}
|
echo ${accInfo} ${accHash}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ done
|
|||||||
log "Querying for markets: _${markets}_ query string: _${queryString}_" debug
|
log "Querying for markets: _${markets}_ query string: _${queryString}_" debug
|
||||||
|
|
||||||
curl -s -X GET "https://api.schwabapi.com/marketdata/v1/markets${queryString}" \
|
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)
|
marketsCheck=$(jq -e -r '.. | .isOpen?' ${cacheFileName} | grep -v null | wc -l)
|
||||||
|
|||||||
@@ -2,17 +2,21 @@
|
|||||||
#set -x
|
#set -x
|
||||||
|
|
||||||
mkdir -p temp
|
mkdir -p temp
|
||||||
|
ageInSec=$(($(date +%s) - $(date +%s -r "access_token.dat")))
|
||||||
|
|
||||||
curl -s -X POST https://api.schwabapi.com/v1/oauth/token \
|
#Cache the last token for 10 min.
|
||||||
-H "Authorization: Basic $(<appCredentials.dat)" \
|
if [[ ${ageInSec} -gt 600 ]]; then
|
||||||
-H 'Content-Type: application/x-www-form-urlencoded' \
|
curl -s -X POST https://api.schwabapi.com/v1/oauth/token \
|
||||||
-d "grant_type=refresh_token&refresh_token=$(<refresh_token.dat)" > temp/accessTokenReqResp.$$.json
|
-H "Authorization: Basic $(<appCredentials.dat)" \
|
||||||
jq -e -r .access_token temp/accessTokenReqResp.$$.json > access_token.dat
|
-H 'Content-Type: application/x-www-form-urlencoded' \
|
||||||
if [[ $? -ne 0 ]]; then
|
-d "grant_type=refresh_token&refresh_token=$(<refresh_token.dat)" > temp/accessTokenReqResp.$$.json
|
||||||
curl -d "" -X POST "https://deadswitch.kawomi.com/api/v1?topic=trade.schwab.error.getNewAccessToken&secs=1&email=joe@kawomi.com"
|
jq -e -r .access_token temp/accessTokenReqResp.$$.json > access_token.dat
|
||||||
throw "ERROR: GETTING THE ACCESS TOKEN FAILED! $(<temp/accessTokenReqResp.$$.json)" err
|
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
|
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 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...
|
## 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
|
log "Querying for Symbol: _${symbol}_ query string: _${queryString}_" debug
|
||||||
|
|
||||||
curl -s -X GET "https://api.schwabapi.com/marketdata/v1/chains${queryString}" \
|
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"
|
jqQuery=".symbol"
|
||||||
symbolCheck=$(jq -r ${jqQuery} < temp/optionChain.${symbol}.tmp.$$.json)
|
symbolCheck=$(jq -r ${jqQuery} < temp/optionChain.${symbol}.tmp.$$.json)
|
||||||
|
|||||||
@@ -18,7 +18,5 @@ done
|
|||||||
|
|
||||||
echo $fromEnteredTime
|
echo $fromEnteredTime
|
||||||
|
|
||||||
./getNewAccessToken.sh
|
curl -s -X GET "https://api.schwabapi.com/trader/v1/orders?fromEnteredTime=${fromEnteredTime}&toEnteredTime=${toEnteredTime}" -H "Authorization: Bearer $(./getNewAccessToken.sh)" > ${tempFile}
|
||||||
|
|
||||||
curl -s -X GET "https://api.schwabapi.com/trader/v1/orders?fromEnteredTime=${fromEnteredTime}&toEnteredTime=${toEnteredTime}" -H "Authorization: Bearer $(<access_token.dat)" > ${tempFile}
|
|
||||||
jq -r '.[] | [.orderId | tostring][0] + "," + .status + "," + .orderLegCollection[].instrument.symbol' < ${tempFile}
|
jq -r '.[] | [.orderId | tostring][0] + "," + .status + "," + .orderLegCollection[].instrument.symbol' < ${tempFile}
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
#set -x
|
#set -x
|
||||||
mkdir -p temp
|
mkdir -p temp
|
||||||
|
|
||||||
./getNewAccessToken.sh
|
|
||||||
|
|
||||||
tempFile=temp/accountPositions.tmp.$$.json
|
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}
|
jq -e '{ accountNumber:.[].securitiesAccount.accountNumber, positions:.[].securitiesAccount.positions}' < ${tempFile}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
log "Started"
|
log "Started"
|
||||||
|
|
||||||
./getNewAccessToken.sh
|
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
throw "Child process to get access token reported error. Exiting." err 1
|
throw "Child process to get access token reported error. Exiting." err 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ done
|
|||||||
log "Querying for Symbol: _${symbol}_ query string: _${queryString}_" debug
|
log "Querying for Symbol: _${symbol}_ query string: _${queryString}_" debug
|
||||||
|
|
||||||
curl -s -X GET "https://api.schwabapi.com/marketdata/v1/chains${queryString}" \
|
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"
|
jqQuery=".symbol"
|
||||||
symbolCheck=$(jq -r ${jqQuery} < temp/optionChain.${symbol}.tmp.$$.json)
|
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
|
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}" \
|
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"
|
jqQuery=".symbol"
|
||||||
symbolCheck=$(jq -r ${jqQuery} < temp/optionChain.${symbol}.${range}.tmp.$$.json)
|
symbolCheck=$(jq -r ${jqQuery} < temp/optionChain.${symbol}.${range}.tmp.$$.json)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ mkdir -p "${outDir}"
|
|||||||
mkdir -p temp
|
mkdir -p temp
|
||||||
|
|
||||||
curl -s -X GET "https://api.schwabapi.com/marketdata/v1/${symbol}/quotes?fields=quote%2Creference" \
|
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"
|
jqQuery=".\"${symbol}\".symbol"
|
||||||
symbolCheck=$(jq -r ${jqQuery} < temp/quote.${symbol}.tmp.$$.json)
|
symbolCheck=$(jq -r ${jqQuery} < temp/quote.${symbol}.tmp.$$.json)
|
||||||
|
|||||||
Reference in New Issue
Block a user