Beispiel #1
0
var createPostData = function(api_key, secret_key, params){
    var w = objectutil.keyMerge({
        api_key : api_key
    },params)
    var qs = querystring.stringify(w).split('&').sort().join('&');
    var res = objectutil.keyMerge(w, {sign:createSign('md5', secret_key, qs)})
    return res;
}
Beispiel #2
0
TradeApi.prototype.query = function(method, mustparams, options){
    var params = objectutil.keyMerge(mustparams, options);
    return lp.req(createPostOption(this.url, this.api_key, this.secret_key, this.user_agent, this.timeout, method, params)).
        then(function(v){
            if(v.result === true){
                return v;
            }else{
                throw new HttpApiError(v.error_code + ':' + constant.ERROR_CODE_MSG[v.error_code], "API", v.error_code, v);
            }
        });
}
FuturesTradeApi.prototype.query = function(method, mustparams, options){
    var params = objectutil.keyMerge(mustparams, options);
    return req(createPostOption(this.url, this.api_key, this.secret_key, this.user_agent, this.nonce_func(), this.timeout, method, params)).
        then(function(v){
            if(v.success === 1){
                return v['return'];
            }else{
                var error_code = (v.error).toUpperCase().replace(' ', '_');
                throw new HttpApiError(v.error, "API", error_code, v);
            }
        });
}
Beispiel #4
0
TradeApi.prototype.query = function(method, mustparams, options){
    var params = objectutil.keyMerge(mustparams, options);
    return lp.req(createPostOption(this.url, this.incrementNonce(), this.api_key, this.secret_key, this.user_agent, this.timeout, method, params)).
        then(function(v){
            if(v.error){
                var error_code = v.error.replace(/ /g, '_').replace('.', '').toUpperCase();
                throw new HttpApiError(v.error, "API", error_code, v);
            }else{
                return v
            }
        });

}
var createPostOption = function(url, api_key, secret_key, user_agent, nonce, timeout, method, params){
    var post = objectutil.keyMerge({nonce:nonce, method:method}, params);
    return {
        url: url,
        method: 'POST',
        forever: constant.OPT_KEEPALIVE,
        form: post,
        headers: createHeader(api_key, secret_key, user_agent, post),
        timeout: timeout,
        transform2xxOnly : true,
        transform: function(body){
            return JSON.parse(body)
        },
    };
}
Beispiel #6
0
var createParameter = function(method, nonce, params){
    return qstring.stringify(objectutil.keyMerge({ command: method, nonce: nonce }, params));
}