CryptoKraken / crypto-kraken-services

MIT License
0 stars 1 forks source link

The operation of getting the user's balance #67

Open skubarenko opened 6 years ago

skubarenko commented 6 years ago

As for now, the base exchange service has the getBalance method with the following signature:

getBalance(currency: string, exchangeCredentials: ExchangeCredentials): Promise<number>;

This method returns a number, though mostly exchanges (Binance, Bitfinex, KuCoin etc) return no just a number but an object which contains a whole balance of currency and a locked balance. So I suggest to change the signature of the getBalance method to:

getBalance(currency: string, exchangeCredentials: ExchangeCredentials): Promise<CurrencyBalance>;

where the CurrencyBalance is the following interface:

interface CurrencyBalance {
     readonly amount: number,
     readonly freeAmount: number;
     readonly lockedAmount: number;
}

Also, I want to add overloads for the getBalance method

// get balance of all your currencies
getBalance(exchangeCredentials: ExchangeCredentials): Promise<AccountBalance>;

where AccountBalance is the following interface:

interface AccountBalance {
    [currencyTicker: string]: CurrencyBalance;
}

The instance of the AccountBalance interface:

const myBalance: AccountBalance = {
    'btc': {
        amount: 2,
        freeAmount: 0.5,
        lockedAmount: 1.5
    },
    'eth': {
        amount: 10,
        freeAmount: 0,
        lockedAmount: 10
    }
}

As a result, the ExchangeService interface will have these two overloads:

export interface ExchangeService {
...
    getBalance(exchangeCredentials: ExchangeCredentials): Promise<AccountBalance>;
    getBalance(currency: string, exchangeCredentials: ExchangeCredentials): Promise<CurrencyBalance>;
    getBalance(currency: string | ExchangeCredentials, exchangeCredentials: ExchangeCredentials | undefined): Promise<CurrencyBalance | AccountBalance>;
...
}
maxima-net commented 6 years ago

I agree with returning a CurrencyBalance instance instead of a number for getBalance method. What about of getting balance of all currencies. We need to check this functionality in all exchanges before we start doing implementation.