htmsBot/handler.js
// build a slackbot message, then push it
build a slackbot message, then push it
build a slackbot message then push it
function submitMetric(metric) {
  obtainAccount(metric.accountId, function(account) {
    var title = "HTMS Analytics for bot:  " + metric.accountId;
    var fields = [];
    fields.push({
      "title": "Total Trades",
      "value": metric.totalTrades,
      "short": true
    });
    fields.push({
      "title": "Buys",
      "value": metric.buys + '',
      "short": true
    });
    fields.push({
      "title": "Sells",
      "value": metric.sells + '',
      "short": true
    });
    fields.push({
      "title": "Hedges",
      "value": metric.hedges + '',
      "short": true
    });
    fields.push({
      "title": "Volume (BTC)",
      "value": metric.volumeBTC.toFixed(4) + '',
      "short": true
    });
    fields.push({
      "title": "Volume (USD)",
      "value": metric.volumeUSD.toFixed(4) + '',
      "short": true
    });
    fields.push({
      "title": "Exchange Balance (BTC)",
      "value": metric.exchangeBalanceBTC.toFixed(4) + '',
      "short": true
    });
    fields.push({
      "title": "Exchange Balance (USD)",
      "value": metric.exchangeBalanceUSD.toFixed(4) + '',
      "short": true
    });
    fields.push({
      "title": "Fund Value",
      "value": '$' + Number(account.accountBalanceUSD).toFixed(2) + ' / ' + '$' + Number(account.targetAmountUsd).toFixed(2),
      "short": false
    });
    fields.push({
      "title": "Siphoned Profit",
      "value": '$' + Number(account.profitUSD).toFixed(2) + '',
      "short": true
    });
    const slackMessage = {
      channel: "hedgie",
      attachments: [{
        "fallback": title,
        "color": "#838996",
        "title": title,
        "fields": fields,
        "ts": Math.round((metric.lastUpdated / 1000))
      }]
    };
    var params = {
      Message: JSON.stringify({
        "slackMessage": slackMessage
      }),
      MessageStructure: 'raw',
      TopicArn: 'arn:aws:sns:<REDACTED>:SlackBot'
    };
    sns.publish(params, function(err, data) {
      if (err) {
        console.log(err, err.stack); 
      } else {
        console.log("successfully published: " + JSON.stringify(params));
      } 
    });
  });
}
function submitMetric ( metric ) { obtainAccount ( metric . accountId , function ( account ) { var title = "HTMS Analytics for bot:  " + metric . accountId ; var fields = [ ] ; fields . push ( { "title" : "Total Trades" , "value" : metric . totalTrades , "short" : true } ) ; fields . push ( { "title" : "Buys" , "value" : metric . buys + '' , "short" : true } ) ; fields . push ( { "title" : "Sells" , "value" : metric . sells + '' , "short" : true } ) ; fields . push ( { "title" : "Hedges" , "value" : metric . hedges + '' , "short" : true } ) ; fields . push ( { "title" : "Volume (BTC)" , "value" : metric . volumeBTC . toFixed ( 4 ) + '' , "short" : true } ) ; fields . push ( { "title" : "Volume (USD)" , "value" : metric . volumeUSD . toFixed ( 4 ) + '' , "short" : true } ) ; fields . push ( { "title" : "Exchange Balance (BTC)" , "value" : metric . exchangeBalanceBTC . toFixed ( 4 ) + '' , "short" : true } ) ; fields . push ( { "title" : "Exchange Balance (USD)" , "value" : metric . exchangeBalanceUSD . toFixed ( 4 ) + '' , "short" : true } ) ; fields . push ( { "title" : "Fund Value" , "value" : '$' + Number ( account . accountBalanceUSD ) . toFixed ( 2 ) + ' / ' + '$' + Number ( account . targetAmountUsd ) . toFixed ( 2 ) , "short" : false } ) ; fields . push ( { "title" : "Siphoned Profit" , "value" : '$' + Number ( account . profitUSD ) . toFixed ( 2 ) + '' , "short" : true } ) ; const slackMessage = { channel : "hedgie" , attachments : [ { "fallback" : title , "color" : "#838996" , "title" : title , "fields" : fields , "ts" : Math . round ( ( metric . lastUpdated / 1000 ) ) } ] } ; var params = { Message : JSON . stringify ( { "slackMessage" : slackMessage } ) , MessageStructure : 'raw' , TopicArn : 'arn:aws:sns:<REDACTED>:SlackBot' } ; sns . publish ( params , function ( err , data ) { if ( err ) { console . log ( err , err . stack ) ; } else { console . log ( "successfully published: " + JSON . stringify ( params ) ) ; } } ) ; } ) ; }
build a slackbot message, then push it
build a slackbot message then push it
/* required */ // an error occurred // successful response