Pages:
Author

Topic: How to build your own Multipool - the Open Source Way - page 6. (Read 35459 times)

sr. member
Activity: 392
Merit: 250
Anybody going through and setting one of these bad boys up?

I'll be attempting to set one up later tomorrow. I like the open-source route and would like to help in the future development.
sr. member
Activity: 378
Merit: 254
small fry
Hashrate pie charts - this would go onto your home.html for example.


Code:

 
                               


                       

                               

                                               

                                                       

                                               

                               





Worker distribution pie charts:
Code:

 
                               

                                               

                                                       

                                               


sr. member
Activity: 378
Merit: 254
small fry
Anybody going through and setting one of these bad boys up?
legendary
Activity: 996
Merit: 1013


Been looking for a guide like this for some time already..
sr. member
Activity: 378
Merit: 254
small fry
Here's a cronjob equivalent of the payment processor.  This way it is entirely independent of the node.js application - it still logs to the redis instance and dumps any failed txns through to a text file.  I will try and clean this up some.

coming up next will be the exchange interactions as well as the front end reporting.

Code:
#!/bin/bash
cp /Scripts/payouts /Scripts/old_payouts
rm /Scripts/payouts
counter=0
                redis-cli del Pool_Stats:CurrentRoundBTCD
                redis-cli del Pool_Stats:CurrentRoundBTC
now="`date +%s`"
thisShift=`redis-cli hget Pool_Stats This_Shift`
ShiftStart=`redis-cli hget Pool_Stats:$thisShift starttime`
BTCDPrice=`redis-cli hget Exchange_Rates btcdcoin`
TotalEarned=0
TotalEarnedBTCD=0
# loop through algos
while read line
do
        AlgoTotal=0
        AlgoTotalBTCD=0
        logkey2="Pool_Stats:"$thisShift":Algos"
        logkey2BTCD="Pool_Stats:"$thisShift":AlgosBTCD"
echo "LOGKEY2: $logkey2"

        # loop through each coin for that algo
        while read CoinName
        do
                coinTotal=0
                coinTotalBTCD=0
                thiskey=$CoinName":balances"
                logkey="Pool_Stats:"$thisShift":Coins"
                logkeyBTCD="Pool_Stats:"$thisShift":CoinsBTCD"
                #Determine price for Coin
                coin2btc=`redis-cli hget Exchange_Rates $CoinName`
#               echo "$CoinName - $coin2btc"
                workersPerCoin=`redis-cli hlen $thiskey`
                if [ $workersPerCoin = 0 ]
                then
                        echo "do nothing" > /dev/null
                else

                        while read WorkerName
                        do
                                thisBalance=`redis-cli hget $thiskey $WorkerName`
                                thisEarned=`echo "scale=4;$thisBalance * $coin2btc" | bc -l`
                                coinTotal=`echo "scale=4;$coinTotal + $thisEarned" | bc -l`
                                AlgoTotal=`echo "scale=4;$AlgoTotal + $thisEarned" | bc -l`
                                BTCDEarned=`echo "scale=4;$thisEarned / $BTCDPrice" | bc -l`
                                coinTotalBTCD=`echo "scale=4;$coinTotalBTCD + $BTCDEarned" | bc -l`
                                AlgoTotalBTCD=`echo "scale=4;$AlgoTotalBTCD + $BTCDEarned" | bc -l`

#                               echo "$WorkerName earned $BTCDEarned from $CoinName"
                                redis-cli hincrbyfloat Pool_Stats:CurrentRoundBTCD $WorkerName $BTCDEarned
                                redis-cli hincrbyfloat Pool_Stats:CurrentRoundBTC $WorkerName $thisEarned
                        done< <(redis-cli hkeys $CoinName:balances)
                        redis-cli hset $logkey $CoinName $coinTotal
                        redis-cli hset $logkeyBTCD $CoinName $coinTotalBTCD
                        echo "$CoinName: $coinTotal"

                fi
        done< <(redis-cli hkeys Coin_Names_$line)
          redis-cli hset $logkey2 $line $AlgoTotal
        redis-cli hset $logkey2BTCD $line $AlgoTotalBTCD
