@debut/plugin-neurofilter
Version:
Neuro filter plugin for debute
59 lines • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.neuroFilterPlugin = void 0;
const community_core_1 = require("@debut/community-core");
const neurohelper_1 = require("./neurohelper");
function neuroFilterPlugin() {
let neuro;
const neuroTrain = 'neuroTrain' in community_core_1.utils.cli.getArgs();
return {
name: 'neurofilter',
api: {
train(input, orderId) {
const data = {
input,
output: null,
id: orderId,
};
neuro.addTrainingData(data);
},
run(input) {
if (!neuro.trained) {
return 1;
}
return neuro.run(input);
},
trained() {
return neuro.trained;
},
},
onInit() {
const botName = this.debut.getName();
neuro = new neurohelper_1.NeuroHelper(botName);
if (!neuroTrain) {
neuro.load(this.debut.opts.ticker);
}
},
async onClose(order) {
if (neuro.trained || !neuroTrain || !order.openId || !order.openPrice) {
return;
}
let output = 0;
if (order.type === "SELL" /* SELL */ && order.openPrice < order.price) {
output = 1;
}
else if (order.type === "BUY" /* BUY */ && order.openPrice > order.price) {
output = 1;
}
neuro.updateTrainingOut(order.openId, output);
},
async onDispose() {
if (neuroTrain) {
neuro.train({ log: true });
neuro.save(this.debut.opts.ticker);
}
},
};
}
exports.neuroFilterPlugin = neuroFilterPlugin;
//# sourceMappingURL=index.js.map