It detects changes in the currency and money in the account balance and sends it to the specified mailbox. Previously, text messages were used as instant messaging because of the large number of users, the accounts were frozen and could not be interfaced with text messages, so they were replaced with e-mail.
function Notify(msg) { var ret = Mail(SMTPServer, SMTPUser, SMTPPass, SendMode == 0 ? SMTPUser : DstMail , msg, "余额变动 " + msg); if (ret) { Log("邮件通知成功"); } else { Log("邮件通知失败"); } Log(ret ? "邮件发送成功" : "邮件发送失败"); return ret; } function GetAccount(print) { var all = { Balance : 0, Stocks : 0, }; var currency = exchange.GetCurrency(); for (var i = 0; i < exchanges.length; i++) { if (exchanges[i].GetCurrency() != currency) { throw "币种不相同"; } var account; while (!(account = exchanges[i].GetAccount())) { Sleep(1000); } all.Stocks += (account.Stocks + account.FrozenStocks); all.Balance += (account.Balance + account.FrozenBalance); if (typeof(print) != 'undefined' && print) { Log(exchanges[i].GetName(), "钱: ", (account.Balance + account.FrozenBalance), "币: ", (account.Stocks + account.FrozenStocks)); } } return all; } function main() { // Disable rate auto convert exchange.SetRate(1); if (Version() < 2.7) { throw "只支持2.7或以上版本"; } var preAccount = GetAccount(true); if (!Notify("策略启成功, 总钱: " + preAccount.Balance + ", 币: " + preAccount.Stocks)) { throw "Exit"; } Log("初始信息: ", "总钱:", preAccount.Balance, "总币:", preAccount.Stocks); var alertAlrelady = false; while (true) { Sleep(LoopInterval * 1000); var account = GetAccount(); if (AlertMode == 2) { if ((MinCoin > 0 && account.Stocks < MinCoin) || (MinCNY > 0 && account.Balance < MinCNY)) { if (!alertAlrelady) { Log(account); Notify(exchange.GetName() + "资金过少 总钱: " + account.Balance + ", 币: " + account.Stocks); alertAlrelady = true; } } else { alertAlrelady = false; } } else if (account.Stocks != preAccount.Stocks || account.Balance != preAccount.Balance) { if (AlertMode == 0 || (MaxDiffCoin > 0 && Math.abs(account.Stocks - preAccount.Stocks) >= MaxDiffCoin) || (MaxDiffCNY > 0 && Math.abs(account.Balance - preAccount.Balance) >= MaxDiffCNY)) { Log(account); preAccount = account; Notify(exchange.GetName() + "账户变动为 总钱: " + account.Balance + ", 币: " + account.Stocks); } } } }