initial commit

This commit is contained in:
2014-06-12 16:27:02 -07:00
parent fe62aa5a3a
commit 1cc6099ac7
46 changed files with 702 additions and 6 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,6 @@
# editor backup files
*~
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "PyCryptsy"]
path = PyCryptsy
url = https://github.com/salfter/PyCryptsy

6
ANC.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://anc.cryptotroll.com:3338 salfter.${i} x clear ${i} 4029
done

8
ARG.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
source miners.sh
for i in $miners
do
# php switchpool.php stratum+tcp://arg.cryptopools.com:3305 salfter.${i} x clear ${i} 4029
php switchpool.php stratum+tcp://arg.minepool.net:3331 salfter.${i} x clear ${i} 4029
# php switchpool.php stratum+tcp://us-west.multipool.us:3346 s_alfter.${i} x clear ${i} 4029
done

6
AUR.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://us-west.multipool.us:3362 s_alfter.${i} x clear ${i} 4029
done

6
BTC.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners-sha256.sh
for i in $miners
do
php switchpool.php stratum+tcp://stratum.mining.eligius.st:3334 1mineSNbjsnJRzXpbW3xUsvtSUjhPRsNy_$i x clear $i 4028
done

7
BTG.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
source miners.sh
for i in $miners
do
# php switchpool.php stratum+tcp://bitgem.dyndns.org:3333 salfter.${i} x clear ${i} 4029
php switchpool.php stratum+tcp://bitgem.gotdns.org:3333 salfter.${i} x clear ${i} 4029
done

6
CAP.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://cap.cryptotroll.com:3335 salfter.${i} x clear ${i} 4029
done

6
CGB.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://us-west.multipool.us:3336 s_alfter.${i} x clear ${i} 4029
done

6
CRC.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://thebestplaza.com:3333 salfter.${i} x clear ${i} 4029
done

6
DEM.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners-sha256.sh
for i in $miners
do
php switchpool.php stratum+tcp://dem.coin-pool.org:3453 salfter.$i x clear $i 4028
done

7
DGC.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
source miners.sh
for i in $miners
do
# php switchpool.php stratum+tcp://de1.miningpool.co:9103 salfter.${i} x clear ${i} 4029
php switchpool.php stratum+tcp://us1.stratum.cryptopools.com:3333 salfter.${i} x clear ${i} 4029
done

6
DMD.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://us-west.multipool.us:3354 s_alfter.${i} x clear ${i} 4029
done

8
DOGE.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
source miners.sh
for i in $miners
do
# php switchpool.php stratum+tcp://us-west.multipool.us:3352 s_alfter.${i} x clear ${i} 4029
# php switchpool.php stratum+tcp://de2.miningpool.co:23001 salfter.${i} x clear ${i} 4029
php switchpool.php stratum+tcp://doberman.dogehouse.org:3336 salfter.${i} x clear ${i} 4029
done

6
EAC.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://eac.poolerino.com:3334 salfter.${i} x clear ${i} 4029
done

6
FRC.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners-sha256.sh
for i in $miners
do
php switchpool.php stratum+tcp://coinotron.com:3336 salfter.${i}_frc x clear $i 4028
done

6
FRK.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://frk.coin-pool.org:3334 salfter.${i} x clear ${i} 4029
done

6
FTC.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://stratum.wemineftc.com:3333 salfter.${i} x clear ${i} 4029
done

6
GDC.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://us-west.multipool.us:3356 s_alfter.${i} x clear ${i} 4029
done

6
GLC.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://de3.miningpool.co:3905 salfter.${i} x clear ${i} 4029
done

6
GLX.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://galaxy.cryptcoins.net:3329 salfter.${i} x clear ${i} 4029
done

View File

@@ -1,6 +1,4 @@
The MIT License (MIT)
Copyright (c) 2014 salfter
Copyright (c) 2014 Scott Alfter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

6
LKY.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://us-west.multipool.us:3345 s_alfter.${i} x clear ${i} 4029
done

6
LOT.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://us-west.multipool.us:3360 s_alfter.${i} x clear ${i} 4029
done

