bitmex: normalize account info currencies (#799)

* bitmex: normalize account info currencies

Bitmex has an interesting way of returning BTC balances, it returns them
as XBt and denominated in Satoshis instead. Normalize that still in the
bitmex wrapper by performing the conversion and returning the normal use
BTC currency.

* Change NW contract to NQ

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
Luis Rascão
2021-10-13 01:05:16 +01:00
committed by GitHub
parent a5a960e9df
commit 0a91af0f2e
5 changed files with 82 additions and 21 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"math"
"sort"
"strconv"
"strings"
"sync"
"time"
@@ -179,6 +180,7 @@ func (b *Bitmex) Setup(exch *config.ExchangeConfig) error {
return b.Websocket.SetupNewConnection(stream.ConnectionSetup{
ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,
ResponseMaxLimit: exch.WebsocketResponseMaxLimit,
URL: bitmexWSURL,
})
}
@@ -415,27 +417,36 @@ func (b *Bitmex) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType
func (b *Bitmex) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
var info account.Holdings
bal, err := b.GetAllUserMargin(ctx)
userMargins, err := b.GetAllUserMargin(ctx)
if err != nil {
return info, err
}
// Need to update to add Margin/Liquidity availibilty
var accountID string
var balances []account.Balance
for i := range bal {
// Need to update to add Margin/Liquidity availability
for i := range userMargins {
accountID = strconv.FormatInt(userMargins[i].Account, 10)
wallet, err := b.GetWalletInfo(ctx, userMargins[i].Currency)
if err != nil {
continue
}
balances = append(balances, account.Balance{
CurrencyName: currency.NewCode(bal[i].Currency),
TotalValue: float64(bal[i].WalletBalance),
CurrencyName: currency.NewCode(wallet.Currency),
TotalValue: wallet.Amount,
})
}
info.Accounts = append(info.Accounts,
account.SubAccount{
ID: accountID,
Currencies: balances,
})
info.Exchange = b.Name
info.Accounts = append(info.Accounts, account.SubAccount{
Currencies: balances,
})
err = account.Process(&info)
if err != nil {
if err := account.Process(&info); err != nil {
return account.Holdings{}, err
}