Exemple #1
0
def checkStopLimit():
    
    print "DEF: checkStopLimit"
    print
    module = "checkForStopLimit"

    logTime = datetime.datetime.now()
    print
    actives = dbMod.getActives()

    for pairActive, activeType, utBought, direction, startPrice, amount, stopPrice, limitPrice in actives:
        for key, value in polTicker.iteritems():
	    pairLatest = key 
	    lastPrice = value['last']
            lastPriceFloat = float(lastPrice)
            priceLimitFloat = float(limitPrice)
            priceStopFloat = float(stopPrice)
            amountFloat = float(amount)

            if pairLatest == pairActive:
                coin = pairLatest[pairLatest.index('_') + 1:]
                totalCoin = getCoinBalance(coin)
                if amountFloat > totalCoin:
                    print "Amount from ACTIVES table is : " + str(amountFloat) + " and actual from account is: " + str(totalCoin) + " so setting amount to totalCoin"
                    amountFloat = totalCoin
		if (direction == 'BUY'):
		    if lastPriceFloat >= priceLimitFloat:
                        profit = (lastPriceFloat - float(startPrice)) * amountFloat
			print pairActive + "...We've hit our BUY LIMIT of " + str(lastPriceFloat) + " as it's above our limit of " + str(priceLimitFloat) + " - cashing out, profit = " + str(profit) + ", startPrice= " + str(startPrice)
			#sendSMS.sendMessage(pairActive + "...We've hit our BUY LIMIT of " + str(lastPriceFloat) + " as it's above our limit of " + str(priceLimitFloat) + " - cashing out, profit = " + str(profit) + ", startPrice= " + str(startPrice))
                        #broker.sellPair(pairActive, lastPriceFloat, amount)                 
		        #dbMod.insertHistory(pairActive, activeType, utBought, nowTimeEpoch, direction, startPrice, lastPrice, amount, profit) 

                        # Add trailing stop here
                        newLimit = priceLimitFloat * 1.05
                        newStop = priceStopFloat * 1.05
                        print pairActive + "... newStop: " + str(newStop) + " and newLimit: " + str(newLimit)
                        sendSMS.sendMessage("TRAILING STOP: " + pairActive + ", new Stop: " + str(newStop) + ", new Limit: " + str(newLimit))
                        priceStopFloat = newStop
                        dbMod.trailingStop(pairActive,newLimit, newStop)
		    if lastPriceFloat <= priceStopFloat:
                        profit = (lastPriceFloat - float(startPrice)) * amountFloat
			print pairActive + "...We've hit our BUY STOP of " + str(lastPriceFloat) + " as it's below our stop of " + str(priceLimitFloat) + " - exiting out, profit = " + str(profit) + ", startPrice= " + str(startPrice)
			#sendSMS.sendMessage(pairActive + "...We've hit our BUY STOP of " + str(lastPriceFloat) + " as it's below our stop of " + str(priceLimitFloat) + " - exiting out, profit = " + str(profit) + ", startPrice= " + str(startPrice))
			sendSMS.sendMessage("BUY STOP: " + pairActive + ", profit is " + str(profit))
                        broker.sellPair(pairActive, lastPriceFloat, amountFloat)                 
		        dbMod.insertHistory(pairActive, activeType, utBought, nowTimeEpoch, direction, startPrice, lastPrice, amountFloat, profit) 

		if (direction == 'SELL'):
		    if lastPriceFloat <= priceLimitFloat:
                        profit = (float(startPrice) - lastPriceFloat) * float(amount)
                        #print utBought
			print module + ": " + pairActive + "...We've hit our SELL LIMIT of " + str(lastPriceFloat) + " as it's below our limit of " + str(priceLimitFloat) + " - cashing out, profit = " + str(profit) + ", startPrice= " + str(startPrice)
                        broker.sellPair(pairActive, lastPriceFloat, amount)                 
		        dbMod.insertHistory(pairActive, activeType, utBought, nowTimeEpoch, direction, startPrice, lastPrice, amount, profit) 
		    if lastPriceFloat >= priceStopFloat:
                        profit = (float(startPrice) - lastPriceFloat) * float(amount)
			print module + ": " + pairActive + "...We've hit our SELL STOP of " + str(lastPriceFloat) + " as it's above our stop of " + str(priceLimitFloat) + " - exiting out, profit = " + str(profit) + ", startPrice= " + str(startPrice)
                        broker.sellPair(pairActive, lastPriceFloat, amount)                 
		        dbMod.insertHistory(pairActive, activeType, utBought, nowTimeEpoch, direction, startPrice, lastPrice, amount, profit) 
