Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import datetime
- import time
- import configparser
- from requests.adapters import HTTPAdapter
- from requests.packages.urllib3.util.retry import Retry
- def block_number(): # ritorna l'altezza dell'ultimo blocco trovato
- t0 = time.time()
- max = 0
- while max == 0:
- try:
- time.sleep(3)
- response = requests_retry_session().get('https://slushpool.com/stats/json/', timeout=5)
- data = response.json()
- for key in data:
- if key == "blocks":
- value = data[key]
- for key2 in value:
- if str(key2) > str(max):
- max = key2
- t2 = time.time()
- print('It works - Status Code:', response.status_code, '- Took', t2 - t0, 'seconds')
- except Exception as x:
- t1 = time.time()
- print('It failed :(', x.__class__.__name__, '- Took', t1 - t0, 'seconds')
- pass
- return max
- def last_block_found(): # ritorna la data dell'ultimo blocco slush trovato in formato YYYY-MM-DD HH:MM:SS
- t0 = time.time()
- while True:
- try:
- response = requests_retry_session().get('https://slushpool.com/stats/json/', timeout=5)
- except Exception as x:
- t1 = time.time()
- print('It failed :(', x.__class__.__name__, '- Took', t1 - t0, 'seconds')
- pass
- else:
- t2 = time.time()
- print('It works - Status Code:', response.status_code, '- Took', t2 - t0, 'seconds')
- data = response.json()
- round_started = data["round_started"]
- return round_started
- def nicehash_total_sha256d_speed(): #ritorna il totale della potenza di calcolo sha256d su nicehash in TH/s
- t0 = time.time()
- while True:
- try:
- response = requests_retry_session().get('https://api.nicehash.com/api?method=stats.global.24h', timeout=5)
- except Exception as x:
- t1 = time.time()
- print('It failed :(', x.__class__.__name__, '- Took', t1 - t0, 'seconds')
- pass
- else:
- t2 = time.time()
- print('It works - Status Code:', response.status_code, '- Took', t2 - t0, 'seconds')
- data = response.json()
- result = data["result"]
- stats = result["stats"]
- sha256d = stats[1]
- speed = int(eval(sha256d["speed"]) / 1000)
- return speed
- def nicehash_best_sha256d_price(): # ritorna il prezzo migliore d'acquisto per sha256d su nicehash in BTC/PH/DAY
- t0 = time.time()
- while True:
- try:
- response = requests_retry_session().get('https://api.nicehash.com/api?method=stats.global.24h', timeout=5)
- except Exception as x:
- t1 = time.time()
- print('It failed :(', x.__class__.__name__, '- Took', t1 - t0, 'seconds')
- pass
- else:
- t2 = time.time()
- print('It works - Status Code:', response.status_code, '- Took', t2 - t0, 'seconds')
- data = response.json()
- result = data["result"]
- stats = result["stats"]
- sha256d = stats[1]
- price = sha256d["price"]
- return price
- def now(): # ritorna la data attuale in formato YYYY-MM-DD HH:MM:SS
- return datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S")
- def nicehash_get_order_method(api, key):
- try:
- raw_data = requests.get("https://www.nicehash.com/api?method=orders.get&my&id={0}&key={1}&location=1&algo=1".format(api, key))
- data = raw_data.json()
- #print(data)
- try:
- if not data['result']['orders']:
- print("Nessun ordine trovato!")
- return False
- else:
- print("Ordine trovato!")
- return data['result']['orders'][0]['id']
- except:
- return print("Dati non codificabili!")
- except:
- return print("Connessione assente!")
- def current_block_stats():
- t0 = time.time()
- while True:
- try:
- response = requests_retry_session().get('https://slushpool.com/stats/json/', timeout=5)
- except Exception as x:
- t1 = time.time()
- print('It failed :(', x.__class__.__name__, '- Took', t1 - t0, 'seconds')
- pass
- else:
- t2 = time.time()
- print('It works - Status Code:', response.status_code, '- Took', t2 - t0, 'seconds')
- data = response.json()
- active_workers = data["active_workers"]
- active_stratum = data["active_stratum"]
- round_started = data["round_started"]
- round_duration = data["round_duration"]
- ghashes_ps = int(eval(data["ghashes_ps"]) / 1000000000000000000000000)
- shares = data["shares"]
- score = int(eval(data["score"]) / 1000000000)
- shares_cdf = eval(data["shares_cdf"])
- luck_b10 = eval(data["luck_b10"])
- luck_b50 = eval(data["luck_b50"])
- luck_b250 = eval(data["luck_b250"])
- luck_1 = float(data["luck_1"])
- luck_7 = eval(data["luck_7"])
- luck_30 = eval(data["luck_30"])
- data = [active_workers, active_stratum, round_started, round_duration, ghashes_ps, shares, score, shares_cdf,
- luck_b10, luck_b50, luck_b250, luck_1, luck_7, luck_30]
- if data != None:
- return data
- def requests_retry_session(
- retries=3,
- backoff_factor=0.3,
- status_forcelist=(500, 502, 504, 503),
- session=None,
- ):
- session = session or requests.Session()
- retry = Retry(
- total=retries,
- read=retries,
- connect=retries,
- backoff_factor=backoff_factor,
- status_forcelist=status_forcelist,
- )
- adapter = HTTPAdapter(max_retries=retry)
- session.mount('http://', adapter)
- session.mount('https://', adapter)
- return session
- def start_orders(api, key):
- price = nicehash_best_sha256d_price()
- START_ORDER_EU = "https://www.nicehash.com/api?method=orders.create&id={0}&key={1}&location=0&algo=1&amount={2}&price={3}&limit=0.05&pool_host={4}&pool_port={5}&pool_user={6}&pool_pass={7}".format(
- api, key, amount, price, host, port, worker, password)
- START_ORDER_USA = "https://www.nicehash.com/api?method=orders.create&id={0}&key={1}&location=1&algo=1&amount={2}&price={3}&limit=0.05&pool_host={4}&pool_port={5}&pool_user={6}&pool_pass={7}".format(
- api, key, amount, price, host, port, worker, password)
- eu = requests.get(START_ORDER_EU)
- print(eu.json())
- time.sleep(5)
- usa = requests.get(START_ORDER_USA)
- print(usa.json())
- round = False
- while True:
- config = configparser.ConfigParser()
- config.read("settings.txt")
- api = config.get('Nicehash', 'api')
- key = config.get('Nicehash', 'key')
- host = config.get('Nicehash', 'host')
- port = config.get('Nicehash', 'port')
- worker = config.get('Nicehash', 'worker')
- password = config.get('Nicehash', 'password')
- amount = config.get('Nicehash', 'amount')
- min_cdf = float(config.get('Nicehash', 'min_cdf'))
- max_luck = float(config.get('Nicehash', 'max_luck'))
- while round == False: # se il round non è iniziato
- current_block_stat = current_block_stats()
- share_cdf = current_block_stat[7]
- print(share_cdf, "attendendo", min_cdf)
- luck_today = current_block_stat[8]
- print(max_luck, "attendendo", luck_today)
- if share_cdf > min_cdf and luck_today < max_luck: # se le condizioni non sono più soddisfatte
- start_orders(api, key)
- round = True
- print("ordine")
- else:
- config.read("settings.txt")
- api = config.get('Nicehash', 'api')
- key = config.get('Nicehash', 'key')
- host = config.get('Nicehash', 'host')
- port = config.get('Nicehash', 'port')
- worker = config.get('Nicehash', 'worker')
- password = config.get('Nicehash', 'password')
- amount = config.get('Nicehash', 'amount')
- min_cdf = float(config.get('Nicehash', 'min_cdf'))
- max_luck = float(config.get('Nicehash', 'max_luck'))
- print("Non è il momento di iniziare")
- if round == True: # se il round è iniziato
- config.read("settings.txt")
- api = config.get('Nicehash', 'api')
- key = config.get('Nicehash', 'key')
- host = config.get('Nicehash', 'host')
- port = config.get('Nicehash', 'port')
- worker = config.get('Nicehash', 'worker')
- password = config.get('Nicehash', 'password')
- amount = config.get('Nicehash', 'amount')
- min_cdf = float(config.get('Nicehash', 'min_cdf'))
- max_luck = float(config.get('Nicehash', 'max_luck'))
- share_cdf = current_block_stats()[7]
- print(share_cdf, min_cdf)
- luck_today = current_block_stats()[8]
- print(luck_today, max_luck)
- time.sleep(10)
- #if share_cdf < min_cdf or luck_today < max_luck: # se le condizioni non sono più soddisfatte
- print("fine")
- round = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement