示例#1
0
    def __init__(self, logger_name):
        ServiceBase.__init__(self, logger_name)

        # servie id used for control
        # self.sid = 'sid002'

        # SUB data
        self.deribitmsgclient = self.ctx.socket(zmq.SUB)
        self.deribitmsgclient.connect('tcp://localhost:9000')
        self.deribitmsgclient.setsockopt_string(zmq.SUBSCRIBE, '')

        self.okexmsgclient = self.ctx.socket(zmq.SUB)
        self.okexmsgclient.connect('tcp://localhost:9100')
        self.okexmsgclient.setsockopt_string(zmq.SUBSCRIBE, '')

        self.okexclient = OptionAPI('3b43d558-c6e6-4460-b8dd-1e542bc8c6c1',
                                    '90EB8F53AABAE20C67FB7E3B0EFBB318',
                                    'mogu198812', True)

        self.deribitauth = openapi_client.AuthenticationApi()
        res = self.deribitauth.public_auth_get(grant_type='client_credentials',
                                               username='',
                                               password='',
                                               client_id=deribit_apikey,
                                               client_secret=deribit_apisecret,
                                               refresh_token='',
                                               timestamp='',
                                               signature='')
        self.deribitconfig = openapi_client.Configuration()
        self.deribitconfig.access_token = res['result']['access_token']
        self.deribitconfig.refresh_token = res['result']['refresh_token']
        self.deribittradingapi = openapi_client.TradingApi(
            openapi_client.ApiClient(self.deribitconfig))
示例#2
0
 async def refresh_token(self):
     while True:
         await asyncio.sleep(800)
         res = self.deribitauth.public_auth_get(
             grant_type='refresh_token',
             username='',
             password='',
             client_id='',
             client_secret='',
             refresh_token=self.deribitconfig.refresh_token,
             timestamp='',
             signature='')
         self.deribitconfig.access_token = res['result']['access_token']
         self.deribitconfig.refresh_token = res['result']['refresh_token']
         self.deribittradingapi = openapi_client.TradingApi(
             openapi_client.ApiClient(self.deribitconfig))