コード例 #1
0
class BotStrategy2(object):
    def __init__(self, pair):
        self.output = BotLog()
        self.prices = []
        self.closes = []
        self.trades = {}
        self.maxTradesPerPair = 10
        self.tradeByPair = 0
        self.openTrades = {}
        self.currentPrice = ""
        self.currentClose = ""
        self.accumProfit = 0
        self.closedPosCounter = 0
        self.indicator = BotIndicators(
            long_prd=26,
            short_prd=12,
            signal_long_length=9,
        )
        self.pair = pair
        self.strategyPnL = 0

    def tick(self, candlestick):
        self.currentPrice = float(candlestick.priceAverage)
        self.prices.append(self.currentPrice)
        self.evaluatePositions()

    def evaluatePositions(self):
        if len(self.prices) > 24:
            macd = self.indicator.MACD(self.prices)
            rsi = self.indicator.RSI(self.prices)
            print(macd)
            for tradePairKey, trade in self.trades.items():
                if trade.status == "OPEN":
                    self.closeTrade(macd, trade)
            for v in self.trades:
                if v == self.pair:
                    self.tradeByPair = self.tradeByPair + 1
            if (macd is not None) & (rsi != 0):
                if self.tradeByPair < self.maxTradesPerPair:
                    self.openTrade(macd, rsi)
            self.tradeByPair = 0

    def closeTrade(self, macd, trade):
        if macd == -1:
            tradeProfit = trade.close(self.currentPrice)
            self.strategyPnL += tradeProfit
            self.output.logClose("Strategy running PnL: " +
                                 str(self.strategyPnL))
            self.closedPosCounter += 1

    def openTrade(self, macd, rsi):
        if len(self.prices) > 35:
            if macd == 1:
                trade = (BotTrade(self.currentPrice, 0.1))
                self.trades[self.pair] = trade
                trade.showTrade()
コード例 #2
0
def main(argv):
    prevCrypto = []
    purchaseAmount = 0

    botLog = BotLog()
    email = EmailAlert()

    fiat = 'EUR'

    try:
        opts, args = getopt.getopt(argv, "a:t:", ["amount=", "time="])
    except getopt.GetoptError:
        print('error')
        sys.exit(2)

    for opt, arg in opts:
        if opt in ("-a", "--amount"):
            purchaseAmount = float(arg)
        if opt in ("-t", "--time"):
            sleepy = float(arg)

    while True:
        currentCrypto = getCryptoList()
        if prevCrypto:
            cryptoList = getNewCryptoAddedList(prevCrypto, currentCrypto,
                                               botLog)
            if len(cryptoList) > 0:
                buyOrder(cryptoList, purchaseAmount, fiat, botLog, email)
        prevCrypto = currentCrypto
        print(purchaseAmount)
        print(currentCrypto)
        time.sleep(sleepy)
コード例 #3
0
ファイル: botstrategy.py プロジェクト: Ricknoonan/TradingBot
 def __init__(self, pair):
     self.output = BotLog()
     self.prices = []
     self.closes = []
     self.trades = {}
     self.maxTradesPerPair = 10
     self.tradeByPair = 0
     self.openTrades = {}
     self.currentPrice = ""
     self.currentClose = ""
     self.accumProfit = 0
     self.closedPosCounter = 0
     self.indicator = BotIndicators(
         long_prd=26,
         short_prd=12,
         signal_long_length=9,
     )
     self.pair = pair
     self.MACDIndicator = False
コード例 #4
0
ファイル: botstrategy.py プロジェクト: Ricknoonan/TradingBot
class BotStrategy(object):
    def __init__(self, pair):
        self.output = BotLog()
        self.prices = []
        self.closes = []
        self.trades = {}
        self.maxTradesPerPair = 10
        self.tradeByPair = 0
        self.openTrades = {}
        self.currentPrice = ""
        self.currentClose = ""
        self.accumProfit = 0
        self.closedPosCounter = 0
        self.indicator = BotIndicators(
            long_prd=26,
            short_prd=12,
            signal_long_length=9,
        )
        self.pair = pair
        self.MACDIndicator = False

    def tick(self, candlestick):
        self.currentPrice = float(candlestick.priceAverage)
        self.prices.append(self.currentPrice)
        self.evaluatePositions()

    def evaluatePositions(self):
        priceFrame = pd.DataFrame({'price': self.prices})
        if len(priceFrame) > 24:
            macd = self.indicator.MACD(priceFrame)
            rsi = self.indicator.RSI(priceFrame)
            for tradePairKey, trade in self.trades.items():
                if trade.status == "OPEN":
                    self.closeTrade(macd, rsi, trade)
            for v in self.trades:
                if v == self.pair:
                    self.tradeByPair = self.tradeByPair + 1
            if macd is not None:
                self.setMACD(macd)
                if rsi != 0 & self.tradeByPair < self.maxTradesPerPair:
                    self.openTrade(rsi)

    def closeTrade(self, macd, rsi, trade):
        if (macd == -1) & (rsi > 60):
            trade.close(self.currentPrice)
            self.accumProfit += trade.profit
            self.closedPosCounter += 1
            self.output.logClose("Entry Price: " + str(trade.entryPrice) +
                                 " Status: " + trade.status + " Exit Price: " +
                                 str(trade.exitPrice) + " P/L: " +
                                 str(trade.profit) + "\n" + "Strategy P/L: " +
                                 str(self.accumProfit))

    def openTrade(self, rsi):
        if len(self.prices) > 35:
            if self.MACDIndicator & (rsi < 40):
                self.trades[self.pair] = (BotTrade(self.currentPrice, 0.1))

    def isMacd(self):
        self.MACDIndicator = True
        return self.MACDIndicator

    def setMACD(self, macd):
        if macd > 0:
            self.MACDIndicator = True
        if macd < 0:
            self.MACDIndicator = False