Python Forum
CryptoCurrency Mining Auto Switch
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CryptoCurrency Mining Auto Switch
#1
Hi Guys
I'm very new to python and need help
I forked this from another project and need your expert help to optimize it.
Scripts works on nvOC mining os by fullzero : https://bitcointalk.org/index.php?topic=1854250
The code main job is to get data from whattomine.com json api and check which coin from selection is the best for mining now.
It is doing it now but what I now need is to not switch if the profit is lower than a given percent

So for examlpe if I set percent to 10 if coin A is making 100 and coin B making 105 it wont switch from A to B and stay on A untill B goes higher 110
So for this to work, I think it should check the last top coin which is logged to a file (I set it as top_coin), check and compare with new result then print to file the new coin so the bash script can read from it and switch if needed

These are the scripts

python script:
#!/usr/bin/env python2.7
#_*_ coding: utf-8 _*_
#### Whattomine auto switch python script written by papampi, forked from smartminer by damNmad

import requests;

data = requests.get("https://whattomine.com/coins.json);

coinsData = data.json()['coins'];
coins = coinsData.keys();
highBTCrev = {};

includeTags = [ 'ZEC', 'ZEN', 'ZCL', 'SIB' , 'LBC'  ]

filterdCoins = {k: v for k, v in coinsData.iteritems() if v['tag']  in includeTags}
coins = filterdCoins.keys()

def findBTCrev(d1):
    return (d1)

for coin in coins:
    coinObj = coinsData[coin]
    coinObj['smartProfitability'] = findBTCrev(coinObj['btc_revenue'])
    highBTCrev[coin] = coinObj

for k in highBTCrev:
    print highBTCrev[k]['tag'], ' - ', highBTCrev[k]['smartProfitability']

BTCrevenueSort = sorted(filterdCoins.values(), key=lambda d: d['smartProfitability'],reverse=True);

if (len(BTCrevenueSort) > 1):
    finalCoin = BTCrevenueSort[0]

log=open("top_coin", "w")
log.write(finalCoin['tag'])
log.close()
bash script:
#!/bin/bash
#### Whattomine auto switch bash script written by papampi

source ~/1bash
BITCOIN="theGROUND"

# Creating a log file to record coin switch 
LOG_FILE="/home/m1/8_wtmautoswitchlog"

if [ -e "$LOG_FILE" ] ; then
  #Limit the logfile, just keep the last 2K
  LASTLOG=$(tail -n 2K $LOG_FILE)
  echo "$LASTLOG"
  echo ""
fi

while [ $BITCOIN == "theGROUND" ]
do

CURRENT_COIN=$(head -n 150 /home/m1/1bash | grep COIN= | sed 's/COIN=//' | sed 's/\"//' | sed 's/\"//')
TOP_COIN=$(cat /home/m1/top_coin)
TIMEIN=$WTM_AUTO_SWITCH_SYNC_INTERVAL
TIMEOUT=$(($TIMEIN * 60))

python2.7 WTM_AUTO_SWITCH.py 
sleep 5
if [ "$CURRENT_COIN" != "$TOP_COIN" ]
then 
sed -i 's/'COIN=\"$CURRENT_COIN\"'/'COIN=\"$TOP_COIN\"/'' /home/m1/1bash
sleep 2
pkill -e screen
pkill -f 3main
echo ""
echo "$(date) Mining switched from $CURRENT_COIN to $TOP_COIN" | tee -a ${LOG_FILE}
echo "Check again in $TIMEOUT seconds"# | tee -a ${LOG_FILE}
sleep $TIMEOUT

else
echo "$(date) Same Coin on Top, Continue mining $CURRENT_COIN" | tee -a ${LOG_FILE}
echo "Check again in $TIMEOUT seconds" #| tee -a ${LOG_FILE}
sleep $TIMEOUT

fi
done
Reply


Messages In This Thread
CryptoCurrency Mining Auto Switch - by papampi - Oct-05-2017, 11:09 AM
RE: CryptoCurrency Mining Auto Switch - by papampi - Oct-07-2017, 09:54 AM
RE: CryptoCurrency Mining Auto Switch - by Larz60+ - Oct-07-2017, 11:51 AM
RE: CryptoCurrency Mining Auto Switch - by papampi - Oct-07-2017, 12:19 PM
RE: CryptoCurrency Mining Auto Switch - by Larz60+ - Oct-07-2017, 01:24 PM
RE: CryptoCurrency Mining Auto Switch - by papampi - Oct-07-2017, 05:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Create csv file with 4 columns for process mining thomaskissas33 3 799 Nov-06-2023, 09:36 PM
Last Post: deanhystad
  best way to use switch case? korenron 8 3,064 Aug-18-2021, 03:16 PM
Last Post: naughtyCat
  How do I do this? Switch Case? mstichler 4 2,610 Jun-05-2020, 10:27 AM
Last Post: snippsat
  Cryptocurrency Blockchain Error johnnypy76 2 3,155 Nov-10-2019, 12:03 AM
Last Post: johnnypy76
  switch limitations MuntyScruntfundle 3 2,416 Jan-27-2019, 06:11 PM
Last Post: aakashjha001

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020