Crypto Bot API
    Preparing search index...

    Class ClientEmitter

    Main class for work with API for Node.js

    Library for Node.js default export this class

    Hierarchy (View Summary)

    Index

    Constructors

    • Create class instance

      Parameters

      • apiKey: string

        Crypto Bot API key, looks like '1234:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'

      • endpoint: string = 'mainnet'

        API endpoint url or 'mainnet' or 'testnet' for hardcoded in library endpoint urls

      Returns ClientEmitter

    Properties

    CheckStatus: typeof CheckStatus = CheckStatus

    Access to CheckStatus enumeration, used in Check type, Client.getChecks and Client.getChecksPaginate methods options

    CurrencyType: typeof CurrencyType = CurrencyType

    Access to CurrencyType enumeration, used in Invoice type

    DetailedCurrencyType: typeof DetailedCurrencyType = DetailedCurrencyType

    Access to DetailedCurrencyType enumeration, used in Store.getCurrencies and Client.getCurrency methods results

    InvoiceStatus: typeof InvoiceStatus = InvoiceStatus

    Access to InvoiceStatus enumeration, used in Invoice type, Client.getInvoices and Client.getInvoicesPaginate methods options

    TransferStatus: typeof TransferStatus = TransferStatus

    Access to TransferStatus enumeration, used in Transfer type, Client.getTransfers and Client.getTransfersPaginate methods options

    _transport: Transport

    Transport class instance

    _apiKey: string

    Api key

    _events: { [key: string]: ((...args: any) => any)[] } = {}

    Event listeners store

    _server: Server

    Handling webhooks created Node.js built-in server

    Methods

    • Call backend API method directly (types unsafe)

      Use it if backend API update (add new methods, change request or response fileds), but library is not

      Parameters

      • method: string

        Backend API method name

      • options: object = {}

        Backend API options object

      Returns Promise<any>

      Promise, what resolved to backend API response result field value

      Error - If there is an error sending request to backend API or parsing response

    • Close created handling webhooks server

      Returns Promise<void>

      Promise, what resolved void

      Error - If server not was started or closing error

    • Create handling webhooks server

      If you app work behind proxy and no need create HTTPS server, no pass key and cert fields and add http field with true value: { http: true }

      Note: if you want to use self-signed certificate you must uploat it in CryptoBot API application settings

      Parameters

      • serverOptions: SecureContextOptions & TlsOptions & ServerOptions<
            typeof IncomingMessage,
            typeof ServerResponse,
        > & { http?: boolean }

        Node.js built-in server options

      • secretPath: string = '/'

        Webhooks secret path, processing webhooks takes place only on it

      • listenOptions: ListenOptions = ...

        Node.js built-in server listen options

      Returns Promise<void>

      Promise, what resolved void

      Error - If create server error

    • Delete check

      Parameters

      • id: number

        Check identifier

      Returns Promise<boolean>

      Promise, what resolved to boolean operation result status

      Error - If there is an error sending request to backend API or parsing response error

    • Delete invoice

      Parameters

      • id: number

        Invoice identifier

      Returns Promise<boolean>

      Promise, what resolved to boolean operation result status

      Error - If there is an error sending request to backend API or parsing response error

    • Get API app balance value for passed currency

      Call Client.getBalances method to fetch balances information

      Parameters

      Returns Promise<string>

      Promise, what resolved to API app available balance value for passed currency

      Error - If there is an error sending request to backend API or parsing response

    • Get API app balance value for passed currency

      Call Client.getBalances method to fetch balances information

      Parameters

      Returns Promise<string>

      Promise, what resolved to API app balance on hold value for passed currency

      Error - If there is an error sending request to backend API or parsing response

    • Get API app balances infomation

      Use toBalances backend API result convert function

      Returns Promise<Balances>

      Promise, what resolved to API app balances infomation object

      Error - If there is an error sending request to backend API or parsing response

    • Get API supported currencies infomation

      Use toCurrencies backend API result convert function

      Parameters

      • OptionalisForce: boolean

        If true, return fresh data from backend API, not from cache

      Returns Promise<Currencies>

      Promise, what resolved to API supported currencies infomation object

      Error - If there is an error sending request to backend API or parsing response

    • Get currency with passed code infomation

      Call Store.getCurrencies method to fetch currencies information

      Parameters

      • currencyCode: CurrencyCode

        Currency code

      • isForce: boolean = false

        If true, return fresh data from backend API, not from cache

      Returns Promise<Currency>

      Promise, what resolved to currency with passed code infomation object or null, if currency with passed code not exists

      Error - If there is an error sending request to backend API or parsing response

    • Get one exchange rate infomation to passed currencies pair

      Call Store.getExchangeRates method to fetch exchange rates information, Store.getCurrencies method to fetch currencies information and use getExchageRate function to get signle exchange rate

      Parameters

      • source: string

        Source currency code

      • target: string

        Target currency code

      • isForce: boolean = false

        If true, return fresh data from backend API, not from cache

      Returns Promise<string>

      Promise, what resolved to exchange rate or zero, if currencies pair not exists

      Error - If there is an error sending request to backend API or parsing response

    • Get API supported currencies exchange rate infomation

      Use toExchangeRates backend API result convert function

      Parameters

      • OptionalisForce: boolean

        If true, return fresh data from backend API, not from cache

      Returns Promise<ExchangeRates>

      Promise, what resolved to API supported currencies exchange rate infomation object

      Error - If there is an error sending request to backend API or parsing response

    • Get associated with passed API key app infomation

      Use toMe backend API result convert function

      Parameters

      • isForce: boolean = false

        If true, return fresh data from backend API, not from cache

      Returns Promise<Me>

      Promise, what resolved to associated with passed API key app infomation object

      Error - If there is an error sending request to backend API or parsing response

    • Get associated with passed API key app statistics

      Use toStats backend API result convert function

      Parameters

      Returns Promise<Stats>

      Promise, what resolved to associated with passed API key app statistics object

      Error - If there is an error sending request to backend API or parsing response

    • Unsubscribes from paid event

      Parameters

      • event: "paid"

        paid event name

      • listener: (invoice: Invoice, requestDate: Date) => any

        Event listener with invoice and requestDate callback parameters

      Returns void

    • Subscribes to paid event

      See ClientEmitter._emit to more about event listener

      Parameters

      • event: "paid"

        paid event name

      • listener: (invoice: Invoice, requestDate: Date) => any

        Event listener with invoice and requestDate callback parameters

      Returns void

    • Emit event to listeners

      Parameters

      • event: "paid"

        paid event name

      • invoice: Invoice

        Paid invoice information object

      • requestDate: Date

        Date of occurrence of event, need to filter old event. If server is not available, backend API try resend webhooks by timeout, so when server becomes available again, many old events will be sent from backend API.

      Returns void

    • Handling webhook data, send response and emit events

      Parameters

      • data: any

        Parsed request body

      • req: IncomingMessage

        Node.js built-in IncomingMessage object

      • res: ServerResponse

        Node.js built-in ServerResponse object

      Returns void