2013-01-16 2 views
1

mtgox 서버에 대한 쿼리를 수행하고 있습니다. 다음은 API https://en.bitcoin.it/wiki/MtGox/API/HTTP/v1입니다. 내 코드가 서버에 성공적으로 도달했지만 몇 시간이 지나면이 오류가 팝업됩니다.요청 모듈에 오류가 발생했습니다.

events.js:115 
     listeners[i].apply(this, args); 
       ^
TypeError: Cannot call method 'apply' of undefined 
    at EncryptedStream.EventEmitter.emit (events.js:115:20) 
    at SecurePair.destroy (tls.js:896:22) 
    at process.startup.processNextTick.process._tickCallback (node.js:244:9) 

API 호출 제한에서 비롯된 것이 아닙니다.

// 다음 함수는 일반 티커 정보를 USD로 반환합니다. 이것은 높은, 낮은, 그리고 볼륨을 포함 ...

exports.market_data = function(req, res, next){ 
    console.log("test"); 
    options = { 
    uri: 'http://mtgox.com/api/1/BTCUSD/ticker', 
    headers: { 
     'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/555.55 (KHTML, like Gecko) Chrome/55.5.5555.55 Safari/555.55' 
    } 
    }; 
    try { 
    request(options, function (err, response, body) { 
     // console.log(body); 
     APIResponder.respond(res, response); 
    }); 
    } catch(err) { 
     console.log(err); 
     console.log("Gangnam style"); 
    throw err; 
    } 
}; 

지연에 대한 죄송합니다, 인터넷 사망했다. 다음은 MTGox를 쿼리하는 코드입니다. 희망이 도움이됩니다.

+0

TypeError : 정의되지 않은 'apply'메서드를 호출 할 수 없습니다. 청취자를 참조하십시오. [i] - 해당 코드 섹션을 게시해야하며 어떤 종류의 개체 또는 함수인지 알 수 없습니다. – Morgan

+0

코드를 보여줄 수 있습니까? 어딘가에'function' 대신에'null' 인 이벤트 핸들러를 바인딩하고 있으므로 함수를 실행하려고 할 때 충돌이 발생합니다. – loganfsmyth

답변

2

나는 당신의 요청 기능을 무엇을하는지 모르지만 그것은 바로 가기 http.request에 대한인지 응답이 덩어리에 도착, 당신이 염두에 두어야한다. res.pipe (응답), 또는 수동으로 처리 할 수 ​​있습니다 : 당신이이 덩어리가 있으므로 APIResponder.respond 파이프 고해상도에 대한 응답해야 얻을 수 응답과 같은 속도로 고해상도 쓸 수 있다면 당신은 모르는

response.on('data',function(data){ 
    var flushed = res.write(data); 
    if(!flushed) response.pause(); 
}) 
res.on('drain',function(){ 
    response.resume(); 
}) 
관련 문제