From d8891ec75fff534dd536ba28c9aaf44e7b12b03b Mon Sep 17 00:00:00 2001 From: Joe Tretter Date: Mon, 26 Aug 2024 21:44:43 -0500 Subject: [PATCH] Introduce mnemonic account name resolution in getAccountNumbers --- accountNumberNameMapping.dat | 4 ++++ autoTradeQQQLongCall.sh | 6 +++--- autoTradeSPXPutCreditSpread.sh | 6 +++--- autoTradeSPX_IB_0DTE_25pctProfitTaker.sh | 6 +++--- autoTradeSPX_IB_1DTE.sh | 8 ++++---- autoTradeSPYLongCall.sh | 10 +++++----- getAccountNumbers.sh | 13 ++++++++++--- getPositions.sh | 10 ++++++++++ 8 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 accountNumberNameMapping.dat create mode 100755 getPositions.sh diff --git a/accountNumberNameMapping.dat b/accountNumberNameMapping.dat new file mode 100644 index 0000000..b8bc9d4 --- /dev/null +++ b/accountNumberNameMapping.dat @@ -0,0 +1,4 @@ +Roth 55040747 +Individual 58291665 +IRA 80319442 +Regular 89036276 diff --git a/autoTradeQQQLongCall.sh b/autoTradeQQQLongCall.sh index 6a32ebf..cb3ffac 100755 --- a/autoTradeQQQLongCall.sh +++ b/autoTradeQQQLongCall.sh @@ -97,9 +97,9 @@ fi ./getNewAccessToken.sh curl -s -X POST \ - 'https://api.schwabapi.com/trader/v1/accounts/CEF970366D4CC9553B5E8846E35FD92A1867F3E73C1082A52647256F42E4746B/orders' \ - -H "Authorization: Bearer $(&2 echo "${errMsg}" -# exit 2 + exit 2 fi inputFile="$1" @@ -152,9 +152,9 @@ fi curl -s -X POST \ - 'https://api.schwabapi.com/trader/v1/accounts/C819AC820A502BA92E55D775B22BDF0E1BC91D86C62685714347734A5827CCB3/orders' \ - -H "Authorization: Bearer $( ${tempFile} -jq '.' < ${tempFile} +(jq -r '.[] | [.accountNumber, .hashValue ] | @tsv' < ${tempFile} | while read accNo accHash; do + read accInfo <<< $(grep ${accNo} accountNumberNameMapping.dat; echo ${accNo}) + echo ${accInfo} ${accHash} +done) >> ${tempFlatFile} +if [[ "$1" != "" ]]; then + read accName accNum accHash <<< $(grep $1 ${tempFlatFile}); echo -n ${accHash} +else + cat ${tempFlatFile} +fi diff --git a/getPositions.sh b/getPositions.sh new file mode 100755 index 0000000..fb3d746 --- /dev/null +++ b/getPositions.sh @@ -0,0 +1,10 @@ +#!/bin/bash +#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} +jq -e '{ accountNumber:.[].securitiesAccount.accountNumber, positions:.[].securitiesAccount.positions}' < ${tempFile} +