2017-12-28 119 views
5

tôi phải xác thực Bitmex API sử dụng khóa Api của tôi, nhưng tôi đã nhận lỗi nàySwagger Client API xác thực khoá

Không thể kết nối: Lỗi Loại: Không thể đọc thuộc 'thêm' không xác định

'use strict'; 
var SwaggerClient = require("swagger-client"); 
var _ = require('lodash'); 
var BitMEXAPIKeyAuthorization = require('./lib/BitMEXAPIKeyAuthorization'); 

require('dotenv').config(); 

new SwaggerClient({ 
    // Switch this to `www.bitmex.com` when you're ready to try it out for real. 
    // Don't forget the `www`! 
    url: 'https://testnet.bitmex.com/api/explorer/swagger.json', 
    usePromise: true 
}) 
.then(function(client) { 
    //console.log(client); 
    // Comment out if you're not requesting any user data. 
    client.clientAuthorizations.add("apiKey", new BitMEXAPIKeyAuthorization(process.env.BITMEX_API_KEY, process.env.BITMEX_API_SECRET)); 

    // Print client capabilities 
    // 

}) 
.catch(function(e) { 
    console.error("Unable to connect:", e); 
}) 

Nodejs nối: https://github.com/BitMEX/api-connectors

Trả lời

2

Bạn đang sử dụng phiên bản mới nhất của khách hàng, mà không làm phép như vậy: https://github.com/swagger-api/swagger-js/blob/903569948d5a5c718d7b87d6832a672de4e76afc/docs/MIGRATION_2_X.md#authorizations

new SwaggerClient({ 
    // Switch this to `www.bitmex.com` when you're ready to try it out for real. 
    // Don't forget the `www`! 
    url: 'https://testnet.bitmex.com/api/explorer/swagger.json', 
    usePromise: true, 
    authorizations: { 
     apiKey: new BitMEXAPIKeyAuthorization(process.env.BITMEX_API_KEY, process.env.BITMEX_API_SECRET) 
    } 
}) 
.then(client => { 
    // Do whatever with client 
}) 
.catch(function(e) { 
console.error("Unable to connect:", e); 
})