7
LTC.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
source miners.sh
for i in $miners
do
# php switchpool.php stratum+tcp://us-west.multipool.us:3334 s_alfter.${i} x clear ${i} 4029
php switchpool.php stratum+tcp://gridseed.wemineltc.com:3333 salfter.${i} x clear ${i} 4029
done

7
MEC.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
source miners.sh
for i in $miners
do
# php switchpool.php stratum+tcp://us-west.multipool.us:3348 s_alfter.${i} x clear ${i} 4029
php switchpool.php stratum+tcp://us3.miningpool.co:4202 salfter.${i} x clear ${i} 4029
done

7
MNC.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
source miners.sh
for i in $miners
do
# php switchpool.php stratum+tcp://us-west.multipool.us:3339 s_alfter.${i} x clear ${i} 4029
php switchpool.php stratum+tcp://mnc.vircurpool.com salfter.${i} x clear ${i} 4029
done

6
MOON.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://us-west.multipool.us:3358 s_alfter.${i} x clear ${i} 4029
done

7
NVC.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
source miners.sh
for i in $miners
do
# php switchpool.php stratum+tcp://us-west.multipool.us:3344 s_alfter.${i} x clear ${i} 4029
php switchpool.php stratum+tcp://stratum.khore.org:3336 salfter.${i} x clear ${i} 4029
done

6
PHS.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://phs.cryptcoins.net:3993 salfter.${i} x clear ${i} 4029
done

7
PPC.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
source miners-sha256.sh
for i in $miners
do
# php switchpool.php stratum+tcp://stratum.d7.lt:3333 salfter.$i x clear $i 4028
php switchpool.php stratum+tcp://coinotron.com:3338 salfter.${i}_ppc x clear $i 4028
done

7
PXC.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
source miners.sh
for i in $miners
do
# php switchpool.php stratum+tcp://us-west.multipool.us:3347 s_alfter.${i} x clear ${i} 4029
php switchpool.php stratum+tcp://pxc.minepool.net:3337 salfter.${i} x clear ${i} 4029
done

1
PyCryptsy Submodule

Submodule PyCryptsy added at fa7f16fcd2

View File

