Files

23 lines
755 B
Bash
Raw Permalink Normal View History

#!/bin/bash
#set -x
mkdir -p temp
tempFile=temp/accountOrders.tmp.$$.json
fromEnteredTime=$(date -u "+%Y-%m-%dT%H:%M:%S.000Z" -d "-100 days")
toEnteredTime=$(date -u "+%Y-%m-%dT%H:%M:%S.000Z" -d "-0 minutes")
while [[ $# -gt 0 ]]
do
case "$1" in
-daysBack) fromEnteredTime=$(date -u "+%Y-%m-%dT%H:%M:%S.000Z" -d "-$2 days");
shift;shift
;;
-*|--*|*) echo "Invalid option: -$1"; exit 1;;
esac
done
echo $fromEnteredTime
2024-09-03 10:32:56 -05:00
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}