Class Client

Represents a client for interacting with the Bitpin API.

Constructors

  • Initializes a new instance of the Client class with the provided parameters.

    Parameters

    • Optionalparams: IClientParams

      Optional parameters for initializing the client.

    Returns Client

Properties

accessToken: undefined | string

The access token for authenticated requests.

apiKey: undefined | string

The API key for authentication.

apiVersion1: string = 'v1'

The API version to use.

'v1'
axiosConfig: undefined | AxiosRequestConfig<any>

Custom Axios configuration.

backgroundProcess: undefined | IBackgroundProcesses

Background processes configuration.

baseUrl: string = 'https://api.bitpin.{tld}/api'

The base URL for the API.

'https://api.bitpin.{tld}'
refreshToken: undefined | string

The refresh token for obtaining new access tokens.

requestTimeout: number = 5_000

The request timeout in milliseconds.

5000
secretKey: undefined | string

The secret key for authentication.

session: AxiosInstance

The Axios instance for making HTTP requests.

tld: TLD = 'ir'

The top-level domain for the API base URL.

'ir'

Methods

  • Authenticates the client using the provided API key and secret key.

    Parameters

    Returns Promise<IAuthenticateResponse>

    A promise that resolves to the authentication response.

    If the API key or secret key is not provided.

    const response = await client.authenticate({ apiKey: 'your_api_key', secretKey: 'your_secret_key' });
    console.log(response);
  • Creates multiple orders in bulk.

    Parameters

    Returns Promise<IBulkCreateOrderResponse>

    A promise that resolves to the bulk create order response.

    const response = await client.bulkCreateOrders([{ symbol: 'BTC_USD', amount: 1 }]);
    console.log(response);
  • Cancels an order with the specified order ID.

    Parameters

    Returns Promise<undefined>

    A promise that resolves to the order status response.

    const response = await client.cancelOrder({ order_id: '12345' });
    console.log(response);
  • Protected

    Creates the full API URI by combining the base URL, version, and path.

    Parameters

    • path: string

      The endpoint path.

    • Optionalversion: string = ...

      The API version to use.

    Returns string

    The full API URI.

    const uri = this.createApiUri('endpoint');
    console.log(uri); // 'https://api.bitpin.ir/v1/endpoint'
  • Creates a new order.

    Parameters

    Returns Promise<IOrderStatusResponse>

    A promise that resolves to the order status response.

    const orderStatus = await client.createOrder({ symbol: 'BTC_USD', amount: 1 });
    console.log(orderStatus);
  • Protected

    Makes a DELETE request to the specified API endpoint.

    Type Parameters

    • R

    Parameters

    • path: string

      The endpoint path.

    • Optionalsigned: boolean = false

      Indicates if the request requires authentication.

    • Optionalversion: string = ...

      The API version to use.

    • Optionalkwargs: IRequestOptions

      Additional request options.

    Returns Promise<any>

    A promise that resolves to the response data.

    const data = await this.delete('endpoint', true);
    console.log(data);
  • Protected

    Makes a GET request to the specified API endpoint.

    Type Parameters

    • R

    Parameters

    • path: string

      The endpoint path.

    • Optionalsigned: boolean = false

      Indicates if the request requires authentication.

    • Optionalversion: string = ...

      The API version to use.

    • Optionalkwargs: IRequestOptions

      Additional request options.

    Returns Promise<R>

    A promise that resolves to the response data.

    const data = await this.get('endpoint', true);
    console.log(data);
  • Protected

    Configures and returns the Axios request configuration.

    Returns AxiosRequestConfig<any>

    The Axios request configuration with default headers.

  • Retrieves the list of available currencies.

    Parameters

    Returns Promise<ICurrencyInfo[]>

    A promise that resolves to an array of currency information.

    const currencies = await client.getCurrenciesList();
    console.log(currencies);
  • Retrieves the list of available markets.

    Parameters

    Returns Promise<IMarketInfo[]>

    A promise that resolves to an array of market information.

    const markets = await client.getMarketsInfo();
    console.log(markets);
  • Retrieves the order book for the specified symbol.

    Parameters

    Returns Promise<IOrderBookResponse>

    A promise that resolves to the order book response.

    const orderBook = await client.getOrderBook({ symbol: 'BTC_USD' });
    console.log(orderBook);
  • Retrieves the status of an order with the specified order ID(s).

    Parameters

    Returns Promise<IOrderStatusResponse>

    A promise that resolves to the order status response.

    const status = await client.getOrderStatus({ order_id: '12345' });
    console.log(status);
  • Retrieves the list of price tickers.

    Parameters

    Returns Promise<ITickerInfo[]>

    A promise that resolves to an array of ticker information.

    const tickers = await client.getPriceTickers();
    console.log(tickers);
  • Retrieves the recent trades for the specified symbol.

    Parameters

    Returns Promise<ITrade[]>

    A promise that resolves to an array of trade information.

    const recentTrades = await client.getRecentTrades({ symbol: 'BTC_USD' });
    console.log(recentTrades);
  • Protected

    Configures and returns the Axios request configuration with the necessary headers and parameters.

    Parameters

    • method: string

      The HTTP request method (e.g., 'get', 'post').

    • signed: boolean

      Indicates if the request requires authentication.

    • Optionalkwargs: IRequestOptions = {}

      Additional request options.

    Returns AxiosRequestConfig<any>

    The configured Axios request configuration.

    If the request requires authentication but the access token is not available.

    const config = this.getRequestKwargs('get', true, { data: { key: 'value' } });
    console.log(config);
  • Retrieves the list of open orders.

    Parameters

    Returns Promise<IOrderStatusResponse[]>

    A promise that resolves to an array of order status responses.

    const openOrders = await client.getOpenOrders();
    console.log(openOrders);
  • Retrieves the user's trade history.

    Parameters

    Returns Promise<IFill[]>

    A promise that resolves to an array of trade information.

    const trades = await client.getUserTrades();
    console.log(trades);
  • Retrieves the wallet information.

    Parameters

    Returns Promise<IWalletResponse[]>

    A promise that resolves to an array of wallet responses.

    const wallets = await client.getWallet();
    console.log(wallets);
  • Protected

    Makes a POST request to the specified API endpoint.

    Type Parameters

    • R

    Parameters

    • path: string

      The endpoint path.

    • Optionalsigned: boolean = false

      Indicates if the request requires authentication.

    • Optionalversion: string = ...

      The API version to use.

    • Optionalkwargs: IRequestOptions

      Additional request options.

    Returns Promise<R>

    A promise that resolves to the response data.

    const data = await this.post('endpoint', true);
    console.log(data);
  • Refreshes the access token using the provided refresh token or the stored refresh token.

    Parameters

    Returns Promise<IRefreshTokenResponse>

    A promise that resolves to the refresh token response.

    If the refresh token is not provided.

    const response = await client.refreshAccessToken({ refresh: 'your_refresh_token' });
    console.log(response);
  • Creates a new instance of the Client class and authenticates if API key and secret key are provided.

    Parameters

    • Optionalparams: IClientParams

      Optional parameters for creating the client instance.

    Returns Promise<Client>

    A promise that resolves to a new Client instance.

    const client = await Client.Create({ apiKey: 'your_api_key', secretKey: 'your_secret_key' });