Exemple #2
0
def checkWallets():
    currBTCPrice = dbMod.getBTCPrice()
    if len(currBTCPrice) > 0:
        for coin, amt in wallets.iteritems():
            coinPrice = dbMod.getCoinPrice(coin)
            if len(coinPrice) != 0:
                thisCoinPrice = coinPrice[0][0]
                btcValue = thisCoinPrice * amt
                usdValue = btcValue * currBTCPrice[0][0]
                #print type(btcValue)
                #print nowTime 
                #print type(usdValue)
                dbMod.insertTotBalHist(nowTime, 'WALLET', coin, btcValue, usdValue)
    
    totalBTC = dbMod.getTotalBTC()
    decimalTotalBTC = totalBTC[0][0]
    #print type(decimalTotalBTC)
    if len(totalBTC) != 0:
        currBTCPrice = dbMod.getBTCPrice()
        #print currBTCPrice
        usdValue = decimalTotalBTC * currBTCPrice[0][0]
        print "============================================"
        print "You're total BTC holdings: " + str(decimalTotalBTC)
        print
        print "USD equivalent: " + str(usdValue)
        print "BTC/USD: " + str(currBTCPrice[0][0])
        print "============================================"
        dbMod.insertTotBalHist(nowTime, 'TOTAL', 'BTC', decimalTotalBTC, usdValue)
        message = "Total USD value: " + str(usdValue)
        sendSMS.sendMessage(message)
    else:
        print "Cannot load BTC price from DB."
Exemple #3
0
def checkBuyTriggers():

    logTime = datetime.datetime.now()
    print "DEF: checkBuyTrigger: " + str(logTime)
    print
    DIRECTION = 'BUY';
    triggers = dbMod.getBuyTriggers()
    startTime = nowTimeEpoch;

    triggerCeiling = 999999

    for pairTrigger, priceTrigger, direction, lowPrice, highPrice in triggers:
        #print "Trigger price from db: " + str(priceTrigger)
	for key, value in polTicker.iteritems():
	    pairLatest = key 
	    lastPrice = value['last']
            lastPriceFloat = float(lastPrice)
            startTimeInt = int(startTime)
            priceTriggerFloat = float(priceTrigger)
            if pairLatest == pairTrigger:
                #print "Checking trigger...lastPrice: " + str(lastPriceFloat) + " and trigger: " + str(priceTriggerFloat)
		#if lastPriceFloat >= priceTriggerFloat and lastPriceFloat < triggerCeiling:
                priceTriggerFloat = float(priceTrigger)
                lowPriceFloat = float(lowPrice)
                highPriceFloat = float(highPrice)
		stop = lowPriceFloat - (STOP_WEIGHT * lastPriceFloat)
		limit = highPriceFloat + (LIMIT_WEIGHT * lastPriceFloat)
                if pairTrigger.startswith('BTC'):
                    coin = 'BTC'
      		    btcToSpend = BTCTOSPEND
                    noOfCoinsToBuy = round(btcToSpend / lastPriceFloat)
                if pairTrigger.startswith('USDT'):
                    coin = 'USDT'
      		    usdToSpend = USDTOSPEND
                    noOfCoinsToBuy = round(usdToSpend / lastPriceFloat)
    	        totalCoin = getCoinBalance(coin)
                if lastPriceFloat > limit:
                    limit = lastPriceFloat + (LIMIT_WEIGHT * lastPriceFloat)
                    print "Setting new buy limit for " + pairTrigger + " at price " + str(limit)
		#if lastPriceFloat >= priceTriggerFloat and lastPriceFloat < triggerCeiling:
		if lastPriceFloat >= priceTriggerFloat and lastPriceFloat < limit:

    		    if ( noOfCoinsToBuy * lastPriceFloat <= totalCoin ):
    		    #if ( True ):
                        #print "Buy %d of %s at %s" % (noOfCoinsToBuy, pairLatest, priceFloat)
                        print "Buy %d of %s at %s" % (noOfCoinsToBuy, pairLatest, lastPriceFloat)
                        print "As we have enough coins: " + str(noOfCoinsToBuy * lastPriceFloat) + " is the cost, and I have " + str(totalCoin) + " of " + coin
                        sendSMS.sendMessage("BUY TRIGGER: " + pairLatest + ", at price " + str(lastPriceFloat))
                        broker.buyPair(pairTrigger, lastPriceFloat, noOfCoinsToBuy)
		        dbMod.insertActive(pairTrigger, ACTIVE_TYPE, startTimeInt, DIRECTION, lastPriceFloat, noOfCoinsToBuy, stop, limit)
    		    else:
         		print "Not enough BTC, need " + str(noOfCoinsToBuy*lastPriceFloat) + " only have " + str(totalCoin)
