Skip to content

Commit

Permalink
Merge pull request #9 from ordinalsbot/exchange-notifications
Browse files Browse the repository at this point in the history
add exchange notifications
  • Loading branch information
ordinariusprof authored Mar 26, 2024
2 parents 245801d + 5561ef7 commit 5cb15a1
Show file tree
Hide file tree
Showing 7 changed files with 726 additions and 1,556 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ switch (ACTIVE_EXCHANGE) {
const krakenAPI = new KrakenAPI(KRAKEN_API_KEY, KRAKEN_API_SECRET);
exchangeTumbler = new KrakenTumbler(
krakenAPI,
notifications,
MIN_WITHDRAWAL_AMOUNT,
MAX_WITHDRAWAL_AMOUNT,
KRAKEN_WITHDRAWAL_WALLET,
Expand All @@ -110,6 +111,7 @@ switch (ACTIVE_EXCHANGE) {
const okcoinAPI = new OkcoinAPI(OKCOIN_API_KEY, OKCOIN_API_SECRET, OKCOIN_API_PASSPHRASE);
exchangeTumbler = new OkcoinTumbler(
okcoinAPI,
notifications,
MIN_WITHDRAWAL_AMOUNT,
MAX_WITHDRAWAL_AMOUNT,
OKCOIN_WITHDRAWAL_WALLET,
Expand Down
6 changes: 6 additions & 0 deletions model/exchanges/kraken.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
const KrakenAPI = require('../../api/kraken');
const NotificationService = require('../notifications/notificationService');

/**
* Rotates funds from a Kraken account
*/
class KrakenTumbler {
/**
* @param {KrakenAPI} krakenClient
* @param {NotificationService} notificationService
* @param {number} minWithdrawalAmount
* @param {number} maxWithdrawalAmount
* @param {string} withdrawWallet
* @param {string} withdrawCurrency
*/
constructor(
krakenClient,
notificationService,
minWithdrawalAmount,
maxWithdrawalAmount,
withdrawWallet,
withdrawCurrency,
) {
this.krakenClient = krakenClient;
this.notificationService = notificationService;
this.minWithdrawalAmount = minWithdrawalAmount;
this.maxWithdrawalAmount = maxWithdrawalAmount;
this.withdrawWallet = withdrawWallet;
Expand Down Expand Up @@ -49,10 +53,12 @@ class KrakenTumbler {
withdrawalAmount,
);
if (res.error.length > 0) {
this.notificationService.sendMessage('stopped: error calling kraken api', 'verbose');
console.error('error calling kraken api', res.error);
return false;
}

this.notificationService.sendMessage(`successful withdrawal ${withdrawalAmount} ${this.withdrawCurrency} to wallet ${this.withdrawWallet}`, 'verbose');
console.log('succeful withdrawal from kraken', res.result);

return true;
Expand Down
5 changes: 5 additions & 0 deletions model/exchanges/okcoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ const OkcoinAPI = require('../../api/okcoin');
class OkcoinTumbler {
/**
* @param {OkcoinAPI} okcoinClient
* @param {NotificationService} notificationService
* @param {number} minWithdrawalAmount
* @param {number} maxWithdrawalAmount
* @param {string} withdrawWallet
* @param {string} withdrawCurrency
*/
constructor(
okcoinClient,
notificationService,
minWithdrawalAmount,
maxWithdrawalAmount,
withdrawWallet,
withdrawCurrency,
) {
this.okcoinClient = okcoinClient;
this.notificationService = notificationService;
this.minWithdrawalAmount = minWithdrawalAmount;
this.maxWithdrawalAmount = maxWithdrawalAmount;
this.withdrawWallet = withdrawWallet;
Expand Down Expand Up @@ -58,11 +61,13 @@ class OkcoinTumbler {
console.log('response from okcoin', res);

if (res.msg) {
this.notificationService.sendMessage('stopped: error calling okcoin api', 'verbose');
console.error('error calling okcoin api', res.msg);
return false;
}

console.log('successful withdrawal from okcoin');
this.notificationService.sendMessage(`successful withdrawal ${withdrawalAmount} ${this.withdrawCurrency} to wallet ${this.withdrawWallet}`, 'verbose');
return true;
};
}
Expand Down
2 changes: 2 additions & 0 deletions model/satminer.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class Satminer {

extractSatsAndRotateFunds = async () => {
console.log('scanning for rare sats...');
this.notificationService.sendMessage(`starting a new cycle.`, 'verbose');

const fees = await this.wallet.estimateFee();
const { fastestFee } = fees;
Expand All @@ -150,6 +151,7 @@ class Satminer {
const { specialRanges, tx, message } = satextractorRes;

if (message && message.includes('Address is empty')) {
this.notificationService.sendMessage(`${this.tumblerAddress} is currently empty.`, 'verbose');
console.log('tumbler wallet is empty');
return false;
} else if (specialRanges.length === 0) {
Expand Down
Loading

0 comments on commit 5cb15a1

Please sign in to comment.