Beispiel #1
0
 def _get_baseinfo(self):
     self.s.headers.update(vs.AGENT)
     txtdata = self.s.get(vs.BASE_URL % (vs.P_TYPE['https'], vs.DOMAINS['csc'], vs.PAGES['baseInfo']))
     jsonobj = utils.get_jdata(txtdata)
     stkdata = jsonobj['data']['moneytype0']
     stkdata['fundid'] = jsonobj['fundid']
     return pd.Series(stkdata)
Beispiel #2
0
 def _get_position(self):
     self.s.headers.update(vs.AGENT)
     txtdata = self.s.get(vs.BASE_URL % (vs.P_TYPE['https'], 
                                         vs.DOMAINS['csc'], 
                                         vs.PAGES['position']))
     jsonobj = utils.get_jdata(txtdata)
     df = pd.DataFrame(jsonobj['data'], columns=vs.POSITION_COLS)
     return df
Beispiel #3
0
 def sell(self, stkcode, price=0, count=0, amount=0):
     """
 卖出证券
     params
     ---------
     stkcode:股票代码,string
     pricce:委托价格,int
     count:卖出数量
     amount:卖出金额
     """
     jsonobj = utils.get_jdata(self._trading(stkcode, price, count, 
                                             amount, 'S', 'sell'))
     res = True if jsonobj['result'] == 'true' else False
     return res
Beispiel #4
0
 def buy(self, stkcode, price=0, count=0, amount=0):
     """
 买入证券
     params
     ---------
     stkcode:股票代码,string
     pricce:委托价格,int
     count:买入数量
     amount:买入金额
     """
     jsonobj = utils.get_jdata(self._trading(stkcode, price, 
                                             count, amount, 'B', 'buy'))
     res = True if jsonobj['result'] == 'true' else False
     return res
Beispiel #5
0
 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)
         jsonobj = utils.get_jdata(result.text)  
         return jsonobj['msgMap']['ResultSucess']
     return None
Beispiel #6
0
 def deal_list(self, begin=None, end=None):
     """
 获取成交列表
     params
     -----------
     begin:开始日期  YYYYMMDD
     end:结束日期  YYYYMMDD
     
     return: DataFrame
     -----------
     ordersno:委托单号
     matchcode:成交编号
     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
Beispiel #7
0
 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
Beispiel #8
0
 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