TotalEarned=`echo "scale=4;$TotalEarned + $AlgoTotal" | bc -l`
TotalEarnedBTCD=`echo "scale=4;$TotalEarnedBTCD + $AlgoTotalBTCD" | bc -l`

done< <(redis-cli hkeys Coin_Algos)
redis-cli hset Pool_Stats:$thisShift Earned_BTC $TotalEarned
redis-cli hset Pool_Stats:$thisShift Earned_BTCD $TotalEarnedBTCD

echo "Total Earned: $TotalEarned"

redis-cli hset Pool_Stats:$thisShift endtime $now
nextShift=$(($thisShift + 1))
redis-cli hincrby Pool_Stats This_Shift 1
echo "$thisShift" >>/Scripts/Shifts
redis-cli hset Pool_Stats:$nextShift starttime $now
echo "Printing Earnings report" >> /Scripts/ShiftChangeLog.txt
echo "Shift change switching from $thisShift to $nextShift at $now" >>/Scripts/ShiftChangeErrorCheckerReport
while read WorkerName
do

        PrevBalance=`redis-cli zscore Pool_Stats:Balances $WorkerName`
        if [[ $PrevBalance == "" ]]
        then
                PrevBalance=0
        fi
        thisBalance=`redis-cli hget Pool_Stats:CurrentRoundBTCD $WorkerName`
        TotalBalance=`echo "scale=4;$PrevBalance + $thisBalance" | bc -l` >/dev/null
        echo $WorkerName $TotalBalance
