-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
219 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,133 +4,98 @@ const gmail_address = env.GMAIL_ADDRESS | |
const gmail_app_password = env.GMAIL_APP_PASSWORD | ||
|
||
function createMailMessage(subject, html) { | ||
return { | ||
from: '"🐬 BVA " <[email protected]>', | ||
to: gmail_address, | ||
subject, | ||
text: html, | ||
html, | ||
} | ||
return { | ||
from: '"🐬 BVA " <[email protected]>', | ||
to: gmail_address, | ||
subject, | ||
text: html, | ||
html, | ||
} | ||
} | ||
|
||
function createSignalMessage(base, signal) { | ||
const subject = | ||
base + | ||
" :: " + | ||
signal.stratname + | ||
" " + | ||
signal.pair + | ||
" " + | ||
signal.price | ||
const subject = | ||
base + " :: " + | ||
signal.stratname + | ||
" " + | ||
signal.pair + | ||
" " + | ||
signal.price; | ||
|
||
const text = (signal.score ? "score: " + signal.score : "score: NA") + "\n" | ||
const text = | ||
(signal.score | ||
? "score: " + signal.score | ||
: "score: NA") + "\n"; | ||
|
||
return createMailMessage(subject, text) | ||
return createMailMessage(subject, text) | ||
} | ||
|
||
module.exports = function () { | ||
if (!env.USE_GMAIL) return {} | ||
|
||
const mailTransport = require("nodemailer").createTransport( | ||
`smtps://${encodeURIComponent(gmail_address)}:${encodeURIComponent( | ||
gmail_app_password | ||
)}@smtp.gmail.com` | ||
) | ||
if (!env.USE_GMAIL) return {}; | ||
|
||
function send(message) { | ||
if (!env.USE_GMAIL) return | ||
const mailTransport = require("nodemailer").createTransport( | ||
`smtps://${encodeURIComponent(gmail_address)}:${encodeURIComponent(gmail_app_password)}@smtp.gmail.com` | ||
) | ||
|
||
if (typeof message === "string") { | ||
message = createMailMessage("Tading Bot Message", message) | ||
} | ||
function send(message) { | ||
if (!env.USE_GMAIL) return; | ||
|
||
return mailTransport.sendMail(message).catch((error) => { | ||
console.error( | ||
"There was an error while sending the email ... trying again...", | ||
error | ||
) | ||
setTimeout(() => { | ||
mailTransport.sendMail(message).catch((error) => { | ||
console.error( | ||
"There was an error while sending the email: stop trying", | ||
error | ||
) | ||
}) | ||
}, 2000) | ||
}) | ||
if (typeof message === "string") { | ||
message = createMailMessage("Tading Bot Message", message) | ||
} | ||
|
||
function notifyBuyToCoverSignal(signal) { | ||
return send( | ||
createSignalMessage( | ||
"<i>BUY_SIGNAL :: BUY TO COVER SHORT TRADE</i>", | ||
signal | ||
) | ||
) | ||
} | ||
function notifyBuyToCoverTraded(signal) { | ||
return send( | ||
createSignalMessage( | ||
"<b>>> SUCCESS! BUY_SIGNAL :: BUY TO COVER SHORT TRADE</b>", | ||
signal | ||
) | ||
) | ||
} | ||
function notifyEnterLongSignal(signal) { | ||
return send( | ||
createSignalMessage("<i>BUY_SIGNAL :: ENTER LONG TRADE</i>", signal) | ||
) | ||
} | ||
function notifyEnterLongTraded(signal) { | ||
return send( | ||
createSignalMessage( | ||
"<b>>> SUCCESS! BUY_SIGNAL :: ENTER LONG TRADE</b>", | ||
signal | ||
) | ||
) | ||
} | ||
function notifyEnterShortSignal(signal) { | ||
return send( | ||
createSignalMessage( | ||
"<i>SEL_SIGNAL :: ENTER SHORT TRADE</i>", | ||
signal | ||
) | ||
return mailTransport | ||
.sendMail(message) | ||
.catch((error) => { | ||
console.error( | ||
"There was an error while sending the email ... trying again...", error | ||
) | ||
} | ||
function notifyEnterShortTraded(signal) { | ||
return send( | ||
createSignalMessage( | ||
"<b>>> SUCCESS! SELL_SIGNAL :: ENTER SHORT TRADE</b>", | ||
signal | ||
) | ||
) | ||
} | ||
function notifyExitLongSignal(signal) { | ||
return send( | ||
createSignalMessage( | ||
"<i>SELL_SIGNAL :: SELL TO EXIT LONG TRADE</i>", | ||
signal | ||
) | ||
) | ||
} | ||
function notifyExitLongTraded(signal) { | ||
return send( | ||
createSignalMessage( | ||
"<b>>> SUCCESS! SELL_SIGNAL :: SELL TO EXIT LONG TRADE</b>", | ||
signal | ||
) | ||
) | ||
} | ||
setTimeout(() => { | ||
mailTransport | ||
.sendMail(message) | ||
.catch((error) => { | ||
console.error( | ||
"There was an error while sending the email: stop trying", error | ||
) | ||
}) | ||
}, 2000) | ||
}) | ||
} | ||
|
||
return { | ||
notifyBuyToCoverSignal, | ||
notifyBuyToCoverTraded, | ||
notifyEnterLongSignal, | ||
notifyEnterLongTraded, | ||
notifyEnterShortSignal, | ||
notifyEnterShortTraded, | ||
notifyExitLongSignal, | ||
notifyExitLongTraded, | ||
send, | ||
} | ||
function notifyBuyToCoverSignal(signal) { | ||
return send(createSignalMessage("<i>BUY_SIGNAL :: BUY TO COVER SHORT TRADE</i>", signal)); | ||
} | ||
function notifyBuyToCoverTraded(signal) { | ||
return send(createSignalMessage("<b>>> SUCCESS! BUY_SIGNAL :: BUY TO COVER SHORT TRADE</b>", signal)); | ||
} | ||
function notifyEnterLongSignal(signal) { | ||
return send(createSignalMessage("<i>BUY_SIGNAL :: ENTER LONG TRADE</i>", signal)); | ||
} | ||
function notifyEnterLongTraded(signal) { | ||
return send(createSignalMessage("<b>>> SUCCESS! BUY_SIGNAL :: ENTER LONG TRADE</b>", signal)); | ||
} | ||
function notifyEnterShortSignal(signal) { | ||
return send(createSignalMessage("<i>SEL_SIGNAL :: ENTER SHORT TRADE</i>", signal)); | ||
} | ||
function notifyEnterShortTraded(signal) { | ||
return send(createSignalMessage("<b>>> SUCCESS! SELL_SIGNAL :: ENTER SHORT TRADE</b>", signal)); | ||
} | ||
function notifyExitLongSignal(signal) { | ||
return send(createSignalMessage("<i>SELL_SIGNAL :: SELL TO EXIT LONG TRADE</i>", signal)); | ||
} | ||
function notifyExitLongTraded(signal) { | ||
return send(createSignalMessage("<b>>> SUCCESS! SELL_SIGNAL :: SELL TO EXIT LONG TRADE</b>", signal)); | ||
} | ||
|
||
return { | ||
notifyBuyToCoverSignal, | ||
notifyBuyToCoverTraded, | ||
notifyEnterLongSignal, | ||
notifyEnterLongTraded, | ||
notifyEnterShortSignal, | ||
notifyEnterShortTraded, | ||
notifyExitLongSignal, | ||
notifyExitLongTraded, | ||
send, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,23 @@ | ||
const env = require("./../env") | ||
|
||
module.exports = function (trading_pairs) { | ||
const notifiers = [] | ||
if (env.USE_TELEGRAM) notifiers.push(require("./telegram")(trading_pairs)) | ||
if (env.USE_GMAIL) notifiers.push(require("./gmail")()) | ||
const notifiers = []; | ||
if (env.USE_TELEGRAM) | ||
notifiers.push(require('./telegram')(trading_pairs)) | ||
if (env.USE_GMAIL) | ||
notifiers.push(require('./gmail')()) | ||
|
||
const notifyAllFor = (method, arg) => | ||
notifiers.forEach((n) => n[method] && n[method](arg)) | ||
const notifyAllFor = (method, arg) => notifiers.forEach(n => n[method] && n[method](arg)); | ||
|
||
return { | ||
notifyBuyToCoverSignal: (signal) => | ||
notifyAllFor("notifyBuyToCoverSignal", signal), | ||
notifyBuyToCoverTraded: (signal) => | ||
notifyAllFor("notifyBuyToCoverTraded", signal), | ||
notifyEnterLongSignal: (signal) => | ||
notifyAllFor("notifyEnterLongSignal", signal), | ||
notifyEnterLongTraded: (signal) => | ||
notifyAllFor("notifyEnterLongTraded", signal), | ||
notifyEnterShortSignal: (signal) => | ||
notifyAllFor("notifyEnterShortSignal", signal), | ||
notifyEnterShortTraded: (signal) => | ||
notifyAllFor("notifyEnterShortTraded", signal), | ||
notifyExitLongSignal: (signal) => | ||
notifyAllFor("notifyExitLongSignal", signal), | ||
notifyExitLongTraded: (signal) => | ||
notifyAllFor("notifyExitLongTraded", signal), | ||
send: (message) => notifyAllFor("send", message), | ||
} | ||
} | ||
return { | ||
notifyBuyToCoverSignal: signal => notifyAllFor("notifyBuyToCoverSignal", signal), | ||
notifyBuyToCoverTraded: signal => notifyAllFor("notifyBuyToCoverTraded", signal), | ||
notifyEnterLongSignal: signal => notifyAllFor("notifyEnterLongSignal", signal), | ||
notifyEnterLongTraded: signal => notifyAllFor("notifyEnterLongTraded", signal), | ||
notifyEnterShortSignal: signal => notifyAllFor("notifyEnterShortSignal", signal), | ||
notifyEnterShortTraded: signal => notifyAllFor("notifyEnterShortTraded", signal), | ||
notifyExitLongSignal: signal => notifyAllFor("notifyExitLongSignal", signal), | ||
notifyExitLongTraded: signal => notifyAllFor("notifyExitLongTraded", signal), | ||
send: message => notifyAllFor("send", message), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.