added getAssets and getLiabs

This commit is contained in:
dd 2021-02-10 14:52:22 -05:00
parent f9f7395c83
commit 10eb1bac82
1 changed files with 33 additions and 0 deletions

View File

@ -182,6 +182,39 @@ export class MarginAccount {
return value return value
} }
getAssets(mangoGroup: MangoGroup): number[] {
if (this.openOrdersAccounts == undefined) {
throw new Error("openOrdersAccounts not yet loaded")
}
const assets = new Array<number>(NUM_TOKENS)
for (let i = 0; i < NUM_TOKENS; i++) {
assets[i] = this.getUiDeposit(mangoGroup, i)
}
for (let i = 0; i < NUM_MARKETS; i++) {
const openOrdersAccount = this.openOrdersAccounts[i]
if (openOrdersAccount == undefined) {
continue
}
assets[i] += nativeToUi(openOrdersAccount.baseTokenTotal.toNumber(), mangoGroup.mintDecimals[i])
assets[NUM_TOKENS-1] += nativeToUi(openOrdersAccount.quoteTokenTotal.toNumber(), mangoGroup.mintDecimals[NUM_TOKENS-1])
}
return assets
}
getLiabs(mangoGroup: MangoGroup): number[] {
const liabs = new Array(NUM_TOKENS)
for (let i = 0; i < NUM_TOKENS; i++) {
liabs[i] = this.getUiBorrow(mangoGroup, i)
}
return liabs
}
getAssetsVal(mangoGroup: MangoGroup, prices: number[]): number { getAssetsVal(mangoGroup: MangoGroup, prices: number[]): number {
let assetsVal = 0 let assetsVal = 0
for (let i = 0; i < NUM_TOKENS; i++) { for (let i = 0; i < NUM_TOKENS; i++) {