def _trading(self, stkcode, price, count, amount, tradeflag, tradetype): txtdata = self.s.get( vs.TRADE_CHECK_URL % (vs.P_TYPE['https'], vs.DOMAINS['csc'], vs.PAGES['tradecheck'], tradeflag, stkcode, tradetype, utils.nowtime_str())) jsonobj = utils.get_jdata(txtdata) list = jsonobj['returnList'][0] secuid = list['buysSecuid'] fundavl = list['fundavl'] stkname = list['stkname'] if secuid is not None: if tradeflag == 'B': buytype = vs.BUY count = count if count else amount // price // 100 * 100 else: buytype = vs.SELL count = count if count else amount // price tradeparams = dict(stkname=stkname, stkcode=stkcode, secuid=secuid, buytype=buytype, bsflag=tradeflag, maxstkqty='', buycount=count, buyprice=price, _=utils.nowtime_str()) tradeResult = self.s.post( vs.TRADE_URL % (vs.P_TYPE['https'], vs.DOMAINS['csc'], vs.PAGES['trade']), params=tradeparams) return tradeResult return None
def deal_list(self, begin=None, end=None): """ 获取成交列表 params ----------- begin:开始日期 YYYYMMDD end:结束日期 YYYYMMDD return: DataFrame ----------- trddate:交易日期 matchtime:交易时间 stkcode:证券代码 stkname:证券名称 bsflagState:买卖标志 orderprice:委托价格 matchprice:成交价格 orderqty:委托数量 matchqty:成交数量 matchamt:成交金额 """ daterange = '' if (begin is None) & (end is None): selecttype = 'intraDay' else: daterange = vs.DEAL_DATE_RANGE % (begin, end) selecttype = 'all' txtdata = self.s.get(vs.DEAL_LIST_URL % (vs.P_TYPE['https'], vs.DOMAINS['csc'], vs.PAGES['deallist'], selecttype, daterange, utils.nowtime_str())) jsonobj = utils.get_jdata(txtdata) df = pd.DataFrame(jsonobj['data'], columns=vs.DEAL_LIST_COLS) return df
def entrust_list(self): txtdata = self.s.get(vs.ENTRUST_LIST_URL % (vs.P_TYPE['https'], vs.DOMAINS['csc'], vs.PAGES['entrustlist'], utils.nowtime_str())) jsonobj = utils.get_jdata(txtdata) df = pd.DataFrame(jsonobj['data'], columns=vs.ENTRUST_LIST_COLS) return df
def _trading(self, stkcode, price, count, amount, tradeflag, tradetype): txtdata = self.s.get(vs.TRADE_CHECK_URL % (vs.P_TYPE['https'], vs.DOMAINS['csc'], vs.PAGES['tradecheck'], tradeflag, stkcode, tradetype, utils.nowtime_str())) jsonobj = utils.get_jdata(txtdata) list = jsonobj['returnList'][0] secuid = list['buysSecuid'] fundavl = list['fundavl'] stkname = list['stkname'] if secuid is not None: if tradeflag == 'B': buytype = vs.BUY count = count if count else amount // price // 100 * 100 else: buytype = vs.SELL count = count if count else amount // price tradeparams = dict( stkname = stkname, stkcode = stkcode, secuid = secuid, buytype = buytype, bsflag = tradeflag, maxstkqty = '', buycount = count, buyprice = price, _ = utils.nowtime_str() ) tradeResult = self.s.post(vs.TRADE_URL % (vs.P_TYPE['https'], vs.DOMAINS['csc'], vs.PAGES['trade']), params = tradeparams) return tradeResult return None
def cancel(self, ordersno='', orderdate=''): """ 撤单 params ----------- ordersno:委托单号,多个以逗号分隔,e.g. 1866,1867 orderdata:委托日期 YYYYMMDD,多个以逗号分隔,对应委托单好 return ------------ string """ if (ordersno != '') & (orderdate != ''): params = dict(ordersno=ordersno, orderdate=orderdate, _=utils.nowtime_str()) result = self.s.post( vs.CANCEL_URL % (vs.P_TYPE['https'], vs.DOMAINS['csc'], vs.PAGES['cancel']), params=params) return result.text return None
def cancel(self, ordersno='', orderdate=''): """ 撤单 params ----------- ordersno:委托单号,多个以逗号分隔,e.g. 1866,1867 orderdata:委托日期 YYYYMMDD,多个以逗号分隔,对应委托单好 return ------------ string """ if (ordersno != '') & (orderdate != ''): params = dict( ordersno = ordersno, orderdate = orderdate, _ = utils.nowtime_str() ) result = self.s.post(vs.CANCEL_URL % (vs.P_TYPE['https'], vs.DOMAINS['csc'], vs.PAGES['cancel']), params = params) return result.text return None
def entrust_list(self): """ 获取委托单列表 return:DataFrame ---------- ordersno:委托单号 stkcode:证券代码 stkname:证券名称 bsflagState:买卖标志 orderqty:委托数量 matchqty:成交数量 orderprice:委托价格 operdate:交易日期 opertime:交易时间 orderdate:下单日期 state:状态 """ txtdata = self.s.get(vs.ENTRUST_LIST_URL % (vs.P_TYPE['https'], vs.DOMAINS['csc'], vs.PAGES['entrustlist'], utils.nowtime_str())) jsonobj = utils.get_jdata(txtdata) df = pd.DataFrame(jsonobj['data'], columns=vs.ENTRUST_LIST_COLS) return df