Exemple #4
0
def checkBTCDip(timePeriod, coinPair):
    print "DEF: checkBTCDip"
    # load last price, load price N 15 min periods ago
    lastPrice = dbMod.getLastPrice(coinPair)
    print "lastPrice = " + str(lastPrice)
    firstPrice = dbMond.getFirstPrice(coinPair)
    print "firstPrice = " + str(firstPrice)
    lowestPrice = dbMod.getLowestPrice(coinPair)
    print "lowestPrice = " + str(lowestPrice)

    if (lowestPrice / firstPrice) < 0.95:
        print "Found a DIP for " + coinPair
  	if lastPrice < firstPrice and lastPrice > (lowestPrice * 1.02):
	    print "Found a BOUNCE, buy some " + coinPair	
	    sendSMS.sendMessage("Found a BOUNCE, buy some " + coinPair)
def compareHighs():
    print("Retrieving new highs and condition details...")
    for stock in symbolList:
        relativeHigh = getRelativeHigh(stock)
        price = getLivePrice(stock)
        date = getDate(stock)
        if price > relativeHigh:
            listOfNewHighs.append(stock)
            highDifference = price - relativeHigh
            highDifference = "%.2f" % round(highDifference,2)
            print(stock, " new high detected at $", "%.2f" % round(price,2), sep="")
            print("Up by $", highDifference, sep="")
            print("Correction: ", checkCorrectionPercentage(stock, date, relativeHigh), "%", sep='')
            print(daysBetween(date, todayDate), "days since last high.")

            if stock not in alreadySentList:
                sendMessage(stock, "%.2f" % round(price,2), daysBetween(date, todayDate), checkCorrectionPercentage(stock, date, relativeHigh), highDifference)
                alreadySentList.append(stock)
Exemple #6
0
def checkEachTick():

    try:
        polTicker = polCon.returnTicker()
        tickPairKeys = polTicker.keys()
    except:
        print "Connection error"
        exit()

    for tickPair in tickPairKeys:
        if tickPair.startswith("BTC"):
            btcTickPairs.append(tickPair)

    for pairName in btcTickPairs:
        lastFourTicks = dbMod.getLastThreePeriods(pairName)
        if len(lastFourTicks) > 3:
            close3 = lastFourTicks[0][1]
            close2 = lastFourTicks[1][1]
            close1 = lastFourTicks[2][1]
            close0 = lastFourTicks[3][1]
            thisPercent = close3 / close0
            #print "Percent change for " + pairName + ": " + str(thisPercent)
            #      	    if close3/close2 > percentInc and close2/close1 > percentInc and close1/close0 > percentInc:
            #                print "%s STREAKING" % (pairName)
            #                message = pairName + " is going to the MOON!"
            #                sendSMS.sendMessage(message)
            #                broker.buyPairSpike(pairName)
            #    	    if close3/close2 < percentDec and close2/close1  < percentDec and close1/close0 < percentDec:
            #                print "%s DUMPING" % (pairName)
            #                message = pairName + " is DUMPING!"
            #                sendSMS.sendMessage(message)
            #                broker.buyPairSpike(pairName)
            if thisPercent > percentInc:
                print pairName + " STREAKING - up " + str(thisPercent)
                message = pairName + " is going to the MOON!"
                sendSMS.sendMessage(message)
                broker.buyPairSpike(pairName)
            if thisPercent < percentDec:
                print pairName + " DUMPIN - down " + str(thisPercent)
                message = pairName + " is DUMPING!"
                sendSMS.sendMessage(message)
                broker.buyPairSpike(pairName)
Exemple #7
0
def confirm(request) :
	data = request.GET
	bookdet = BookDetails()

	bookdet.doc_name = data['dname']
	bookdet.location = data['location']
	bookdet.time_slot = data['timeslot']
	bookdet.patientname = data['Pname']
	bookdet.patientphone = data['Phone']
	bookdet.date = data['date']


	#checking whether booking has already been done

	booked = 0

	docobj=BookDetails.objects.filter(doc_name = data['dname'] )
	for doc in docobj :
		if doc.location ==  data['location'] :
			if doc.date == data['date'] : 
				if doc.time_slot == data['timeslot'] :
					booked =1

	if booked == 0 :
		bookdet.save()
		phonenumber = str(data['Phone'])
		message = 'Booking Successfull\n Booking ID :' + str(bookdet.id) + '\nDoctor :'+ str(bookdet.doc_name) +'\nLocation :' + str(bookdet.location) +'\nDate: ' + str(bookdet.date) + '\nTime : ' + str(bookdet.time_slot) 
		sendMessage(message,phonenumber)
	

	
	
	context = {
		"book" : bookdet,
		"flag" : booked 
	}
	return render(request,'bookingid.html',context)