Пример #1
0
 def CalAllData(self):
     Fac = PriceLoopFactory()
     loop = Fac.GetPriceLoop()
     StockMarketValue = 0
     for dir in self.position:
         pricedata = loop.GetPriceData(dir[POS_SCo])
         if not type(pricedata) == type(0):
             if not (dir[POS_SBa]
                     == dir[POS_ABa] + dir[POS_FQu] + dir[POS_QOTW]):
                 logger.warning('股票数量不对,股票余额:%d 可用余额:%d 冻结数量%d 在途数量:%d ',
                                dir[POS_SBa], dir[POS_ABa], dir[POS_FQu],
                                dir[POS_QOTW])
                 logger.warning('程序自动更正股票余额。')
             dir[POS_SBa] = dir[POS_ABa] + dir[POS_FQu] + dir[POS_QOTW]
             dir[POS_MPr] = float(pricedata['price'])
             dir[POS_SNa] = pricedata['name']
             dir[POS_MVa] = dir[POS_MPr] * dir[POS_SBa]
             dir[POS_PLo] = dir[POS_MVa] - dir[POS_GPr] * dir[POS_SBa]
             if dir[POS_SBa] == 0 or dir[POS_GPr] == 0:
                 dir[POS_PLR] = 0
             else:
                 dir[POS_PLR] = dir[POS_PLo] / (dir[POS_GPr] *
                                                dir[POS_SBa]) * 100
             StockMarketValue = StockMarketValue + dir[POS_MVa]
     self.balance[BAL_RMV] = StockMarketValue
     self.balance[BAL_TAs] = StockMarketValue + self.balance[BAL_CBa]
Пример #2
0
 def ClearStock(self, code):  #以当前市场价清空对应的股票
     if code in self.StockCodeList:
         tempDir = {}
         for dir in self.position:
             if dir[POS_SCo] == code:
                 tempDir = dir
                 break
         Fac = PriceLoopFactory()
         loop = Fac.GetPriceLoop()
         pricedata = loop.GetPriceData(code)
         CurrentPrice = float(pricedata['price'])
         ableCount = tempDir[POS_ABa]
         if ableCount == 0:
             return False
         self.balance[BAL_AFu] = self.balance[
             BAL_AFu] + CurrentPrice * ableCount  #增加可用资金
         self.balance[BAL_CBa] = self.balance[
             BAL_CBa] + CurrentPrice * ableCount  #增加资金余额
         self.__S_ReduceStock(CurrentPrice, ableCount, code)
         self.CalAllData()
         self.RemoveEmptyStock()
         logger.info('卖出股票%s成功', code)
         self.XMLLog.TodayLog.SellOper(code, ableCount, CurrentPrice)
         return True
     else:
         inofr = self.Number + '未拥有股票:' + code + ' 无法卖出。'
         logger.info(inofr)
         return False
Пример #3
0
 def __S_CheckMarketPrice(self, price, count, stockcode):  #检查当前价格是否可以成功交易
     Fac = PriceLoopFactory()
     loop = Fac.GetPriceLoop()
     pricedata = loop.GetPriceData(stockcode)
     if not type(pricedata) == type(0):
         if price <= float(pricedata['price']):
             return True
         else:
             logger.warning('出价太高,无法以%f元卖出%s,股票当前价%s.', price, stockcode,
                            pricedata['price'])
     return False
Пример #4
0
 def __B_CheckMarketPrice(self, price, stockcode):  #当前价格是否可以买入
     PriceConditions = False
     Fac = PriceLoopFactory()
     loop = Fac.GetPriceLoop()
     pricedata = loop.GetPriceData(stockcode)
     if not type(pricedata) == type(0):
         if price >= float(pricedata['price']):
             return True
         else:
             logger.warning('出价太低,无法以%f元购入%s,股票当前价%s.', price, stockcode,
                            pricedata['price'])
     return False
Пример #5
0
def GetCDP(code):
    Fac = PriceLoopFactory()
    loop = Fac.GetPriceLoop()
    pricedata = loop.GetFrontDayData(code)
    if len(pricedata) == 0:
        return False
    high = float(pricedata['high'])
    low = float(pricedata['low'])
    close = float(pricedata['close'])
    cdp = (high + low + 2 * close) / 4
    AH = cdp + high - low
    NH = cdp * 2 - low
    NL = cdp * 2 - high
    AL = cdp + low - high
    return [AH, NH, cdp, NL, AL]