def max_amounts(self, code, price, max_qty): "https://trade.cgws.com/cgi-bin/stock/EntrustQuery?function=ajaxMaxAmount&market=0&secuid=0121056913&stkcode=300762&bsflag=B&price=16.280&rand=1551774639858" randNum = str(int(time.time())) + "".join(map(lambda x:random.choice(string.digits), range(3))) market_id = CStock.get_market(code) post_data = { "function": "ajaxMaxAmount", "market": market_id, "secuid": self.secuids[market_id], "stkcode": code, "bsflag": "B", "price": price, "rand": randNum } (ret, response) = self.session_client.post(STOCK_MONUT, post_data) if ret != 0: self.log.warn("get to url fail: ret=%d" % ret) return -5, "get order url failed" try: stock_info = response.json() return int(stock_info[0]['errorCode']), int(stock_info[0]['maxstkqty']) except: self.log.warn("stock info can not be json.") return -6, "stock info can not be json."
def deal(self, code, price, amount, action): market_id = CStock.get_market(code) up_limit = 0 down_limit = 0 secuid = self.secuids[market_id] maxBuy = 0 post_data = { "type": action, "market": market_id, "up_limit": up_limit, "down_limit": down_limit, "stktype": "0", "secuid": secuid, "stkcode": code, "stockName":"", "price": price, "fundavl": "1.00", "maxBuy": maxBuy, "amount": amount } (ret, response) = self.session_client.post(DEAL_URL, post_data) self.log.debug("%s action:%s, current price:%s, amount:%s" % (code, action, price, amount)) if ret != 0: self.log.warn("post to url fail: ret=%d" % ret) return -10 #check if has error result = response.text reg = re.compile(r'.*alert\(\"-(\d{9}).*\)') match = reg.search(result) if match: if match.group(1) == "150906130": return ct.NOT_ENOUGH_MONEY, "no enough money" elif match.group(1) == "160002006": return ct.NOT_DEAL_TIME, "[配售申购]业务,当前时间不允许委托,可委托的时间段为:091500-150000!" elif match.group(1) == "150906090": return ct.ALREADY_BUY, "already buy new stock for:%s" % code elif match.group(1) == "150906135": return ct.NOT_ENOUGH_STOCK, "no enough stocks for sell" elif match.group(1) == "999003088": return ct.SETTLEMENT_TIME, "deal forbidden" elif match.group(1) == "990297020": return ct.NOT_DEAL_TIME, "not in deal time" elif match.group(1) == "990265060": return ct.NOT_CORRECT_PRICE, "price is not right" elif match.group(1) == "150906090": return ct.REPEATED_SHENGOU, "new stock can not be duplicated delegation." elif match.group(1) == "990221020": return ct.NO_SUCH_CODE, "not such code:%s." % code else: return ct.OTHER_ERROR, "other err" else: reg = re.compile('.*alert.*新股申购数量超出.*\[(\d{3,})\]') match = reg.search(result) if match: return ct.SHENGOU_LIMIT, match.group(1) #parse the deal id. if not exist return "" reg = re.compile(r'alert.*(\d{4})') match = reg.search(result) if match: return 0, match.group(1) else: self.log.debug("reslut:%s" % result) return -5, "err happened need check."