Exemplo n.º 1
0
    def post (self, *args, **kwargs):
        
        if self.checkToken() is not True:
            
            self.write({'success': -1})
    
            return

        data = json.loads(self.request.body.decode('utf-8'))
        
        allInfos = data['capitals']

        result = []

        for key in allInfos:

            value = allInfos[key]

            result.append({"code":key, "capital":value})

        DatabaseMgr.instance().capitals.remove({})

        DatabaseMgr.instance().capitals.insert_many(result)

        self.write({'success': 1})
Exemplo n.º 2
0
    def post (self, *args, **kwargs):
        
        if self.checkToken() is not True:
            
            self.write({'success': -1})
    
            return

        data = json.loads(self.request.body.decode('utf-8'))
        
        allblocks = data['blocks']

        result = []

        for key in allblocks:

            blockInfo = BlockInfo()

            blockInfo.createFromJson(key, allblocks[key])

            result.append(blockInfo.toJson())

        DatabaseMgr.instance().block.remove({})

        DatabaseMgr.instance().block.insert_many(result)

        self.write({'success': 1})
Exemplo n.º 3
0
    def post (self, *args, **kwargs):

        today = datetime.date.today()

        dateToday = today.strftime('%m-%d')

        datas = DatabaseMgr.instance().hotSecurities.find_one({'type':'w'})

        wWavecodeInfos = datas['codeInfos']

        datas = DatabaseMgr.instance().hotSecurities.find_one({'type':'limit'})

        reachLimits = datas['codeInfos']

        self.write({'success': 1, "data":{"w":wWavecodeInfos, 'limit':reachLimits}})
    def retriveConsultor(self, name:str, company:str) -> Consultor:

        for consultor in self.consltors:

            if consultor.name == name and consultor.company == company:

                return consultor

        consultor = Consultor(name, company, len(self.consltors))

        DatabaseMgr.instance().consultors.insert_one(consultor.toJson())

        self.consltors.append(consultor)

        return consultor
Exemplo n.º 5
0
    def post(self, *args, **kwargs):

        data = json.loads(self.request.body.decode('utf-8'))

        stockid = data['stockId']

        add = data['add']

        DatabaseMgr.instance().selfselect.remove({'stockid': stockid})

        if add == 1:

            DatabaseMgr.instance().selfselect.insert_one({'stockid': stockid})

        self.write({'success': 1})
Exemplo n.º 6
0
def loadAllBlockFromDB() -> List[BlockInfo]:

    result: List[BlockInfo] = []

    items = DatabaseMgr.instance().block.find({}, {'_id': 0})

    for item in items:

        if 'name' in item and "codeList" in item:

            name = item['name']

            codeList = item['codeList']

            if name is None or name in abortBlocks:

                continue

            blockInfo = BlockInfo()

            blockInfo.createFromJson(name, codeList)

            result.append(blockInfo)

    return result
Exemplo n.º 7
0
    def post(self, *args, **kwargs):

        if self.checkToken() is not True:

            self.write({'success': -1})

            return

        data = json.loads(self.request.body.decode('utf-8'))

        allInfos = data['codeInfos']

        DatabaseMgr.instance().stockInfos.remove({})

        DatabaseMgr.instance().stockInfos.insert_many(allInfos)

        self.write({'success': 1})
Exemplo n.º 8
0
    def checkIsSelfSelect(self, stockId:str) -> bool:

        items = DatabaseMgr.instance().selfselect.find({"stockid":stockId}, {'_id':0})

        for item in items:

            return True

        return False
Exemplo n.º 9
0
def getStockLevel(stockId:str) -> int:

    items = DatabaseMgr.instance().stockLevels.find({'id':stockId})

    for item in items:

        return item['level']

    return -1
Exemplo n.º 10
0
def getStockId(name:str):

    items = DatabaseMgr.instance().stockInfos.find({'name': name}, {'_id': 0})

    results = []

    for item in items:
        
        return item['id']

    return None
Exemplo n.º 11
0
def checkUser(name, pwd):
    
    user = DatabaseMgr.instance().users.find({'name': name})
    
    for u in user:
        
        if u['pwd'] == pwd:
            
            return True
    
    return False
Exemplo n.º 12
0
    def getIndustryStocks(self, industry:str):

        items = DatabaseMgr.instance().industry.find({'firstindustry':industry}, {'_id':0})

        stocks = None

        for item in items:

            stocks = list(item['stocks'])

        return stocks
Exemplo n.º 13
0
def refreshHotSecurities():

    items = getHotSecurities()

    today = datetime.date.today()

    dateToday = today.strftime('%m-%d')

    DatabaseMgr.instance().hotSecurities.delete_one({'date': dateToday})

    result = []

    for item in items:

        print(item.name)

        result.append(item.toJson())

    data = {'date':dateToday, 'codeInfos':result}

    DatabaseMgr.instance().hotSecurities.insert_one(data)
Exemplo n.º 14
0
def refreshReachLimitUp():

    items:List[Securities] = getReachLimitUps(count=5)

    today = datetime.date.today()

    dateToday = today.strftime('%m-%d')

    DatabaseMgr.instance().hotSecurities.delete_one({'type': 'limit'})

    result = []

    for item in items:

        print(item.codeInfo.name)

        result.append({'code':item.codeInfo.code, 'type':item.codeType})

    data = {'type': 'limit', 'codeInfos': result}

    DatabaseMgr.instance().hotSecurities.insert_one(data)
Exemplo n.º 15
0
def loadCapitalsFromDB() -> Dict:

    result: Dict = {}

    items = DatabaseMgr.instance().capitals.find({}, {'_id': 0})

    for item in items:

        capital = int(item["capital"])

        result[item["code"]] = capital

    return result
Exemplo n.º 16
0
def saveToDB():

    mypath = 'C:/Users/Administrator/Desktop/tdx-gbk/'

    f = []

    for (dirpath, dirname, filenames) in walk(mypath):

        f.extend(filenames)

    print(f)

    stocks = []

    securitiesList = []

    for file in f:

        filePath = mypath + file

        if filePath.find('.txt') == -1:

            continue

        stock = formatData(getLines(filePath))

        securitiesList.append(stock)

        stocks.append(stock.toJson())

    DatabaseMgr.instance().stocks.remove({})

    DatabaseMgr.instance().stocks.insert_many(stocks)

    result = []

    for stock in stocks:

        codeInfo = CodeInfo()

        codeInfo.code = stock['code']

        codeInfo.name = stock['name']

        result.append(codeInfo.toJson())

    DatabaseMgr.instance().stockInfos.remove({})

    DatabaseMgr.instance().stockInfos.insert_many(result)
Exemplo n.º 17
0
def loadCodeMapsFromDB() -> Dict:

    result:Dict = {}

    items = DatabaseMgr.instance().stockInfos.find({}, {'_id': 0})

    for item in items:

        codeType = int(item["type"])

        result[item["code"]] = codeType

    return result
Exemplo n.º 18
0
    def post(self):
        
        items = DatabaseMgr.instance().industry.find({}, {'_id':0})

        results = [item['firstindustry'] for item in items]

        senddata = dict()

        senddata['success'] = 1

        senddata['data'] = list(results)

        self.write(senddata)
Exemplo n.º 19
0
def loadPEMapsFromDB() -> Dict:

    result:Dict = {}

    items = DatabaseMgr.instance().stockInfos.find({}, {'_id': 0})

    for item in items:

        pe = item["pe"]

        result[item["code"]] = pe

    return result
Exemplo n.º 20
0
def refreshWWave():

    items:List[Securities] = getWWave()

    print(len(items))

    today = datetime.date.today()

    dateToday = today.strftime('%m-%d')

    DatabaseMgr.instance().hotSecurities.delete_one({'type': 'w'})

    result = []

    for item in items:

        print(item.codeInfo.name)

        result.append({'code':item.codeInfo.code, 'type':item.codeType})

    data = {'type': 'w', 'codeInfos': result}

    DatabaseMgr.instance().hotSecurities.insert_one(data)
Exemplo n.º 21
0
def fun():

    df = ts.get_stock_basics()

    d = df.loc[:, ['industry']]

    dic = defaultdict(list)

    for index, item in enumerate(d.index):

        name = d.loc[item, 'industry']

        # print(index, name)

        dic[d.loc[item, 'industry']].append(item)

    industrys = []

    for key in dic:

        arrays = list()

        print(key)

        for value in dic[key]:

            stockid = value

            arrays.append({'id': stockid})

        temp = {'firstindustry': key, 'stocks': arrays}

        industrys.append(temp)

    DatabaseMgr.instance().industry.remove({})

    DatabaseMgr.instance().industry.insert_many(industrys)
Exemplo n.º 22
0
def saveToDB():

    mypath = 'C:/Users/Administrator/Desktop/tdx-gbk'

    f = []

    for (dirpath, dirname, filenames) in walk(mypath):

        f.extend(filenames)

    print(f)

    stocks = []

    for file in f:

        filePath = mypath + file

        if filePath.find('.txt') == -1:

            continue

        stock = formatData(getLines(filePath))

        stocks.append(stock.toJson())

    DatabaseMgr.instance().stocks.remove({})

    DatabaseMgr.instance().stocks.insert_many(stocks)

    result = []

    for stock in stocks:

        unit = dict()

        unit['id'] = stock['id']

        unit['name'] = stock['name']

        result.append(unit)

    DatabaseMgr.instance().stockInfos.remove({})

    DatabaseMgr.instance().stockInfos.insert_many(result)
    def post(self, *args, **kwargs):

        results = []

        items = DatabaseMgr.instance().stocks.find({}, {'_id': 0})

        for item in items:

            if 'id' in item is False:

                continue

            stockId = item['id']

            stock = StockMgr.instance().getStock(stockId)

            if stock is None or stock.isNew():

                continue

            increase = stock.increaseTrend()

            lowvolatility = StockMgr.instance().checkIsLowVolatility(stock.id)

            if lowvolatility is not True and increase is not True:

                continue

            isselfselect = StockMgr.instance().checkIsSelfSelect(stock.id)

            stockbasic = StockMgr.instance().getStockbasic(stock.id)

            if stockbasic is None:

                continue

            results.append({
                'stock': stock.toJson(),
                'increase': increase,
                'lowvolatility': lowvolatility,
                'pe': stockbasic.pe,
                'marketcap': stockbasic.outstanding,
                'isselfselect': isselfselect
            })

        self.write({'success': 1, 'data': results})
Exemplo n.º 24
0
def loadYestodayVolums():

    dt = getPreTradeDay('2017/10/27')

    dtstr = dt.strftime('%Y/%m/%d')

    items = DatabaseMgr.instance().stockvolumof(dtstr).find({}, {'_id': 0})

    global dayvolums

    global stocklist

    for item in items:

        stockid = item['id']

        stocklist.append(stockid)

        dayvolums[stockid] = item['volume']
Exemplo n.º 25
0
def loadAllStockFromDB() -> Dict[str, Stock]:
    stocks = dict()

    items = DatabaseMgr.instance().stocks.find({}, {'_id': 0})

    for item in items:

        if 'id' in item:

            print(item['id'])

            stockId = item['id']

            stock = Stock.fromJson(item)

            stock.calcMinsAndMaxs()

            stocks[stockId] = stock

    return stocks
Exemplo n.º 26
0
def loadAllSecuritiesFromDB() -> List[Securities]:

    result: List[Securities] = []

    items = DatabaseMgr.instance().stocks.find({}, {'_id': 0})

    for item in items:

        if 'code' in item:

            code = item['code']

            if code == 0:

                continue

            securities = Securities.fromJson(item)

            securities.calcMinsAndMaxs()

            result.append(securities)

    return result
Exemplo n.º 27
0
from data.databasemgr import DatabaseMgr
from data.stock import Stock
from data.storemgr import StockMgr

items = DatabaseMgr.instance().stocks.find({'id': '002807'}, {'_id': 0})

stock = None

for item in items:

    if 'id' in item:

        # print(item['id'])

        stockId = item['id']

        stock = Stock.fromJson(item)

        break

value = stock.findHeighestValue('2017/1/1')

value0 = stock.findLowestValue(value.date)

value1 = stock.findHeighestValue(value0.date)

if value1 is not None:

    if (value1.high - value0.low) / value0.open < 0.15:

        pass
Exemplo n.º 28
0
from data.storemgr import *
from data.suggest import Suggest
from data.databasemgr import DatabaseMgr

suggests = loadSuggests()

def doS(suggest):

    suggest.date = datetime.strptime(suggest.date, '%Y/%m/%d').strftime('%Y/%m/%d')

    return suggest

items = list(map(doS, suggests))

results = set()

for item in items:

    results.add(item)

DatabaseMgr.instance().suggests.remove({})

DatabaseMgr.instance().suggests.insert_many(list(map(lambda suggest: suggest.toJson(), results)))



Exemplo n.º 29
0
    def saveToDB(self):

        items = list(map(lambda consulor: consulor.toJson(), self.consltors))

        DatabaseMgr.instance().consultors.insert_many(items)
Exemplo n.º 30
0
from data.databasemgr import DatabaseMgr
from stockmgr.consultor_manager import ConsultorManager
from data.suggest import Suggest

items = DatabaseMgr.instance().suggests.find({}, {'_id':0})

print(items)

results = []

for item in items:

    suggest = Suggest()

    consultor = ConsultorManager.instance().retriveConsultorBy(item['consultorId'])

    suggest.consultor = consultor

    suggest.consultorId = consultor.id

    suggest.stockId = item['stockId']

    suggest.stockName = item['stockName']

    suggest.date = item['date']

    results.append(suggest)

DatabaseMgr.instance().suggestscopy.insert_many(list(map(lambda suggest: suggest.toJson(), results)))