Beispiel #1
0
def execute(direction, current_trendExist, APIKey, Secret):
	cr = Cryptsy(APIKey, Secret)
	method = "singleorderdata"
	#orderIds= ""
	if (current_trendExist == "newTrend" and direction == "Up"):
		action = "Buy"
		btcBalance = float(cr.getInfo()['return']['balances_available']['BTC'])
		while(btcBalance > .01):
			ret = ""
			while(ret == ""):
				try:
					ret = urllib2.urlopen(urllib2.Request('http://pubapi.cryptsy.com/api.php?method=' + method + '&marketid=' + str(marketid)))
				except:
					continue

			topTrade = json.loads(ret.read())['return']['DOGE']['sellorders'][1]
			tradePrice = float(topTrade['price'])
			amount = min((btcBalance)*.99, float(topTrade['total']))
			amount = amount/tradePrice
			orderid = cr.createOrder(marketid, "Buy", amount, tradePrice)
			#orderIds = orderIds + "-" + orderid
			btcBalance = float(cr.getInfo()['return']['balances_available']['BTC'])
		pause(5)
		if (cr.myOrders(marketid)['return']!=[]):
			cr.cancelAllOrders()
			pause(10)
			print "Cancled Orders: Redoing excecute stage"
			execute(direction, current_trendExist, APIKey, Secret)
		sendText(action)

	else:
		action = "Hold"
		dogeBalance = float(cr.getInfo()['return']['balances_available']['DOGE'])
		while(dogeBalance > 3000):
			action = "Sell"
			ret = ""
			while(ret == ""):
				try:
					ret = urllib2.urlopen(urllib2.Request('http://pubapi.cryptsy.com/api.php?method=' + method + '&marketid=' + str(marketid)))
				except:
					continue

			topTrade = json.loads(ret.read())['return']['DOGE']['buyorders'][1]
			amount = min(dogeBalance*.99, float(topTrade['quantity']))
			orderid = cr.createOrder(marketid, "Sell", amount, topTrade['price'])
			#orderIds = orderIds + "-" + orderid
			dogeBalance = float(cr.getInfo()['return']['balances_available']['DOGE'])
			pause(2)
			sendText(action)
		pause(5)
		if (cr.myOrders(marketid)['return']!=[]):
			cr.cancelAllOrders()
			pause(10)
			print "Cancled Orders: Redoing excecute stage"
			execute(direction, current_trendExist, APIKey, Secret)
		

	return action #+ ": " + orderIds
