コード例 #1
0
 def __init__(self):
     Market.__init__(self)
     self.balance = 0
     self.trades = 0
     self.profit_trades = 0
     self.buy_price = 0
     self.bag = []
     self.ticks = 0
コード例 #2
0
 def tick(self,ticker):
     Market.tick(self,ticker)
     self.ticks += 1
     for order in ticker.orders:
         if order.action == "NEW_ORDER" and order.status == ACTIVE:
             if order.operation == BUY and order.price >= ticker.price:
                 order.status = EXECUTED
                 self.balance -= ticker.price
                 self.buy_price = ticker.price
                 self.bag.append(ticker)
                 self.trades += 1
                 log.info("Buy %s: balance: %.2f", ticker, self.balance )
                 order.onexecuted()
                 order.delete()
             if order.operation == SELL and order.price <= ticker.price:
                 order.status = EXECUTED
                 self.balance += ticker.price
                 profit = ticker.price - self.buy_price
                 if profit > 0:
                     self.profit_trades +=1
                 self.bag.remove(ticker)
                 log.info("Sell %s: balance: %.2f profit: %.2f", ticker, self.balance, profit )
                 order.onexecuted()
                 order.delete()