Skip to content

Instantly share code, notes, and snippets.

@JonathanVeg
Created May 4, 2021 18:03
Show Gist options
  • Save JonathanVeg/1b15247388cebad5b42a0f33b1cd44bf to your computer and use it in GitHub Desktop.
Save JonathanVeg/1b15247388cebad5b42a0f33b1cd44bf to your computer and use it in GitHub Desktop.
import time
import datetime
import base64
import hmac
import json
from hashlib import sha512
from urllib.request import urlopen, Request
from urllib.error import HTTPError
apiKey = 'YOUR CREX24 API KEY'
secret = 'YOUR CREX24 API SECRET'
address = 'Your wallet'
baseUrl = "https://api.crex24.com"
amount = 100000 # amout to be withdraw in each try - max is about 900000
allowed = False
def notifyWithdrawDoneToSlack():
# Optional - if want to be notified create a slack account and get an web hook - It's free!
url = "your slack url"
request = Request(url)
request.method = "POST"
request.data = str.encode(str({"text": "Saque de %d HTMLs feito com sucesso na Crex24 pra a carteira %s"%(amount, address)}), "utf-8")
try:
response = urlopen(request)
except HTTPError as e:
response = e
print(e)
def writeToFile(content):
arq = open('lastrunpy.txt', 'a+')
arq.write("%s\n\n" % content)
arq.close()
def execWithdraw():
path = "/v2/account/withdraw"
body = json.dumps({
"currency": "HTML",
"amount": amount,
"address": address
}, separators=(',', ':'))
nonce = round(datetime.datetime.now().timestamp() * 1000)
key = base64.b64decode(secret)
message = str.encode(path + str(nonce) + body, "utf-8")
generatedHmac = hmac.new(key, message, sha512)
signature = base64.b64encode(generatedHmac.digest()).decode()
request = Request(baseUrl + path)
request.method = "POST"
request.data = str.encode(body, "utf-8")
request.add_header("Content-Length", len(body))
request.add_header("X-CREX24-API-KEY", apiKey)
request.add_header("X-CREX24-API-NONCE", nonce)
request.add_header("X-CREX24-API-SIGN", signature)
try:
response = urlopen(request)
except HTTPError as e:
response = e
status = response.getcode()
body = bytes.decode(response.read())
print("Status code: " + str(status))
if status == 200:
notifyWithdrawDoneToSlack()
print(body)
content = "Trying to exec withdraw: %s %s"%(str(status), body)
writeToFile(content)
def verifyIfWithdrawIsOpened():
url = "https://api.crex24.com/v2/public/currencies?filter=HTML"
request = Request(url)
request.method = "GET"
try:
response = urlopen(request)
body = json.loads(bytes.decode(response.read()))[0]
allowed = body["withdrawalsAllowed"]
return allowed
except HTTPError as e:
response = e
return false
content = str(datetime.datetime.now())
allowed = verifyIfWithdrawIsOpened()
content += " - allowed: %s"%allowed
writeToFile(content)
if allowed:
for i in range(1, 10):
execWithdraw()
time.sleep(3)
exit()
else:
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment