def seller(share): try: ymin = min(share.get("yclose"), share.get("yopen")) ymax = max(share.get("yclose"), share.get("yopen")) price = share.get("close") if len(stores.online) == 0: raise TError('''无持仓!!!''') sellers = [] for item in stores.online: item["inday"] = item.get("inday") + 1 if share.get('ma5') <= share.get('ma10') or share.get( 'ma10') < share.get('ma20'): item["sdate"] = share.get("date") item["sprice"] = price item["isSeller"] = True item["fee"] = 10.00 item["income"] = ((item["sprice"] - item["bprice"]) * item["num"]) - item["fee"] stores.seller(item) sellers.append(item) if len(sellers) == 0: raise TError('''没有符合条件的卖出单!!!''') except TError as err: share["S"] = {"isSeller": False, "msg": err.msg} except Exception as e: share["S"] = {"isSeller": False, "msg": "Exception"} else: share["S"] = {"isSeller": True, "data": sellers} finally: logging.info("{}/n\n/n\n".format(share["S"])) return share
def summary(share): share["blance"] = stores.balance share["assets"] = stores.assets share["summary"] = (stores.assets * share.get("close")) + stores.balance share["online"] = stores.online share["money"] = money return share
def seller(share): try: if len(stores.online) == 0: raise TError('''持仓为空''') if share.get('ma10') <= share.get('ma5'): raise TError('''ma10 {:.3f}小于ma5 {:.3f}'''.format( share.get('ma10'), share.get('ma5'))) sellers = [] for item in stores.online: item["inday"] = item.get("inday") + 1 sellerPrice = item.get("bprice") * outScale if sellerPrice < share.get('high'): item["sdate"] = share.get("date") item["sprice"] = max([sellerPrice, share.get('close')]) item["isSeller"] = True item["fee"] = 10.00 stores.seller(item) sellers.append(item) if len(sellers) == 0: raise TError('''没有符合条件的卖出单''') except TError as err: share["S"] = {"isSeller": False, "msg": err.msg} else: share["S"] = {"isSeller": True, "data": sellers} finally: return share
def buy(share): try: if share.get('yma30') > share.get('ma30'): raise TError('''ma10{:.3f}大于ma5 {:.3f}'''.format( share.get('ma10'), share.get('ma5'))) ymin = min(share.get("yclose"), share.get("yopen")) ymax = max(share.get("yclose"), share.get("yopen")) price = share.get("close") if len(stores.online) > 0: raise TError('''已有持仓''') if price < ymax: raise TError('''购买价小于前一日最大值''') bcount = buyCount(price, acount) totalPrice = price * bcount if stores.balance < totalPrice: raise TError('''余额不足''') store = { "num": bcount, "bdate": share.get("date"), "bprice": price, "inday": 0 } stores.buy(store) except TError as err: share["B"] = {"isBuy": False, "msg": err.msg} except Exception as e: share["B"] = {"isBuy": False, "msg": "Exception"} else: share["B"] = {"isBuy": True, "data": store} finally: logging.info("{}/n\n".format(share["B"])) return share
def buy(share): try: if share.get('yma10') > share.get('ma10'): raise TError('30均线向下') if share.get('ma5') < share.get('ma10') or share.get( 'ma10') < share.get('ma20') or share.get('ma20') < share.get( 'ma30'): raise TError('ma5小于ma20') price = share.get("close") if len(stores.online) > 0: raise TError('''已有持仓''') bcount = buyCount(price, acount) totalPrice = price * bcount if stores.balance < totalPrice: raise TError('''余额不足!!!''') store = { "num": bcount, "bdate": share.get("date"), "bprice": price, "inday": 0 } stores.buy(store) except TError as err: share["B"] = {"isBuy": False, "msg": err.msg} except Exception as e: share["B"] = {"isBuy": False, "msg": "Exception"} else: share["B"] = {"isBuy": True, "data": store} finally: logging.info("{}/n\n".format(share["B"])) return share
def buy(share): try: if share.get('ma5') < share.get('ma10'): raise TError('''ma5{:.3f}<ma10{:.3f}'''.format( share.get('ma5'), share.get('ma10'), )) price = share.get("close") if len(stores.online) > 0: scalePrice = stores.minPrice() * inScale price = min([scalePrice, price]) if price < share.get('close'): raise TError('''买入价{:.3f}小于收盘价{:.3f}'''.format( price, share.get('close'))) bcount = buyCount(price, acount) totalPrice = price * bcount if stores.balance < totalPrice: raise TError('''余额不足!!!''') store = { "num": bcount, "bdate": share.get("date"), "bprice": price, "inday": 0 } stores.buy(store) except TError as err: share["B"] = {"isBuy": False, "msg": err.msg} except Exception as e: share["B"] = {"isBuy": False, "msg": "Exception"} else: share["B"] = {"isBuy": True, "data": store} finally: logging.info("{}/n\n".format(share["B"])) return share
def buy(share): try: # 预算买入价 # 如果没有持仓,买入价为当天收盘价 # 如果有持仓,买入价为持仓最低价*买入系数 price = share.get('close') if len(stores.online) > 0: scalePrice = stores.minPrice() * inScale price = min([scalePrice, price]) if price < share.get('close'): raise TError('''买入价{:.3f}小于收盘价{:.3f}'''.format( price, share.get('close'))) # 如果10日均线大于5日均线 不买入 if share.get('ma10') > share.get('ma5'): raise TError('''ma10{:.3f}大于ma5 {:.3f}'''.format( share.get('ma10'), share.get('ma5'))) # 计算买入数量 bcount = buyCount(price, acount) # 计算买入花费 totalPrice = price * bcount if stores.balance < totalPrice: raise TError('''余额不足''') store = { "num": bcount, "bdate": share.get("date"), "bprice": price, "inday": 0 } stores.buy(store) except TError as err: share["B"] = {"isBuy": False, "msg": err.msg} else: share["B"] = {"isBuy": True, "data": store} finally: return share