Beispiel #2
0
"""
if __name__ == '__main__':
    config = Helper.Config()
    #log = Helper.Log()
    #printing = Helper.Printing()
    cryptsy = Cryptsy(config.publickey, config.privatekey)
    markets = cryptsy.getMarkets()

    """
    list = []
    for i in markets['return']:
        element = []
        element.append(int(i['marketid']))
        element.append(str(i['label']))
        list.append(element)

    final = sorted(list, key=itemgetter(0))
    for i in final:
        #print "%s" % (i[1])
        #print "self.pairs['%s'] = self.parser.getboolean('Markets', '%s')" % (i[1], i[1])
        print "%i %s" % (i[0], i[1])
    """
    info = cryptsy.getInfo()

    print info['return']['serverdatetime']
    for i in info['return']['balances_available']:
        if (float(info['return']['balances_available'][i]) > 0.0):
            print "%s balance: %s" % (i, info['return']['balances_available'][i])

    # TODO bot trading logic #
Beispiel #3
0
class Config(object):
    def __init__(self, file='settings.ini'):
        self.file = file
        self.parser = SafeConfigParser()
        self.configAll()

    # Method: configAll
    # Description: Configure and store all user settings based on settings.ini values
    def configAll(self):
        self.parser.read(self.file)

        # API keys
        self.publickey = self.parser.get('API', 'public')
        self.privatekey = self.parser.get('API', 'private')

        # Check if keys are valid        
        self.cryptsy = Cryptsy(self.publickey, self.privatekey)

        if self.cryptsy.getInfo()['success'] != '1':
            raise Exception('Cryptsy key pairs are invalid.')

        # Settings
        self.configSettings()

        # Trading
        self.configTrading()

        # Signals
        self.configSignals()
        
        # Markets
        self.configMarkets()

    # Method: configSettings
    # Description: Configure and store settings only based on settings.ini values
    def configSettings(self):
        self.parser.read(self.file)
        self.showTicker = self.parser.getboolean('Settings', 'showTicker')
        self.verbose = self.parser.getboolean('Settings', 'verbose')
        self.loopSleep = self.parser.getint('Settings', 'loopSleep')
        self.saveGraph = self.parser.getboolean('Settings', 'saveGraph')
        self.graphDPI = self.parser.getint('Settings', 'graphDPI')

    # Method: configTrading
    # Description: Configure and store trading only based on settings.ini values
    def configTrading(self):
        self.parser.read(self.file)
        self.simMode = self.parser.getboolean('Trading','simMode')
        self.min_volatility = self.parser.getfloat('Trading', 'min_volatility')
        self.volatility_sleep = self.parser.getint('Trading', 'volatility_sleep')
        self.longOn = self.parser.get('Trading','longOn')
        self.orderType = self.parser.get('Trading','orderType')
        self.fokTimeout = self.parser.getint('Trading', 'fokTimeout')
        self.fee = self.parser.getfloat('Trading', 'fee')

    # Method: configSignals
    # Description: Configure and store signals only based on settings.ini values
    def configSignals(self):
        self.parser.read(self.file)
        self.signalType = self.parser.get('Signals','signalType')
        if self.signalType == 'single':
            self.single = self.parser.get('Signals','single')
        elif self.signalType == 'dual':
            self.fast = self.parser.getint('Signals','fast')
            self.slow = self.parser.getint('Signals','slow')
        elif self.signalType == 'ribbon':
            self.ribbonStart = self.parser.get('Signals','ribbonStart')
            self.numRibbon = self.parser.get('Signals','numRibbon')
            self.ribbonSpacing = self.parser.get('Signals','ribbonSpacing')
        self.priceBand= self.parser.getboolean('Signals','priceBand')

    # Method: configMarkets
    # Description: Configure and store markets based on settings.ini values
    def configMarkets(self):
        self.parser.read(self.file)
        self.request= self.cryptsy.getMarkets()
        self.markets= {}

        # Check to see if there are new or removed markets.
        # If not, configure settings.
        self.marketsCryptsy = []
        for label in self.request['return']:
            self.marketsCryptsy.append(str(label['label']).upper())
        self.marketsSettings = [x[0].upper() for x in self.parser.items('Markets')]
        self.marketDiffC = list(set(self.marketsCryptsy) - set(self.marketsSettings))
        self.marketDiffS = list(set(self.marketsSettings) - set(self.marketsCryptsy))
        if (len(self.marketDiffC + self.marketDiffS) == 0):
            for market in self.marketsCryptsy:
                self.markets[market] = self.parser.getboolean('Markets', market)
        else:
            if (len(self.marketDiffC) > 0):
                print "ERROR: New Cryptsy market(s) found. Add %s to settings.ini." % self.marketDiffC
            if (len(self.marketDiffS) > 0):
                print "ERROR: Cryptsy market(s) removed. Remove %s from settings.ini." % self.marketDiffS
            raise Exception("Cryptsy markets sync with settings.ini markets mismatch.")
Beispiel #4
0
def execute(direction, current_trendExist, APIKey, Secret):
    cr = Cryptsy(APIKey, Secret)
    method = "singleorderdata"
    #orderIds= ""
    if (current_trendExist == "newTrend" and direction == "Up"):
        action = "Buy"
        btcBalance = float(cr.getInfo()['return']['balances_available']['BTC'])
        while (btcBalance > .01):
            ret = ""
            while (ret == ""):
                try:
                    ret = urllib2.urlopen(
                        urllib2.Request(
                            'http://pubapi.cryptsy.com/api.php?method=' +
                            method + '&marketid=' + str(marketid)))
                except:
                    continue

            topTrade = json.loads(
                ret.read())['return']['DOGE']['sellorders'][1]
            tradePrice = float(topTrade['price'])
            amount = min((btcBalance) * .99, float(topTrade['total']))
            amount = amount / tradePrice
            orderid = cr.createOrder(marketid, "Buy", amount, tradePrice)
            #orderIds = orderIds + "-" + orderid
            btcBalance = float(
                cr.getInfo()['return']['balances_available']['BTC'])
        pause(5)
        if (cr.myOrders(marketid)['return'] != []):
            cr.cancelAllOrders()
            pause(10)
            print "Cancled Orders: Redoing excecute stage"
            execute(direction, current_trendExist, APIKey, Secret)
        sendText(action)

    else:
        action = "Hold"
        dogeBalance = float(
            cr.getInfo()['return']['balances_available']['DOGE'])
        while (dogeBalance > 3000):
            action = "Sell"
            ret = ""
            while (ret == ""):
                try:
                    ret = urllib2.urlopen(
                        urllib2.Request(
                            'http://pubapi.cryptsy.com/api.php?method=' +
                            method + '&marketid=' + str(marketid)))
                except:
                    continue

            topTrade = json.loads(ret.read())['return']['DOGE']['buyorders'][1]
            amount = min(dogeBalance * .99, float(topTrade['quantity']))
            orderid = cr.createOrder(marketid, "Sell", amount,
                                     topTrade['price'])
            #orderIds = orderIds + "-" + orderid
            dogeBalance = float(
                cr.getInfo()['return']['balances_available']['DOGE'])
            pause(2)
            sendText(action)
        pause(5)
        if (cr.myOrders(marketid)['return'] != []):
            cr.cancelAllOrders()
            pause(10)
            print "Cancled Orders: Redoing excecute stage"
            execute(direction, current_trendExist, APIKey, Secret)

    return action  #+ ": " + orderIds
Beispiel #5
0
"""
if __name__ == '__main__':
    config = Helper.Config()
    #log = Helper.Log()
    #printing = Helper.Printing()
    cryptsy = Cryptsy(config.publickey, config.privatekey)
    markets = cryptsy.getMarkets()
    """
    list = []
    for i in markets['return']:
        element = []
        element.append(int(i['marketid']))
        element.append(str(i['label']))
        list.append(element)

    final = sorted(list, key=itemgetter(0))
    for i in final:
        #print "%s" % (i[1])
        #print "self.pairs['%s'] = self.parser.getboolean('Markets', '%s')" % (i[1], i[1])
        print "%i %s" % (i[0], i[1])
    """
    info = cryptsy.getInfo()

    print info['return']['serverdatetime']
    for i in info['return']['balances_available']:
        if (float(info['return']['balances_available'][i]) > 0.0):
            print "%s balance: %s" % (i,
                                      info['return']['balances_available'][i])

    # TODO bot trading logic #