0
我嘗試使用bitfinex庫(https://www.npmjs.com/package/bitfinex)從Bitfinex調用Rest API。當使用相同的API密鑰同時運行多個進程時,文檔警告此錯誤。不過,我相信我只能立即運行一個進程,即使我生成了新的API密鑰,錯誤仍然會發生。我正在考慮重寫nonce或擴展它,但我不知道如何做到這一點。我曾在互聯網上嘗試過一些建議,但仍然沒有成功。錯誤:Nonce太小 - Bitfinex api
下面是我的參考代碼:
import Bitfinex = require('bitfinex');
import pollingtoevent = require('polling-to-event');
import { Logger, LoggerFactory } from '../../common';
import { AppDataServices } from '../../data';
export class BitfinexPoller {
private static readonly LOGGER: Logger = LoggerFactory.getLogger();
private bitfinex: any = undefined;
private emitter: any = undefined;
private public_key: string = '<my-public-key>';
private secret_key: string = '<my-secret-key>';
private nonce: any = new Date().getTime();
constructor(private appServices: AppDataServices) {
BitfinexPoller.LOGGER.info('Bitfinex poller init');
this.bitfinex = new Bitfinex(this.public_key, this.secret_key, this.nonce);
// Lend book service
this.emitter = pollingtoevent((done: any) => {
this.bitfinex.lendbook('USD', (err: any, res: any, orderId: any) => {
done(err, res);
});
}, { interval: 30000, eventName: 'bitfinex-lending' });
this.emitter.on('bitfinex-lending', (data: any) => {
BitfinexPoller.LOGGER.info(data);
if (data.bids !== undefined) {
for (const row of data.bids) {
appServices.lendbookService.insert(BitfinexPoller.lendingData('BID', row));
}
}
if (data.asks !== undefined) {
for (const row of data.asks) {
appServices.lendbookService.insert(BitfinexPoller.lendingData('ASK', row));
}
}
});
// Order book service
this.emitter = pollingtoevent((done: any) => {
this.bitfinex.orderbook('btcusd', (err: any, res: any, orderId: any) => {
done(err, res);
});
}, { interval: 30000, eventName: 'bitfinex-order' });
this.emitter.on('bitfinex-order', (data: any) => {
BitfinexPoller.LOGGER.info(data);
if (data.bids !== undefined) {
for (const row of data.bids) {
appServices.lendbookService.insert(BitfinexPoller.orderData('BID', row));
}
}
if (data.asks !== undefined) {
for (const row of data.asks) {
appServices.lendbookService.insert(BitfinexPoller.orderData('ASK', row));
}
}
});
}
}
是的,你說得對,我昨天就知道了。 –