#       echo "$WorkerName $TotalBalance" >> /Scripts/PayoutReport
        echo "$WorkerName $TotalBalance - was $PrevBalance plus today's $thisBalance" >> /Scripts/ShiftChangeErrorCheckerReport

        redis-cli zadd Pool_Stats:Balances $TotalBalance $WorkerName
        redis-cli hset Worker_Stats:Earnings:$WorkerName $thisShift $thisBalance
        redis-cli hincrbyfloat Worker_Stats:TotalEarned $WorkerName $thisBalance
        #Log each earning in the redis instance in the HTML format.
        #But first, mask the worker address.
                str=$WorkerName
                n=7
                hiddenWorkerName="***************"${str:${#str} - $n}


         redis-cli hincrby Pool_Stats Earning_Log_Entries 1
EarningNumber=`redis-cli hget Pool_Stats Earning_Log_Entries`
redis-cli hset Pool_Stats:EarningsLog $EarningNumber "
$thisShift
Shift Earning
$hiddenWorkerName
$thisBalance
$PrevBalance
$TotalBalance
$now
"


done< <(redis-cli hkeys Pool_Stats:CurrentRoundBTCD)
echo "Done adding coins, clearing balances now." >> /Scripts/ShiftChangeLog.log


# Save the total BTC/BTCD earned for each shift into a historical key for auditing purposes.
redis-cli rename Pool_Stats:CurrentRoundBTCD Pool_Stats:$thisShift:ShiftBTCD
redis-cli rename Pool_Stats:CurrentRoundBTC Pool_Stats:$thisShift:ShiftBTC

#for every coin on the pool....
while read Coin_Names2
do
        #Save the old balances key for every coin into a historical key.
        redis-cli rename $Coin_Names2:balances Prev:$thisShift:$Coin_Names2:balances

        # This loop will move every block from the blocksConfirmed keys into the blocksPaid keys. This means only blocksConfirmed are unpaid.
        while read PaidLine
        do
                redis-cli sadd $Coin_Names2:"blocksPaid" $PaidLine
                redis-cli srem $Coin_Names2:"blocksConfirmed" $PaidLine
                echo "nothing" > /dev/null
        done< <(redis-cli smembers $Coin_Names2:"blocksConfirmed")


done< <(redis-cli hkeys Coin_Names)

echo "Done script at $now" >> /Scripts/ShiftChangeLog.log

#Calculate workers owed in excesss of 5 BTCDcoin and generate a report of them.
while read PayoutLine
do

        amount=`redis-cli zscore Pool_Stats:Balances $PayoutLine`
        roundedamount=`echo "scale=4;$amount - 1" | bc -l`
        echo "$PayoutLine $roundedamount"
#log a file named /Scripts/pallp0pp
        echo "$PayoutLine $amount" >> /Scripts/payouts
#send all of the payments using the coin daemon
        txn=`bitcoindarkd sendtoaddress $PayoutLine $amount`
        if [ -z "$txn" ]
        then
#log failed payout to txt file.
                echo "payment failed! $PayoutLine" >>/Scripts/AlertLog
        else
                urlstring="http://btcd.explorer.ssdpool.com:9050/tx/$txn"

                 newtotal=`echo "scale=4;$amount - $roundedamount" | bc -l` >/dev/null
                redis-cli hincrby Pool_Stats Earning_Log_Entries 1
                redis-cli hset Worker_Stats:Payouts:$PayoutLine $thisShift $amount
                redis-cli hincrbyfloat Worker_Stats:TotalPaid $PayoutLine $amount
EarningNumber=`redis-cli hget Pool_Stats Earning_Log_Entries`
                str=$PayoutLine
                n=7
                hiddenPayoutLine="***************"${str:${#str} - $n}
#log in redis for displaying on website
redis-cli hset Pool_Stats:EarningsLog $EarningNumber "$thisShiftPayout$hiddenPayoutLine$amount$amounthere$now"
                redis-cli zadd Pool_Stats:Balances 0 $PayoutLine
        fi
done< <(redis-cli zrangebyscore Pool_Stats:Balances 5 inf)
#move old profitability stats
redis-cli rename Pool_Stats:CurrentShift:Profitability Pool_Stats:$thisShift:Profitability

sr. member
Activity: 280
Merit: 250
Thank you for sharing , was already working on one and this is helping me a lot
newbie
Activity: 42
Merit: 0
thank you for your sharing, waiting to read more.
sr. member
Activity: 378
Merit: 254
small fry
Haven't tried it yet but if your info is good as it looks, you'll be a hero around here.
This is all live directly off of the BTCDPool.com site.
I will be uploading a snapshot of all of the config files from that pool later tonight.
member
Activity: 109
Merit: 35
Haven't tried it yet but if your info is good as it looks, you'll be a hero around here.
sr. member
Activity: 378
Merit: 254
small fry
I'll post the next bit about the pool once the hashrate on btcdpool.com goes up a bit.
sr. member
Activity: 378
Merit: 254
small fry
Calculating Profitability

Calculating profitability can be done fairly easily like this!  This also calculates each worker's current earnings for the round, as well as updates each of the respective keys under the Pool_Stats:CurrentShift key for the coin/algo earning totals.
Set via cronjob, runs in only a few seconds on a pool even when it is getting mutli GH of scrypt/x11 traffic. You can run it manually to verify the output (it's a bit spammy, but it prints what it's doing to the screen as you do it.  If run via cronjob this would all just go to null.

Code:
#!/bin/bash
declare -A ProArr
declare -A NameArr
AlgoCounter=0
now="`date +%s`"
ShiftNumber=`redis-cli hget Pool_Stats This_Shift`
echo "Test"
startstring="Pool_Stats:"$ShiftNumber
starttime=`redis-cli hget $startstring starttime`
endtime=$now
length=$(($endtime - $starttime))
redis-cli hset Pool_Stats CurLength $length
dayslength=`echo "scale=3;$length / 86400" | bc -l`
TgtCoinPrice=`redis-cli hget Exchange_Rates `
TotalEarned=0
TotalEarnedTgtCoin=0
redis-cli hset Pool_Stats CurDaysLength $dayslength
redis-cli del Pool_Stats:CurrentShift:WorkerBTC
redis-cli del Pool_Stats:CurrentShift:WorkerTgtCoin

# START CALCULATING COIN PROFIT FOR CURRENT ROUND - THIS ALSO CALCULATES WORKER EARNINGS MID SHIFT.
# PLEASE NOTE ALL COIN NAMES IN COIN_ALGO REDIS KEY MUST MATCH KEY NAMES IN EXCHANGE_RATES KEY CASE-WISE
while read line
do
        AlgoTotal=0
        AlgoTotalTgtCoin=0
        logkey2="Pool_Stats:CurrentShift:Algos"
        logkey2TgtCoin="Pool_Stats:CurrentShift:AlgosTgtCoin"
        echo "LOGKEY2: $logkey2"
        # loop through each coin for that algo
        while read CoinName
        do
                coinTotal=0
                coinTotalTgtCoin=0
                thiskey=$CoinName":balances"
                logkey="Pool_Stats:CurrentShift:Coins"
                logkeyTgtCoin="Pool_Stats:CurrentShift:CoinsTgtCoin"
                #Determine price for Coin
                coin2btc=`redis-cli hget Exchange_Rates $CoinName`
#               echo "$CoinName - $coin2btc"
                workersPerCoin=`redis-cli hlen $thiskey`
                if [ $workersPerCoin = 0 ]
                then
                        echo "do nothing" > /dev/null
                else

                        while read WorkerName
                        do
                                thisBalance=`redis-cli hget $thiskey $WorkerName`
                                thisEarned=`echo "scale=6;$thisBalance * $coin2btc" | bc -l`
                                coinTotal=`echo "scale=6;$coinTotal + $thisEarned" | bc -l`
                                AlgoTotal=`echo "scale=6;$AlgoTotal + $thisEarned" | bc -l`
                                TgtCoinEarned=`echo "scale=6;$thisEarned / $TgtCoinPrice" | bc -l`
                                coinTotalTgtCoin=`echo "scale=6;$coinTotalTgtCoin + $TgtCoinEarned" | bc -l`
                                AlgoTotalTgtCoin=`echo "scale=6;$AlgoTotalTgtCoin + $TgtCoinEarned" | bc -l`

#                               echo "$WorkerName earned $TgtCoinEarned from $CoinName"
                                redis-cli hincrbyfloat Pool_Stats:CurrentShift:WorkerTgtCoin $WorkerName $TgtCoinEarned
                                redis-cli hincrbyfloat Pool_Stats:CurrentShift:WorkerBTC $WorkerName $thisEarned
                        done< <(redis-cli hkeys $CoinName:balances)
                        redis-cli hset $logkey $CoinName $coinTotal
                        redis-cli hset $logkeyTgtCoin $CoinName $coinTotalTgtCoin
                        echo "$CoinName: $coinTotal"

                fi
        done< <(redis-cli hkeys Coin_Names_$line)
          redis-cli hset $logkey2 $line $AlgoTotal
        redis-cli hset $logkey2TgtCoin $line $AlgoTotalTgtCoin
TotalEarned=`echo "scale=6;$TotalEarned + $AlgoTotal" | bc -l`
TotalEarnedTgtCoin=`echo "scale=6;$TotalEarnedTgtCoin + $AlgoTotalTgtCoin" | bc -l`

done< <(redis-cli hkeys Coin_Algos)


# END CALCULATING COIN PROFITS FOR CURRENT SHIFT


# START CALCULATIN AVERAGE HASHRATES SO FAR THIS SHIFT
echo "Start: $starttime End: $endtime"
        AlgoCounter=0
        while read Algo
        do
                AlgoCounter=$(($AlgoCounter + 1))
                if [ $Algo = "sha256" ]
                then
                        Algo="sha256"
                fi
                AlgoHRTotal=0
                counter=0
                loopstring="Pool_Stats:AvgHRs:"$Algo
                while read HR
                do
                        IN=$HR
                        arrIN=(${IN//:/ })
                        amt=${arrIN[0]}
                        counter=`echo "$counter + 1" | bc`
                        AlgoHRTotal=`echo "$AlgoHRTotal + $amt" | bc -l`
               done< <(redis-cli zrangebyscore $loopstring $starttime $endtime)

                if [ $Algo = "sha" ]
                then
                        Algo="sha256"
                fi
                thisalgoAVG=`echo "scale=8;$AlgoHRTotal / $counter" |  bc -l`
                string="average_"$Algo
                redis-cli hset Pool_Stats:CurrentShift $string $thisalgoAVG
                string3="Pool_Stats:CurrentShift:Algos"
                thisalgoEarned=`redis-cli hget $string3 $Algo`
                thisalgoP=`echo "scale=8;$thisalgoEarned / $thisalgoAVG / $dayslength" | bc -l`
                string2="Profitability_$Algo"
                redis-cli hset Pool_Stats:CurrentShift $string2 $thisalgoP
                if [ $Algo = "keccak" ]
                then
                        thisalgoP=`echo "scale=8;$thisalgoP * 500" | bc -l`
                elif [ $Algo = "sha256" ]
                then
                        thisalgoP=`echo "scale=8;$thisalgoP * 100" | bc -l`
                elif [ $Algo = "x11" ]
                then
                        thisalgoP=`echo "scale=8;$thisalgoP * 4" | bc -l`
                else
                        echo "done" >/dev/null
                fi
                if [ -z "$thisalgoP" ]
                then
                        thisalgoP=0
                fi

                ProArr[$AlgoCounter]=$thisalgoP
                NameArr[$AlgoCounter]=$Algo
                redis-cli hset Pool_Stats:CurrentShift $string2 $thisalgoP

                echo "For Current Shift Algo $Algo had an average of $thisalgoAVG - profitability was $thisalgoP"
        done< <(redis-cli hkeys Coin_Algos)

                profitstring=${ProArr[1]}":"${ProArr[2]}":"${ProArr[3]}":"${ProArr[4]}":"${ProArr[5]}
                stringnames=${NameArr[1]}":"${NameArr[2]}":"${NameArr[3]}":"${NameArr[4]}":"${NameArr[5]}
redis-cli hset Pool_Stats:CurrentShift:Profitability $now $profitstring
redis-cli hset Pool_Stats:CurrentShift  NameString $stringnames



Ugly, but it works.
It even gives you all the data that you require to be able to pull pretty charts of current shift profitability.
I will try and clean up the commenting and repost soon.
sr. member
Activity: 378
Merit: 254
small fry
BTW, I invite anyone intereted to check out http://www.btcdpool.com  Send some hash it's way and see how it works and if you like the feel of it.
I will be posting all of it's source in time, this thread is inspired by it.
legendary
Activity: 1610
Merit: 1000
Crackpot Idealist
Naw, feel free to post - I'm not going to waste my time putting all this up if nobody is interested.
I will be linking to a .zip with all of the files I am referring to as well, once I get all these written.


No sir, please share! I've been very curious of how MP's work and this guide so far has been great!
sr. member
Activity: 378
Merit: 254
small fry
STILL TO COME:

--> custom payment processor
---> front end javascript reporting
---> Exchange integration
---> Cryptonote integration
--> Sanity Checking
--> Future Plans
hero member
Activity: 546
Merit: 500
Im probably going to set one back-end up for my miners. Thanks for your effort!
At the moment im switching manually on my NOMP pool back-end.
sr. member
Activity: 378
Merit: 254
small fry
Naw, feel free to post - I'm not going to waste my time putting all this up if nobody is interested.
I will be linking to a .zip with all of the files I am referring to as well, once I get all these written.
sr. member
Activity: 378
Merit: 254
small fry
Let me know if anyone is even reading this far. Smiley
sr. member
Activity: 378
Merit: 254
small fry
Now let's set up a cronjob, and start grabbing a local copy of all of the coin exchange rates.
This is a simplfied version, I have a better version that aggregates prices from multiple exchanges but we all have to keep some secrets, right? Smiley I never said I'd give away how to make the most  profitable pool, but I did say i'd show you how to set up A multipool.

Code:
#!/bin/bash
BC2BTC=`curl -G 'https://api.mintpal.com/v1/market/stats/BC/BTC/' | jq -r .[].last_price`
FTC2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=5' | jq -r .return.markets.FTC.lasttradeprice`
MZC2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=164' | jq -r .return.markets.MZC.lasttradeprice`
NET2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=134' | jq -r .return.markets.NET.lasttradeprice`
DRK2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=155' | jq -r .return.markets.DRK.lasttradeprice`
WDC2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=14' | jq -r .return.markets.WDC.lasttradeprice`
STR2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=83' | jq -r .return.markets.STR.lasttradeprice`
KDC2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=178' | jq -r .return.markets.KDC.lasttradeprice`
NYAN2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=184' | jq -r .return.markets.NYAN.lasttradeprice`
MNC2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=7' | jq -r .return.markets.MNC.lasttradeprice`
POT2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=173' | jq -r .return.markets.POT.lasttradeprice`
GDC2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=82' | jq -r .return.markets.GDC.lasttradeprice`
GLC2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=76' | jq -r .return.markets.GLC.lasttradeprice`
BTE2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=49' | jq -r .return.markets.BTE.lasttradeprice`
UNO2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=133' | jq -r .return.markets.UNO.lasttradeprice`
USDE2BTC=`curl -G 'https://poloniex.com/public?command=returnTicker' | jq -r .BTC_USDE.last`
HIRO2BTC=`curl -G 'https://poloniex.com/public?command=returnTicker' | jq -r .BTC_HIRO.last`
GDN2BTC=`curl -G 'https://poloniex.com/public?command=returnTicker' | jq -r .BTC_GDN.last`
cinni2btc=`curl -G 'https://poloniex.com/public?command=returnTicker' | jq -r .BTC_CINNI.last`
NOBL2BTC=`curl -G 'https://poloniex.com/public?command=returnTicker' | jq -r .BTC_NOBL.last`
REDD2BTC=`curl -G 'https://poloniex.com/public?command=returnTicker' | jq -r .BTC_REDD.last`
LGC2BTC=`curl -G 'https://poloniex.com/public?command=returnTicker' | jq -r .BTC_LGC.last`
EAC2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=139' | jq -r .return.markets.EAC.lasttradeprice`
CAP2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=53' | jq -r .return.markets.CAP.lasttradeprice`
RBY2BTC=`curl -G 'https://bittrex.com/api/v1/public/getticker?market=BTC-RBY' | jq -r .result.Last`
tips2ltc=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=147' | jq -r .return.markets.TIPS.lasttradeprice`
ltc2btc=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=3' | jq -r .return.markets.LTC.lasttradeprice`
nxt2btc=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=159' | jq -r .return.markets.NXT.lasttradeprice`
tips2btc=`echo "$tips2ltc * $ltc2btc" | bc -l`
TRC2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=27' | jq -r .return.markets.TRC.lasttradeprice`
LOT2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=137' | jq -r .return.markets.LOT.lasttradeprice`
GLD2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=30' | jq -r .return.markets.GLD.lasttradeprice`
MEC2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=45' | jq -r .return.markets.MEC.lasttradeprice`
MYR2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=200' | jq -r .return.markets.MYR.lasttradeprice`
MEOW2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=149' | jq -r .return.markets.MEOW.lasttradeprice`
EXE2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=183' | jq -r .return.markets.EXE.lasttradeprice`
VTC2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=151' | jq -r .return.markets.VTC.lasttradeprice`
SAT2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=168' | jq -r .return.markets.SAT.lasttradeprice`
NXT2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=159' | jq -r .return.markets.NXT.lasttradeprice`
MAX2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=152' | jq -r .return.markets.MAX.lasttradeprice`
THREE2BTC=`curl -G 'https://api.mintpal.com/v1/market/stats/365/BTC/' | jq -r .[].last_price`
ZET2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=85' | jq -r .return.markets.ZET.lasttradeprice`
XC2BTC=`curl -G 'http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=210' | jq -r .return.markets.XC.lasttradeprice`

redis-cli hset Exchange_Rates blackcoin $BC2BTC
redis-cli hset Exchange_Rates globaldenomination $GDN2BTC
redis-cli hset Exchange_Rates zetacoin $ZET2BTC
redis-cli hset Exchange_Rates logicoin $LGC2BTC
redis-cli hset Exchange_Rates cinnicoin $cinni2btc
redis-cli hset Exchange_Rates 365coin $THREE2BTC
redis-cli hset Exchange_Rates NXT $NXT2BTC
redis-cli hset Exchange_Rates execoin $EXE2BTC
redis-cli hset Exchange_Rates vertcoin $VTC2BTC
redis-cli hset Exchange_Rates kittehcoin $MEOW2BTC
redis-cli hset Exchange_Rates megacoin $MEC2BTC
redis-cli hset Exchange_Rates netcoin $NET2BTC
redis-cli hset Exchange_Rates globalcoin $GLC2BTC
redis-cli hset Exchange_Rates grandcoin $GDC2BTC
redis-cli hset Exchange_Rates goldcoin $GLD2BTC
redis-cli hset Exchange_Rates fedoracoin $tips2btc
redis-cli hset Exchange_Rates litecoin $ltc2btc
redis-cli hset Exchange_Rates nxt $NXT2BTC
redis-cli hset Exchange_Rates terracoin $TRC2BTC
redis-cli hset Exchange_Rates feathercoin $FTC2BTC
redis-cli hset Exchange_Rates reddcoin $REDD2BTC
redis-cli hset Exchange_Rates earthcoin $EAC2BTC
redis-cli hset Exchange_Rates bottlecaps $CAP2BTC
redis-cli hset Exchange_Rates rubycoin $RBY2BTC
redis-cli hset Exchange_Rates terracoin $TRC2BTC
redis-cli hset Exchange_Rates noblecoin $NOBL2BTC
redis-cli hset Exchange_Rates mincoin $MNC2BTC
redis-cli hset Exchange_Rates klondikecoin $KDC2BTC
redis-cli hset Exchange_Rates darkcoin $DRK2BTC
redis-cli hset Exchange_Rates mazacoin $MZC2BTC
redis-cli hset Exchange_Rates unobtanium $UNO2BTC
redis-cli hset Exchange_Rates hirocoin $HIRO2BTC
redis-cli hset Exchange_Rates cinnicoin $cinni2btc
redis-cli hset Exchange_Rates usde $USDE2BTC
redis-cli hset Exchange_Rates lottocoin $LOT2BTC
redis-cli hset Exchange_Rates nyancoin $NYAN2BTC
redis-cli hset Exchange_Rates worldcoin $WDC2BTC
redis-cli hset Exchange_Rates potcoin $POT2BTC
redis-cli hset Exchange_Rates myriadcoin $MYR2BTC
redis-cli hset Exchange_Rates myriad-scrypt $MYR2BTC
redis-cli hset Exchange_Rates myriadsha $MYR2BTC
redis-cli hset Exchange_Rates saturncoin $SAT2BTC
redis-cli hset Exchange_Rates maxcoin $MAX2BTC
redis-cli hset Exchange_Rates rubycoin $RBY2BTC
redis-cli hset Exchange_Rates xccoin $XC2BTC

Get this cronjob to run every 5 minutes, this will keep track of the most current exchange prices.  (the final step will be syncing all the cronjobs into a single script, but we'll get to that still in a few posts. Next up is re-writing the payment processor to properly handle the start and end of 'shifts' as well as to handle the coin moving to the exchange.

sr. member
Activity: 378
Merit: 254
small fry
Set up a cronjob to run every 10 minutes.
Have it run a bash file, and this is the bash file:
Code:
#!/bin/bash
workercounter=0
arraycounter=0
now="`date +%s`"
TenMins=$((now - 600))
interval=600
modifier=65536
SHAmodifier=4294967296
redis-cli del tmpkey

while read Algo
do
        TotalWorkers=0
        WorkerTotals=0
        unset arrWorkerTotals
        unset arrWorkerCounts
        unset arrWorkerNames
        typeset -A arrWorkerTotals
        typeset -A arrWorkerCounts
        typeset -A arrWorkerNames
        AlgoCounter=0
        workercounter=0
        redis-cli del tmpkey
        while read CoinType
        do
                echo "$CoinType"

                counter=0
                CoinKeyName=$CoinType":hashrate"
                totalhashes=`redis-cli zcard $CoinKeyName`
        if [ -z "$totalhashes" ]
        then
                echo "no hashes" >/dev/null
        else
                while read LineItem
                do
#                       echo "$LineItem"
        counter=$(($counter + 1))
                        AlgoCounter=$(($AlgoCounter + 1))
                        IN=$LineItem
            arrIN=(${IN//:/ })
            preworker=(${arrIN[1]})
            #strip HTML tags out to ensure safe displaying later
            workername=`echo "$preworker," | tr -d '<>,'`
                        echo "$workername"
                        if [[ $workername == "" ]]
                        then
                                echo "ignore worker"
                        else
                               share=(${arrIN[0]})
                                arrWorkerCounts[$workername]=$((${arrWorkerCounts[$workername]} + 1))
if [[ ${arrWorkerCounts[$workername]} -eq 1 ]]
                                  then
                                #must have been this workers first share, so thi                                                                                                             s is a new worker
                                TotalWorkers=$(($TotalWorkers + 1))
                workercounter=$(($workercounter + 1))
                        arrWorkerNames[$workercounter]=$workername
                                echo "TotalWorkers - $TotalWorkers ~~~ workercounter - $workercounter ~~~ arrWorkerNames -" ${arrWorkerNames[$workercounter]}
                                  else
                                        #this was a duplicate worker, do nothing
                                        echo " " >/dev/null
                                fi
                        if [ -z "${arrWorkerTotals[$workername]}" ]
                        then
                                tempvar=0
                        else
                                tempvar=${arrWorkerTotals[$workername]}
                        fi


                         arrWorkerTotals[$workername]=`echo "scale=6;$tempvar + $share" | bc -l`

                        echo "${arrWorkerNames[$workercounter]}"



            fi
                        done< <(redis-cli zrangebyscore $CoinKeyName $TenMins $now)

                        TotalHash=`echo "$TotalHash + $share" | bc -l`
fi
                done< <(redis-cli hkeys Coin_Names_$Algo)


                  # break it down - sha is stored a GH, everything else is stored a MH
                                if [ $Algo = "sha256" ]
                                then
                                        modifier=4294967296
                                        divisor=1073741824
                                elif [ $Algo = "keccak" ]
                                then
                                        modifier=16777216
                                        divisor=1048576
                                elif [ $Algo = "x11" ]
                                then
                                        modifier=4294967296
                                        divisor=1048576
                                else
                                        modifier=65536
                                        divisor=1048576
                                fi

                                TotalHR=`echo "scale=3;$TotalHash * $modifier / $interval / $divisor" | bc`
                redis-cli zadd Pool_Stats:avgHR:$Algo $now $TotalHR":"$now
                #go over the array of WorkerNames and calculate each workers HR
                                counterB=0
                while [[ $counterB -lt $workercounter ]]
                do
                        counterB=$(($counterB + 1))
                        workerName=${arrWorkerNames[$counterB]}
                        echo $workerName
                        temporary=`echo "scale=6;${arrWorkerTotals[$workerName]} * $modifier" | bc -l`
                                        #               number=`echo "$interval / $divisor" | bc -l`
                          arrWorkerHashRates[$counterB]=`echo "$temporary / $interval / $divisor" | bc -l`
                                                workerName=${arrWorkerNames[$counterB]}
                                                rate=${arrWorkerHashRates[$counterB]}
                                                echo $workerName $rate
                                                string=$rate":"$now
                                                redis-cli zadd Pool_Stats:WorkerHRs:$Algo:$workerName $now $string
                                                echo "$Algo - $workerName -"$arrWorkerHashRates[$counterB]}
                done


done< <(redis-cli hkeys Coin_Algos)

Go ahead and run it a few times at the command line and see how it works - it's a bit spammy, but notice how the redis keys are being populated with all of the users hashrate information now?  The line near the top can be adjuted from 600 to a lower number if you would rather users not have to wait 10 min to see an accurate hash rate.  Make sure you have your Coin_Algos and Coin_Names_ redis values filled in appropriately for this to work.
sr. member
Activity: 378
Merit: 254
small fry
These are probably noob questions, but here goes anyways.

How much machine would this require (RAM, storage)?

What is the minimum hashrate you would recommend for before setting up your own Multipool?
SSD backing is important, but you can run a MP easily on a machine with 4 GB of ram and 40 GB of disk space.
Pages:
Jump to: