Esempio n. 1
0
    def qryPosition(self, InstrumentID=''):

        self.request_id += 1

        if InstrumentID:
            req = ApiStruct.QryInvestorPosition(BrokerID=self.broker_id, InvestorID=self.investor_id,
                                                InstrumentID=InstrumentID)
        else:
            req = ApiStruct.QryInvestorPosition(BrokerID=self.broker_id, InvestorID=self.investor_id)

        self.ReqQryInvestorPosition(req, self.request_id)
Esempio n. 2
0
    def OnRspUserLogin(self, pRspUserLogin, pRspInfo, nRequestID, bIsLast):

        print('系统登录完成。user login done.')
        print datetime.datetime.now(
        ), u"登录交易服务器...", bIsLast, pRspInfo.ErrorMsg.decode('gbk')
        print datetime.datetime.now(), 'user_login:'******'交易服务器登录成功。', pRspUserLogin.BrokerID, pRspUserLogin.UserID

            # Logger.info('OnRspUserLogin %s' % is_last)
            print datetime.datetime.now(), u'请求确认结算单。'
            req = ApiStruct.SettlementInfoConfirm(BrokerID=self.broker_id,
                                                  InvestorID=self.investor_id)
            self.ReqSettlementInfoConfirm(req, self.inc_request_id())
            print datetime.datetime.now(
            ), 'SettlementInfo Confirm Requested,结算单确认申请已提交.'
            print datetime.datetime.now(), "get today's trading day:", repr(
                self.GetTradingDay())

        else:
            print('something wrong, connect failed....')
Esempio n. 3
0
    def user_login(self, broker_id, investor_id, passwd):
        req = ApiStruct.ReqUserLogin(BrokerID=broker_id,
                                     UserID=investor_id,
                                     Password=passwd)

        self.requestid += 1
        r = self.ReqUserLogin(req, self.requestid)
Esempio n. 4
0
 def fetch_instrument_marginrate(self, instrument_id):
     req = ApiStruct.QryInstrumentMarginRate(
         BrokerID=self.cuser.broker_id,
         InvestorID=self.cuser.investor_id,
         InstrumentID=instrument_id,
         HedgeFlag=ApiStruct.HF_Speculation)
     r = self.trader.ReqQryInstrumentMarginRate(req, self.inc_request_id())
     logging.info(u'A:查询保证金率, 函数发出返回值:%s' % r)
Esempio n. 5
0
 def QrySettlementInfo(self):
     """请求查询投资者结算结果"""
     req = ApiStruct.QrySettlementInfo()
     req.BrokerID = self.broker_id
     req.InvestorID = self.investor_id
     req.TradingDay = self.GetTradingDay()
     p = self.ReqQrySettlementInfo(req, self.request_id)
     print(p)
Esempio n. 6
0
 def fetch_investor_position_detail(self, instrument_id):
     '''
         获取合约的当前持仓明细,目前没用
     '''
     # logging.info(u'A:获取合约%s的当前持仓..' % (instrument_id,))
     print
     'get posi'
     req = ApiStruct.QryInvestorPositionDetail(BrokerID=self.broker_id, InvestorID=self.investor_id,
                                               InstrumentID=instrument_id)
     self.ReqQryInvestorPositionDetail(req, self.inc_request_id())
Esempio n. 7
0
    def OnRspAuthenticate(self, pRspAuthenticateField, pRspInfo, nRequestID,
                          bIsLast):
        # print(pRspAuthenticateField.AppType)

        info.append(copy.deepcopy(pRspAuthenticateField))
        print('client authenticate done. Req User login...客户端认证完成,请求用户登录.')
        time.sleep(3)
        req = ApiStruct.ReqUserLogin(BrokerID=self.broker_id,
                                     UserID=self.investor_id,
                                     Password=self.password)
        r = self.ReqUserLogin(req, self.inc_request_id())
        print(r)
Esempio n. 8
0
    def OnFrontConnected(self):
        print('Front connected....')
        req = ApiStruct.ReqAuthenticate(BrokerID=self.broker_id,
                                             UserID=self.investor_id,
                                        UserProductInfo =self.productinfo,
                                             # Password=self.password,
                                                AppID=self.appid,
                                                AuthCode=self.authcode)

        r=self.ReqAuthenticate(req, self.inc_request_id())
        print(r)
        print('Req Authenticate finished..申请客户端认证提交完成.')
        time.sleep(3)
Esempio n. 9
0
    def formatOrder(self, inst, direc, open_close, volume, price):

        orderp = ApiStruct.InputOrder(
            InstrumentID=inst,
            Direction=direc,  # ApiStruct.D_Buy or ApiStruct.D_Sell
            OrderRef=str(self.inc_request_id()),
            LimitPrice=price,
            VolumeTotalOriginal=volume,
            OrderPriceType=ApiStruct.OPT_LimitPrice,
            BrokerID=self.broker_id,
            InvestorID=self.investor_id,
            UserID=self.investor_id,
            CombOffsetFlag=open_close,  # OF_Open, OF_Close, OF_CloseToday
            CombHedgeFlag=ApiStruct.HF_Speculation,
            VolumeCondition=ApiStruct.VC_AV,
            MinVolume=1,
            ForceCloseReason=ApiStruct.FCC_NotForceClose,
            IsAutoSuspend=1,
            UserForceClose=0,
            TimeCondition=ApiStruct.TC_GFD)
        # print orderp
        return orderp
Esempio n. 10
0
 def fetch_instrument(self, instrument_id):
     req = ApiStruct.QryInstrument(InstrumentID=instrument_id, )
     time.sleep(1)
     r = self.trader.ReqQryInstrument(req, self.inc_request_id())
     logging.info(u'A:查询合约, 函数发出返回值:%s' % r)
Esempio n. 11
0
 def fetch_instrument(self, instrument_id):
     req = ApiStruct.QryInstrument(InstrumentID=instrument_id)
     # req = ApiStruct.QryInstrument()
     time.sleep(1)
     r = self.ReqQryInstrument(req, self.inc_request_id())
     print(('A:查询合约, 函数发出返回值:%s' % r))
Esempio n. 12
0
 def fetch_all_instruments(self):
     # req = ApiStruct.QryInstrument(InstrumentID=instrument_id)
     req = ApiStruct.QryInstrument()
     time.sleep(1)
     r = self.ReqQryInstrument(req, self.inc_request_id())
     print(u'A:查询合约, 函数发出返回值:%s' % r)