コード例 #1
0
    def getInfo(self, query=None):

        result = None
        if query == "trades":
            result = self.get_trades()
        elif query == "amcharts":
            result = self.get_amchart_panels()
        else:
            indicators = []
            for i in self.bot.analyzer.getIndicators():
                if i["object"]:
                    indicators.append(i["object"].format_view())

            result = {
                "bot": self.bot.info(),
                "indicators": indicators,
                "signals": self.bot.signal_history,
                "signal_history": self.bot.all_signals,
                "debug": self.bot.debug
            }

            if self.bot.backtest:
                result["backtest"] = {
                    "startprice":
                    self.bot.backtest_startprice,
                    "endprice":
                    self.bot.backtest_endprice,
                    "change":
                    "{:.2f}".format(
                        Tools.calculateGrowth(self.bot.backtest_endprice,
                                              self.bot.backtest_startprice))
                }

        return json.dumps(result)
コード例 #2
0
    def genSellOrders(self, sellorder = None):
        """find active trade to sell"""

        if not sellorder and self.tradeTick("sell"):
            return None

        upforsale = []

        if sellorder:
            if sellorder.order_type == Order.BUY and sellorder.status == Order.FILLED:
                upforsale.append(sellorder)
        else:
            activeOrders = Order.findByBot(self.bot.getName(),self.bot.getMarket(),self.exchange.getName())
            for order in activeOrders.data["results"]:
                if order.status == Order.FILLED:
                    growth = Tools.calculateGrowth( self.bot.marketRate(), order.rate )
                    if growth and growth > self.bot.growth_target:
                        upforsale.append(order)
                    else:
                        self.log.info("order rejected, doesn't meet growth target {} < {}".format(growth,self.bot.growth_target))


        self.log.info("found {} orders up for sale".format(len(upforsale)))
        orders = []
        for orderforsale in upforsale:
            #orderforsale.status = Order.UPFORSALE
            #ref = orderforsale.save()
            #print("saving orderforsale: {} {}".format(orderforsale.ref_id,ref))
            neworder = {
                    "market": self.bot.market,
                    "created_by" : self.bot.getName(),
                    "candle_time": self.bot.analyzer.last("time"),
                    "assoc_id" : orderforsale.pkey,
                    "order_type" : Order.SELL,
                    "qty": orderforsale.qty,
                    "rate": self.bot.marketRate(),
                    "upforsale": orderforsale
                    }

            self.trade_history["sell"].append({"time":time.time(),"order": neworder})
            orders += [ neworder ]

        return orders
コード例 #3
0
    def checkStops(self):
        stopped= 0
        rate = self.bot.marketRate()
        for order in self.openorders:
            if order.status == Order.FILLED:
                g = Tools.calculateGrowth( rate, order.rate)
                if g < self.bot.stop_loss:
                    self.log.info("{} stop loss triggered on {} with {} drop".format(order.market,order.ref_id,g))
                    sellorders = self.genSellOrders(order)
                    for sellorder in sellorders:
                        if sellorder:
                            self.send( Order(sellorder),force=True )
                            stopped += 1


        #if stopped > 0:
        #    self.syncOpenOrders()

        return stopped
コード例 #4
0
ファイル: order.py プロジェクト: meetri/cryptobot
    def getView(self, lastrate=None):
        ot = Order.TYPES
        os = Order.STATUS

        growth = ""
        profit = 0
        if self.order_type == Order.BUY:

            if self.status == Order.COMPLETED:
                lastrate = self.meta["sold_at"]

            if self.status == Order.FILLED or self.status == Order.COMPLETED:
                growth = "{:.02f}".format(
                    Tools.calculateGrowth(lastrate, self.rate))

                if self.status == Order.COMPLETED:
                    profit = (float(self.qty) * float(lastrate)) - (
                        float(self.qty) * float(self.rate))
                    #profit = "{:.08f}".format(profit)

        if growth:
            growth = float(growth)
        else:
            growth = 0

        res = {
            "id": self.pkey,
            "order_type": ot[self.order_type],
            "qty": "{:.08f}".format(self.qty),
            "rate": "{:.08f}".format(self.rate),
            "growth": growth,
            "profit": profit,
            "status": os[self.status],
            "time": self.created_ts,
            "candle_time": self.meta["candle_trade_time"]
        }

        if self.order_type == Order.BUY and self.status == Order.COMPLETED:
            res["sold_at"] = "{:.08f}".format(lastrate)

        return res