Ejemplo n.º 1
0
    def __call__(self, r):
        """
        Called when forming a request - generates api key headers. This call uses `expires` instead of nonce.

        This way it will not collide with other processes using the same API Key if requests arrive out of order.
        For more details, see https://www.bitmex.com/app/apiKeys
        """
        # modify and return the request
        expires = int(round(time.time()) + 5)  # 5s grace period in case of clock skew
        r.headers['api-expires'] = str(expires)
        r.headers['api-key'] = self.apiKey
        r.headers['api-signature'] = generate_signature(self.apiSecret, r.method, r.url, expires, r.body or '')

        return r
Ejemplo n.º 2
0
    def __call__(self, r):
        """
        Called when forming a request - generates api key headers. This call uses `expires` instead of nonce.

        This way it will not collide with other processes using the same API Key if requests arrive out of order.
        For more details, see https://www.bitmex.com/app/apiKeys
        """
        # modify and return the request
        expires = int(round(time.time()) + 60)  # 5s grace period in case of clock skew
        r.headers['api-expires'] = str(expires)
        r.headers['api-key'] = self.apiKey
        r.headers['api-signature'] = generate_signature(self.apiSecret, r.method, r.url, expires, r.body or '')

        return r
Ejemplo n.º 3
0
    def __get_auth(self):
        '''Return auth headers. Will use API Keys if present in settings.'''

        if self.shouldAuth is False:
            return []

        self.logger.info("Authenticating with API Key.")
        # To auth to the WS using an API key, we generate a signature of a nonce and
        # the WS API endpoint.
        nonce = generate_nonce()
        return [
            "api-nonce: " + str(nonce),
            "api-signature: " + generate_signature(settings.API_SECRET, 'GET', '/realtime', nonce, ''),
            "api-key:" + settings.API_KEY
        ]
Ejemplo n.º 4
0
    def __get_auth(self):
        '''Return auth headers. Will use API Keys if present in settings.'''

        if self.shouldAuth is False:
            return []

        self.logger.info("Authenticating with API Key.")
        # To auth to the WS using an API key, we generate a signature of a nonce and
        # the WS API endpoint.
        nonce = generate_expires()
        return [
            "api-expires: " + str(nonce),
            "api-signature: " + generate_signature(settings.API_SECRET, 'GET', '/realtime', nonce, ''),
            "api-key:" + settings.API_KEY
        ]
Ejemplo n.º 5
0
    def __get_auth(self):
        """Return auth headers. Will use API Keys if present in settings."""

        if self.shouldAuth is False:
            return []

        self.logger.info("Authenticating with API Key.")
        # To auth to the WS using an API key, we generate a signature of a nonce and
        # the WS API endpoint.
        nonce = generate_expires()
        return [
            "api-expires: " + str(nonce),
            "api-signature: " + generate_signature(settings.API_SECRET, "GET",
                                                   "/realtime", nonce, ""),
            "api-key:" + settings.API_KEY,
        ]
Ejemplo n.º 6
0
    def __get_auth(self):
        '''Return auth headers. Will use API Keys if present in settings.'''

        if self.shouldAuth is False:
            return []

        self.logger.info("Authenticating with API Key.")
        # To auth to the WS using an API key, we generate a signature of a nonce and
        # the WS API endpoint.
        self.endpoint = pickle.load(open('ws_url', 'rb'))
        self.secret = pickle.load(open('ws_secret', 'rb'))
        self.key = pickle.load(open('ws_key', 'rb'))
        nonce = generate_nonce()
        return [
            "api-nonce: " + str(nonce), "api-signature: " +
            generate_signature(self.secret, 'GET', '/realtime', nonce, ''),
            "api-key:" + self.key
        ]
Ejemplo n.º 7
0
 def __get_auth(self):
     '''Return auth headers. Will use API Keys if present in settings.'''
     if not settings.API_KEY:
         self.logger.info("Authenticating with email/password.")
         return [
             "email: " + settings.LOGIN,
             "password: "******"Authenticating with API Key.")
         # To auth to the WS using an API key, we generate a signature of a nonce and
         # the WS API endpoint.
         nonce = generate_nonce()
         return [
             "api-nonce: " + str(nonce),
             "api-signature: " + generate_signature(settings.API_SECRET, 'GET', '/realtime', nonce, ''),
             "api-key:" + settings.API_KEY
         ]
Ejemplo n.º 8
0
    def __get_auth(self):
        '''Return auth headers. Will use API Keys if present in settings.'''
        if not self.config['API_KEY'] and not self.config['LOGIN']:
            self.logger.error("No authentication provided! Unable to connect.")
            sys.exit(1)

        if not self.config['API_KEY']:
            self.logger.info("Authenticating with email/password.")
            return [
                "email: " + self.config['LOGIN'],
                "password: "******"Authenticating with API Key.")
            # To auth to the WS using an API key, we generate a signature of a nonce and
            # the WS API endpoint.
            nonce = generate_nonce()
            return [
                "api-nonce: " + str(nonce),
                "api-signature: " + generate_signature(self.config['API_SECRET'], 'GET', '/realtime', nonce, ''),
                "api-key:" + self.config['API_KEY']
            ]
Ejemplo n.º 9
0
    def __get_auth(self):
        '''Return auth headers. Will use API Keys if present in settings.'''
        if not self.config['API_KEY'] and not self.config['LOGIN']:
            self.logger.error("No authentication provided! Unable to connect.")
            sys.exit(1)

        if not self.config['API_KEY']:
            self.logger.info("Authenticating with email/password.")
            return [
                "email: " + self.config['LOGIN'],
                "password: "******"Authenticating with API Key.")
            # To auth to the WS using an API key, we generate a signature of a nonce and
            # the WS API endpoint.
            nonce = generate_nonce()
            return [
                "api-nonce: " + str(nonce),
                "api-signature: " + generate_signature(
                    self.config['API_SECRET'], 'GET', '/realtime', nonce, ''),
                "api-key:" + self.config['API_KEY']
            ]