add choosing mango account

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2021-09-17 22:07:23 +02:00
parent 984d9409e7
commit ed174fb95b
2 changed files with 22 additions and 3 deletions

View File

@ -28,3 +28,4 @@
- integration with tradingview or https://github.com/thibaultyou/tradingview-alerts-processor/blob/master/docs/2_Alerts.md & https://www.tradingview.com/support/solutions/43000529348-about-webhooks/
- cleanup tsconfig.json
- add pre commit tools e.g. husky/pre-commit for code formatting and linting
- requests https://twitter.com/microwavedcola1/status/1438439176194727937

View File

@ -53,10 +53,12 @@ class MangoSimpleClient {
let possibleClustersUrls = [
"https://api.mainnet-beta.solana.com",
"https://lokidfxnwlabdq.main.genesysgo.net:8899/",
"https://solana-api.projectserum.com/"
"https://solana-api.projectserum.com/",
];
clusterUrl =
possibleClustersUrls[Math.floor(Math.random() * possibleClustersUrls.length)];
possibleClustersUrls[
Math.floor(Math.random() * possibleClustersUrls.length)
];
logger.info(`switching to rpc node - ${clusterUrl}...`);
this.connection = new Connection(clusterUrl, "processed" as Commitment);
@ -123,7 +125,23 @@ class MangoSimpleClient {
a.publicKey.toBase58() > b.publicKey.toBase58() ? 1 : -1
);
const chosenMangoAccount = sortedMangoAccounts[0];
let chosenMangoAccount;
if (process.env.MANGO_ACCOUNT) {
const filteredMangoAccounts = sortedMangoAccounts.filter(
(mangoAccount) =>
mangoAccount.publicKey.toBase58() === process.env.MANGO_ACCOUNT
);
if (!filteredMangoAccounts.length) {
logger.error(
`- no mango account found for key ${process.env.MANGO_ACCOUNT}`
);
process.exit(1);
}
chosenMangoAccount = filteredMangoAccounts[0];
} else {
chosenMangoAccount = sortedMangoAccounts[0];
}
const debugAccounts = sortedMangoAccounts
.map((mangoAccount) => mangoAccount.publicKey.toBase58())
.join(", ");