@@ -1,4 +1,58 @@
coinswitch
==========
coinswitch: a mining profitability switcher
===========================================
cryptocoin mining auto-switcher
CoinChoose's data has apparently gotten worse over the past few months due
to a lack of maintenance, which has made CryptoSwitcher somewhat less
useful. This package doesn't try to do all of the things that
CryptoSwitcher did, but what it does, it should do well. Its workflow is
roughly as follows:
* see what coins are tradable for BTC on Cryptsy
* check CoinWarz for profitability information (tested with scrypt coins,
but others should work)
* find the most profitable coin to mine that we'll be able to trade for BTC
* call a shell script to switch pools, if necessary
* wait and repeat
You'll need API keys for both Cryptsy and CoinWarz. CoinWarz charges for
use of its API after the first 1000 calls; checking once per hour, you
should be able to try out this script for six weeks before running out.
To set up coinswitch, copy coinswitch.conf.sample to coinswitch.conf and
edit as appropriate. For each coin, set up a script named $ABBREV.sh (such
as LTC.sh for Litecoin or DOGE.sh for Dogecoin) that will switch your miners
to the appropriate pool.
If you notice that a coin is having issues (as I wrote this, Neocoin pools
were having orphan problems), you can rename the script to something like
$ABBREV.sh.disabled; on the next round, it will be removed from
consideration. Likewise, if you add or reenable a pool, it will be
considered in the next round. Changes can be made to the configuration
while coinswitch is running; restarts shouldn't be necessary most of the
time.
By way of example, I've included the scripts I'm using for the pools that
I've currently configured. My scripts, in turn, have two dependencies.
miners.sh declares a variable with miner hostnames. switchpool.php is used
to communicate with a running cgminer or bfgminer instance (this means the
miner's RPC interface needs to be enabled for writing). Note that my
SHA-256 miners are on port 4028 and my scrypt miners are on port 4029;
you'll want to edit your scripts according to your configuration.
At each pool, you'll want to configure your payout address to send to
Cryptsy and to auto-pay after a couple hours' worth of coin has accumulated
(CoinWarz will give you an estimate of how many coins you can expect per
hour). At Cryptsy, you'll want to enable auto-trade for the coins you will
mine.
Finally, you might want to auto-withdraw your BTC proceeds from Cryptsy.
withdraw.py will check your BTC balance at Cryptsy and sweep it to a
preapproved address when it reaches the minimum you select.
If this script helps you out, tips are appreciated:
BTC: 1TipsGocnz2N5qgAm9f7JLrsMqkb3oXe2
LTC: LTipsVC7XaFy9M6Zaf1aGGe8w8xVUeWFvR
BTG: gTipsVB9qmyYHuqMMKTuCYMHpfkUFBXKrZ
(last updated 11 June 2014)

6
SXC.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://sxc.cryptominer.net:3353 salfter.${i} x clear ${i} 4029
done

6
TIPS.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://us-west.multipool.us:3357 s_alfter.${i} x clear ${i} 4029
done

6
TRC.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners-sha256.sh
for i in $miners
do
php switchpool.php stratum+tcp://trc.coin-pool.org:3340 salfter.$i x clear $i 4028
done

7
UNO.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
source miners-sha256.sh
for i in $miners
do
# php switchpool.php stratum+tcp://uno.coin-pool.org:3331 salfter.$i x clear $i
php switchpool.php stratum+tcp://de1.miningpool.co:10701 salfter.$i x clear $i 4028
done

6
WDC.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
source miners.sh
for i in $miners
do
php switchpool.php stratum+tcp://us-west.multipool.us:3342 s_alfter.${i} x clear ${i} 4029
done

7
XJO.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
source miners-sha256.sh
for i in $miners
do
# php switchpool.php stratum+tcp://xjo.coin-pool.org:3335 salfter.$i x clear $i 4028
php switchpool.php stratum+tcp://de1.miningpool.co:11001 salfter.$i x clear $i 4028
done

8
ZET.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
source miners-sha256.sh
for i in $miners
do
# php switchpool.php stratum+tcp://mine1.coinmine.pl:6000 salfter.$i x clear $i 4028
# php switchpool.php stratum+tcp://ch1.miningpool.co:7001 salfter.$i x clear $i 4028
php switchpool.php stratum+tcp://pool.dsync.net:3333 s_alfter.$i x clear $i 4028
done

38
coinswitch.conf.sample Normal file
View File

@@ -0,0 +1,38 @@
##############################################################################
[Cryptsy]
# Cryptsy API key
key=CRYPTSY_KEY_GOES_HERE
# Cryptsy API secret
secret=CRYPTSY_SECRET_GOES_HERE
# auto-withdraw BTC address (must be a preauthorized withdrawal address)
addr=BTC_ADDR_GOES_HERE
# minimum balance to auto-withdraw
minbal=0.01 ; BTC
##############################################################################
[CoinWarz]
# CoinWarz API key
apikey=COINWARZ_API_KEY_GOES_HERE
# The rest of these are parameters to the CoinWarz API's profitability call
# and are passed to it as-is:
# http://www.coinwarz.com/v1/api/documentation
# algorithm to check
algo=scrypt
# scrypt mining parameters
ScryptHashRate=6500 ; kH/s
ScryptPower=200 ; W
ScryptPowerCost=0.11 ; $/kWh
##############################################################################
[Misc]
# frequency with which we should reevaluate profitability
interval=3600 ; s

166
coinswitch.py Executable file
View File

@@ -0,0 +1,166 @@
#!/usr/bin/env python
# coinswitch: a mining profitability switcher
#
# Copyright © 2014 Scott Alfter
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import pprint
import simplejson
import os
import ConfigParser
import sys
import subprocess
import time
import StringIO
import pycurl
sys.path.insert(0, './PyCryptsy/')
from PyCryptsy import PyCryptsy
# get market info from Cryptsy
def GetMarkets(cfg):
#return simplejson.loads(open("cryptsy.json").read()) # read from file for testing
cryptsy=PyCryptsy(cfg.get("Cryptsy", "key"), cfg.get("Cryptsy", "secret"))
return cryptsy.Query("getmarkets", {})
# get profitability info from CoinWarz
def GetProfitability(cfg):
#return simplejson.loads(open("coinwarz.json").read()) # read from file for testing
b=StringIO.StringIO()
ch=pycurl.Curl()
url="http://www.coinwarz.com/v1/api/profitability/"
args=""
items=cfg.items("CoinWarz")
for i in items:
if (args!=""):
args=args+"&"
args=args+i[0]+"="+i[1]
if (args!=""):
url=url+"?"+args
ch.setopt(pycurl.URL, url)
ch.setopt(pycurl.WRITEFUNCTION, b.write)
ch.perform()
return simplejson.loads(b.getvalue())
# initialization
cfg=ConfigParser.ConfigParser()
cfg.optionxform=str
round=1
curr_coin=""
history={}
# main loop
while True:
# check for configuration changes
cfg.read("./coinswitch.conf")
files=[]
for file in os.listdir("."):
files.append(file)
# round header
print ""
print "###############"
print "# Round "+str(round).rjust(5)+" #"
print "###############"
print ""
print "Fetching updated information..."
# get updated info from Cryptsy & CoinWarz
markets=GetMarkets(cfg)
profitability=GetProfitability(cfg)
# find most profitable coin listed at Cryptsy for which we have a miner config
on_cryptsy={}
for pair in markets["return"]:
if (pair["secondary_currency_code"]=="BTC"):
on_cryptsy[pair["primary_currency_code"]]={"marketid": pair["marketid"]}
unsorted_ratios={}
for coin in profitability["Data"]:
if (coin["CoinTag"] in on_cryptsy and coin["IsBlockExplorerOnline"]==True and coin["HealthStatus"]=="Healthy"):
#unsorted_ratios[coin["CoinTag"]]=coin["AvgProfitRatio"]
unsorted_ratios[coin["CoinTag"]]=coin["ProfitRatio"]
ratios=sorted(unsorted_ratios.items(), reverse=True, key=lambda x:x[1])
available=[]
for coin in ratios:
if (coin[0]+".sh" in files):
available.append(coin)
print ""
print "Most profitable: "+ratios[0][0]+", "+str(ratios[0][1])
print "Most profitable that's configured: "+available[0][0]+", "+str(available[0][1])
# switch and update history
if (available[0][0]!=curr_coin):
curr_coin=available[0][0]
print ""
print "Switching to "+curr_coin+"..."
subprocess.call(["./"+curr_coin+".sh"])
if (curr_coin in history):
coinhist=history[curr_coin]
coinhist["profitability"]=(coinhist["rounds"]*coinhist["profitability"]+available[0][1])/(coinhist["rounds"]+1)
coinhist["rounds"]=coinhist["rounds"]+1
else:
coinhist={"rounds": 1, "profitability": available[0][1]}
history[curr_coin]=coinhist
# print history table
print ""
out="#"
for i in range(0, len(history)):
out=out+"########"
print out
out="#"
for i in history:
out=out+" "+i.ljust(5)+" # "
print out
out="#"
for i in history:
out=out+" "+str(history[i]["rounds"]).rjust(5)+" # "
print out
out="#"
for i in history:
out=out+" "+str(int(history[i]["profitability"]+0.5)).rjust(5)+" # "
print out
out="#"
for i in range(0, len(history)):
out=out+"########"
print out
round=round+1
# lather, rinse, repeat
print ""
print "Waiting "+cfg.get("Misc", "interval")+" seconds for next round..."
time.sleep(float(cfg.get("Misc", "interval")))

2
miners.sh Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
miners="miner2"

153
switchpool.php Normal file
View File

@@ -0,0 +1,153 @@
<?php
#
# Sample Socket I/O to CGMiner API
#
function getsock($addr, $port)
{
$socket = null;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false || $socket === null)
{
$error = socket_strerror(socket_last_error());
$msg = "socket create(TCP) failed";
echo "ERR: $msg '$error'\n";
return null;
}
$res = socket_connect($socket, $addr, $port);
if ($res === false)
{
$error = socket_strerror(socket_last_error());
$msg = "socket connect($addr,$port) failed";
echo "ERR: $msg '$error'\n";
socket_close($socket);
return null;
}
return $socket;
}
#
# Slow ...
function readsockline($socket)
{
$line = '';
while (true)
{
$byte = socket_read($socket, 1);
if ($byte === false || $byte === '')
break;
if ($byte === "\0")
break;
$line .= $byte;
}
return $line;
}
#
function request($host, $port, $cmd)
{
#print "request $host $port $cmd\n";
$socket = getsock($host, $port);
if ($socket != null)
{
socket_write($socket, $cmd, strlen($cmd));
$line = readsockline($socket);
socket_close($socket);
if (strlen($line) == 0)
{
echo "WARN: '$cmd' returned nothing\n";
return $line;
}
#print "$cmd returned '$line'\n";
if (substr($line,0,1) == '{')
return json_decode($line, true);
$data = array();
$objs = explode('|', $line);
foreach ($objs as $obj)
{
if (strlen($obj) > 0)
{
$items = explode(',', $obj);
$item = $items[0];
$id = explode('=', $items[0], 2);
if (count($id) == 1 or !ctype_digit($id[1]))
$name = $id[0];
else
$name = $id[0].$id[1];
if (strlen($name) == 0)
$name = 'null';
if (isset($data[$name]))
{
$num = 1;
while (isset($data[$name.$num]))
$num++;
$name .= $num;
}
$counter = 0;
foreach ($items as $item)
{
$id = explode('=', $item, 2);
if (count($id) == 2)
$data[$name][$id[0]] = $id[1];
else
$data[$name][$counter] = $id[0];
$counter++;
}
}
}
return $data;
}
return null;
}
if ($argv[5]=="")
$host="127.0.0.1";
else
$host=$argv[5];
if ($argv[6]=="")
$port=4028;
else
$port=$argv[6];
request($host, $port, "addpool|".$argv[1].",".$argv[2].",".$argv[3]);
if ($argv[4]=="clear")
{
$found=0;
while (!$found)
{
$pools=request($host, $port, "pools");
foreach ($pools as $pool)
if (array_key_exists("URL", $pool) && !$found)
if ($pool["URL"]==$argv[1] && !$found)
{
request($host, $port, "switchpool|".$pool["POOL"]);
$found=1;
}
}
sleep(2);
$pools=request($host, $port, "pools");
$found=0;
foreach ($pools as $pool)
if (array_key_exists("URL", $pool))
{
if ($pool["URL"]==$argv[1] && !$found)
$found=1;
else
$remove[$pool["POOL"]]=$pool["POOL"];
}
krsort($remove);
foreach ($remove as $poolnum)
{
request($host, $port, "disablepool|".$poolnum);
request($host, $port, "removepool|".$poolnum);
}
}
?>

46
withdraw.py Executable file
View File

@@ -0,0 +1,46 @@
#!/usr/bin/env python
# coding=iso-8859-1
# Cryptsy auto-withdraw cronjob
#
# Copyright © 2014 Scott Alfter
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import sys
sys.path.insert(0, './PyCryptsy/')
from PyCryptsy import PyCryptsy
from decimal import *
import ConfigParser
import pprint
import time
Config = ConfigParser.ConfigParser()
Config.read('./coinswitch.conf')
api=PyCryptsy(Config.get("Cryptsy", "key"), Config.get("Cryptsy", "secret"))
getcontext().prec=8
while True:
balance=Decimal(api.Query("getinfo", {})["return"]["balances_available"]["BTC"])
print "balance: "+str(balance)+" BTC"
if (balance>0.01):
print "withdrawal triggered"
pprint.pprint(api.Query("makewithdrawal", {"address": Config.get("Cryptsy", "addr"), "amount": Config.get("Cryptsy", "minbal")}))
time.sleep(float(Config.get("Misc", "interval")))