• Public
  • Public/Protected
  • All

All requests to the Bity API should begin by creating an instance of this Order class. It's designed around the builder pattern, where methods are chained to declaratively configure the order.

Here are a few common examples to get you started!

NOTE: Even though this package does a best-effort approach to safety, it is possible to create invalid trading pairs, such as a fiat to fiat trade. In these cases, the Bity Exchange API will tell you it doesn't support this trade. The same goes for any unsupported currency codes or invalid amounts.

Create a simple order based on the input

This is the most common usage of Order. Depending on the currency codes the underlying available methods change. In this example, 'CHF' will cause a FiatInput to be assigned to Order.input, and 'BTC' will cause a CryptocurrencyOutput to be assigned to Order.output.

const order = (new Order())
  .setInput('CHF', '12.00')
    .do((input) => input
      .setOwner(new Owner(...))
    .do((output) => output

// Now use your order in a request.
const preparedOrder = await order.generateObjectForOrderCreation();


We can see here that generateObjectForOrderCreation can fail. This is because some fields may be invalid, such as a phone number, or an IBAN. This is one of many safety features we have put in to make it safe for developers to create orders with confidence. This is accomplished with Order.areAllFieldsValid().

Base an order on its output

It's common where a user would like to "pin" their exchange on its output price. This is particularly useful for cryptocurrency to fiat exchanges, when a client might want a precise amount of money for the trade to pay for something directly like their rent or some fast food.

const order = (new Order())
    .do((input) => input.setCryptoAddress('...'))
  .setOutput('CHF', '100.00')
    .do((output) => output.setOwner(new Owner(...)));

Amounts as strings?

Due to the nature of floating point numbers, precision is lost when using this format. For some people the loss of even the smallest denomination is unacceptable. The solution is to encode all amounts as strings so precision is kept throughout the entire process. As a developer, it's up to you how you use these NumericalStrings. You should never parseFloat() or parseInt() these strings unless you are using the result to display a warning, error, or similar message to the end-user.

In the event a developer tries to set an amount as a string, it will throw an error.





  • Returns Order



contactPerson: { email: Field<Email> }

Type declaration

Optional directionToBasePriceOn

directionToBasePriceOn: DIRECTIONS


do: (a: (b: any) => void) => this

Allows to stay within the context of configuring an order. By default it will be a no operation until setInput or setOutput is called.

Type declaration

    • (a: (b: any) => void): this
    • Parameters

      • a: (b: any) => void
          • (b: any): void
          • Parameters

            • b: any

            Returns void

      Returns this


input: Inputs


output: Outputs

Optional partnerFee

partnerFee: PartnerFee

Optional priceBreakdown

priceBreakdown: PriceBreakdown


status: string



  • areAllFieldsValid(): boolean
  • Returns boolean


  • generateObjectForOrderCreation(): Promise<any>
  • Returns Promise<any>

    On resolve, an object (which is intentionally abstracted to be robust against API changes) that will be sent to Bity's /order endpoint. On rejection, the error object.


  • Parameters

    Returns Order


  • Parameters

    • currencyCode: CurrencyCode

      A currency code supported by Bity. See /currencies endpoint for available codes.

    • amount: NumericalString

      A numerical string amount to retain precision, i.e. "14.3339".

    Returns Order


  • Parameters

    • currencyCode: CurrencyCode

      A currency code supported by Bity. See /currencies endpoint for available codes.

    • amount: NumericalString

      A numerical string amount to retain precision, i.e. "14.3339".

    Returns this


  • Parameters

    Returns Order


Static fromBookmarkModify

  • Parameters

    Returns Order | never

Static toBookmark

  • Parameters

    • order: Order
    • direction: string
    • label: string

    Returns BookmarkTypes | never

Generated using TypeDoc