<commit_before># encoding: UTF-8
import hashlib
import urllib


########################################################################
from vnpy.api.rest import RestClient, Request


########################################################################
class OkexFutureRestBase(RestClient):
    
    #----------------------------------------------------------------------
    def __init__(self):
        super(OkexFutureRestBase, self).__init__()
        self.apiKey = None
        self.apiSecret = None
    
    #----------------------------------------------------------------------
    # noinspection PyMethodOverriding
    def init(self, apiKey, apiSecret):
        # type: (str, str) -> any
        super(OkexFutureRestBase, self).init('https://www.okex.com/api/v1')
        self.apiKey = apiKey
        self.apiSecret = apiSecret

#----------------------------------------------------------------------
    def beforeRequest(self, req):  # type: (Request)->Request
        args = req.params or {}
        args.update(req.data or {})
        if 'sign' in args:
            args.pop('sign')
        if 'apiKey' not in args:
            args['api_key'] = self.apiKey
        data = urllib.urlencode(sorted(args.items()))
        data += "&secret_key=" + self.apiSecret
        
        sign = hashlib.md5(data.encode()).hexdigest().upper()
        data += "&sign=" + sign

        req.headers = {'Content-Type': 'application/x-www-form-urlencoded'}
        req.data = data
        return req
<commit_msg>[Fix] okex:修复一个BUG：在传参的时候不应传apiSecret<commit_after># encoding: UTF-8
import hashlib
import urllib

from vnpy.api.rest import Request, RestClient


#----------------------------------------------------------------------
def sign(dataWithApiKey, apiSecret):
    """
    :param dataWithApiKey: sorted urlencoded args with apiKey
    :return: param 'sign' for okex api
    """
    dataWithSecret = dataWithApiKey + "&secret_key=" + apiSecret
    return hashlib.md5(dataWithSecret.encode()).hexdigest().upper()


########################################################################
class OkexFutureRestBase(RestClient):
    host = 'https://www.okex.com/api/v1'
    
    #----------------------------------------------------------------------
    def __init__(self):
        super(OkexFutureRestBase, self).__init__()
        self.apiKey = None
        self.apiSecret = None
    
    #----------------------------------------------------------------------
    # noinspection PyMethodOverriding
    def init(self, apiKey, apiSecret):
        # type: (str, str) -> any
        super(OkexFutureRestBase, self).init(self.host)
        self.apiKey = apiKey
        self.apiSecret = apiSecret

    #----------------------------------------------------------------------
    def beforeRequest(self, req):  # type: (Request)->Request
        args = req.params or {}
        args.update(req.data or {})
        if 'sign' in args:
            args.pop('sign')
        if 'apiKey' not in args:
            args['api_key'] = self.apiKey
        data = urllib.urlencode(sorted(args.items()))
        signature = sign(data, self.apiSecret)
        data += "&sign=" + signature

        req.headers = {'Content-Type': 'application/x-www-form-urlencoded'}
        req.data = data
        return req
{'fraction_non_alphanumeric': 0.3134872417982989, 'fraction_numerical': 0.0018226002430133657, 'mean_word_length': 1.6428571428571428, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2870316', 'n_tokens_mistral': 867, 'n_tokens_neox': 855, 'n_words': 177}