Skip to content

Instantly share code, notes, and snippets.

@mhluska
Last active November 22, 2017 15:33
Show Gist options
  • Save mhluska/347b61edfa31c0348ca1f21aeb9a2207 to your computer and use it in GitHub Desktop.
Save mhluska/347b61edfa31c0348ca1f21aeb9a2207 to your computer and use it in GitHub Desktop.
Transfer money into Gemini exchange (no API, no Selenium)
#!/bin/bash
# Exit on error or unset variable.
set -e
set -u
source .env
# TODO: Find a builtin way to do this.
function urldecode() {
python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])" "${1}"
}
# TODO: Find a builtin way to do this.
function urlencode() {
python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1])" "${1}"
}
function print_help() {
echo "usage: ${0} amount"
}
if [ "${#}" -ne 1 ]; then
print_help
exit 1
fi
TRANSFER_AMOUNT="${1}"
# Get CSRF token.
curl \
--silent \
-b ./cookies \
-c ./cookies \
https://exchange.gemini.com/signin >/dev/null
csrf_token=$(cat cookies | grep GEMINI_SESSION | awk '{print $7}' | awk -F '=' '{print $2}')
# Attempt sign in.
curl \
--silent \
-b ./cookies \
-c ./cookies \
-H 'Pragma: no-cache' \
-H 'Origin: https://exchange.gemini.com' \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'Accept-Language: en-GB,en-US;q=0.8,en;q=0.6' \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' \
-H 'Cache-Control: no-cache' \
-H 'Referer: https://exchange.gemini.com/signin' \
-H 'Connection: keep-alive' \
--data "csrfToken=${csrf_token}&email=$(urlencode "${GEMINI_EMAIL}")&password=${GEMINI_PASSWORD}" \
--compressed \
https://exchange.gemini.com/signin >/dev/null
curl \
--silent \
-b ./cookies \
-c ./cookies \
-D ./headers \
https://exchange.gemini.com >/dev/null
# Enter two factor code.
location=$(urldecode $(grep Location ./headers | awk '{print $2}'))
totp=$(oathtool --digits=7 --totp --time-step-size=10 "${GEMINI_TWO_FACTOR_SECRET}")
curl \
--silent \
-b ./cookies \
-c ./cookies \
-H 'Pragma: no-cache' \
-H 'Origin: https://exchange.gemini.com' \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'Accept-Language: en-GB,en-US;q=0.8,en;q=0.6' \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Length: 117' \
--data "token=${totp}&csrfToken=${csrf_token}&remember=true" \
--compressed \
"https://exchange.gemini.com${location%$'\r'}" >/dev/null
# Initiate transfer.
curl \
--silent \
-b ./cookies \
-c ./cookies \
-H 'Host: exchange.gemini.com' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:54.0) Gecko/20100101 Firefox/54.0' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
-H 'Accept-Language: en-GB,en;q=0.5' \
-H 'Referer: https://exchange.gemini.com/deposit/usd/ach' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Connection: keep-alive' \
-H 'Upgrade-Insecure-Requests: 1' \
--data "csrfToken=${csrf_token}&amount=${TRANSFER_AMOUNT}&bankAccountUuid=${BANK_ACCOUNT_UUID}&emailOnAchLimitReset=true" \
--compressed \
https://exchange.gemini.com/deposit/usd/ach >/dev/null
rm -f ./cookies ./headers
echo "Finished initiating ${TRANSFER_AMOUNT} transfer"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment