Esempio n. 1
0
 def buy(self, price, mysell, num=0.001):
     if self.tcny > price * num:
         self.tbtc += num
         self.tcny -= price * num
         self.resCny = self.getResCny()
         self.marketTimes += 1
         self.marketBuyTimes += 1
         self.netPrices.append(price)
         self.noCny = False
         print "len self.netprices", len(self.netPrices)
         dirUtil.saveDatToFile(
             "{buy:%.2f,num:%.3f,res:%.2f,btc:%.3f,cny:%.2f,nowPrice:%.2f,times:%d,buytimes:%d,selltimes:%d}--%s\n"
             % (
                 price,
                 num,
                 self.resCny,
                 self.tbtc,
                 self.tcny,
                 self.lastMarketPrice,
                 self.marketTimes,
                 self.marketBuyTimes,
                 self.marketSellTimes,
                 str(self.netPrices),
             ),
             "netbuyselllog.txt",
         )
     else:
         # 现在资金已经不能支持币价下跌了,这时可以以现价卖出最上层的一个网络币以预防价格下跌,如果价格再下跌,则下次可以再买一个回来。
         nx = int(len(self.netPrices) * self.forceSellPecent)
         self.netPrices = self.netPrices[nx:]
         self.sell(mysell, self.baseBuySell * nx, False)
Esempio n. 2
0
 def findPriceInNetAndBuySell(self, mybuy, mysell):
     if len(self.netPrices) == 0:
         dirUtil.saveDatToFile("net self.netPrices empty\n", "netbuyselllog.txt")
         self.buy(mybuy, mysell, self.baseBuySell)
         return "none", None, None
     else:
         si = -1
         lastprice = self.netPrices[len(self.netPrices) - 1]
         if lastprice - mybuy > self.netStep:
             print lastprice, mybuy
             self.buy(lastprice - self.netStep, mysell, self.baseBuySell)  # 阶格下跌一个网络,进行买入操作
             return "buy", lastprice + self.netStep, self.baseBuySell
         elif mysell - lastprice > self.netStep:
             for i in range(len(self.netPrices)):
                 if mysell > self.netPrices[i]:
                     si = i
             num = (len(self.netPrices) - si) * self.baseBuySell
             self.sell(mysell, si, num)
             return "sell", mysell, num
Esempio n. 3
0
 def sell(self, price, n, num=0.001, selltype=True):
     if selltype:
         if n < 0:
             dirUtil.saveDatToFile("net sell erro\n", "netbuyselllog.txt")
             return
         self.tbtc -= num
         self.tcny += price * num
         self.resCny = self.getResCny()
         self.marketTimes += 1
         self.marketSellTimes += 1
         self.netPrices = self.netPrices[:n]
         self.noCny = False
         dirUtil.saveDatToFile(
             "{type:nomal,sell:%.2f,num:%.3f,res:%.2f,btc:%.3f,cny:%.2f,nowPrice:%.2f,times:%d,buytimes:%d,selltimes:%d}--%s\n"
             % (
                 price,
                 num,
                 self.resCny,
                 self.tbtc,
                 self.tcny,
                 self.lastMarketPrice,
                 self.marketTimes,
                 self.marketBuyTimes,
                 self.marketSellTimes,
                 str(self.netPrices),
             ),
             "netbuyselllog.txt",
         )
     else:
         self.tbtc -= num
         self.tcny += price * num
         self.resCny = self.getResCny()
         self.marketTimes += 1
         self.marketSellTimes += 1
         self.noCny = True
         dirUtil.saveDatToFile(
             "{type:nobuy,sell:%.2f,num:%.3f,res:%.2f,btc:%.3f,cny:%.2f,nowPrice:%.2f,times:%d,buytimes:%d,selltimes:%d}--%s\n"
             % (
                 price,
                 num,
                 self.resCny,
                 self.tbtc,
                 self.tcny,
                 self.lastMarketPrice,
                 self.marketTimes,
                 self.marketBuyTimes,
                 self.marketSellTimes,
                 str(self.netPrices),
             ),
             "netbuyselllog.txt",
         )
Esempio n. 4
0
 def savelog(self, strlog, filename="datalog.txt"):
     dirUtil.saveDatToFile(strlog, filename)
Esempio n. 5
0
#!/usr/bin/python