Class RestAuthenticatedClient

The RestAuthenticatedClient is used to make authenticated requests to the IDEX API. It includes methods that make requests on behalf of a specific wallet such as creating and cancelling orders.

  • The client requires the following properties to automatically handle authentication of requests:
  • Optionally, a sandbox option can be set to true in order to point to the IDEX Sandbox API.

Example

import { RestAuthenticatedClient } from '@idexio/idex-sdk';

// Edit the values before for your environment
const authenticatedClient = new RestAuthenticatedClient({
sandbox: false,
apiKey: '1f7c4f52-4af7-4e1b-aa94-94fac8d931aa',
apiSecret: 'axuh3ywgg854aq7m73oy6gnnpj5ar9a67szuw5lclbz77zqu0j',
walletPrivateKey: '0x...'
});


See

Accessors

When creating an authenticated client, a RestPublicClient is automatically created and can be used based on the config given for this client.

Example

import { RestAuthenticatedClient } from '@idexio/idex-sdk';

// Edit the values before for your environment
const client = new RestAuthenticatedClient({
sandbox: true,
apiKey: '1f7c4f52-4af7-4e1b-aa94-94fac8d931aa',
apiSecret: 'axuh3ywgg854aq7m73oy6gnnpj5ar9a67szuw5lclbz77zqu0j',
walletPrivateKey: '0x...'
});

const wallets = await client.getWallets();


See

client RestPublicClient

Constructor

Deposits & Withdrawals

Fills & Historical

Orders

  • Create and submit an order to the matching engine.

    • It is recommended to use the OrderType enum when creating your requests. This provides inline documentation and ensures accuracy of the values.
    • Check out the RestRequestOrder type for an overview of the various parameters needed for different order types.

    Endpoint Parameters

    • HTTP Request: POST /v4/orders
    • Endpoint Security: Trade
    • API Key Scope: Trade
    • Pagination: None

    Type Parameters

    Parameters

    • params: RestRequestOrder & {
          type: T;
      }
    • signer: undefined | SignTypedData = ...

    Returns Promise<RestResponseGetOrder>

    • Returns the IDEXOrder which was created by the request.

    Example

    import { OrderType, OrderSide } from '@idexio/idex-sdk';

    const order = await client.createOrder({
    // always use the enum and define it first so that
    // the type of this params object change to the
    // appropriate interface with completion hints in IDE!
    type: OrderType.market,
    // this object is now narrowed to
    // interface: RestRequestOrderTypeMarket
    side: OrderSide.buy,
    nonce: uuidv1(),
    wallet: '0xA71C4aeeAabBBB8D2910F41C2ca3964b81F7310d',
    market: 'ETH-USD',
    quantity: '10.00000000'
    });


    See

Rewards & Payouts

Wallets & Positions

  • Override minimum Initial Margin Fraction for wallet for a market


    Endpoint Parameters

    • HTTP Request: POST /v4/initialMarginFractionOverride
    • Endpoint Security: Trade
    • API Key Scope: Read
    • Pagination:

    Type Parameters

    • R = IDEXInitialMarginFractionOverride

    Parameters

    • params: RestRequestSetInitialMarginFractionOverride
    • signer: undefined | SignTypedData = ...

    Returns Promise<R>

    • Returns an idex.IDEXInitialMarginFractionOverride IDEXInitialMarginFractionOverride object providing the details of the new setting.

WebSocket

Other

  • A convenience method that helps capture the appropriate value for the withdraw method's maximumGasFee parameter.

    • Calls publicClient.getGasFees and adds the defined maximumSlippagePercent to it.
    • User should then confirm the value is acceptable before calling withdraw method.
    • If gas were 0.05000000 and maximumSlippagePercent is 0.10000000 (10%) then result would be 0.05500000
    • The value is represented in USD.

    Parameters

    • __namedParameters: {
          bridgeTarget: BridgeTarget;
          maximumSlippagePercent: string;
      }
      • bridgeTarget: BridgeTarget

        The bridge target for the withdrawal of funds.

        • Utilize the BridgeTarget enum for convenience and auto-completion.
        • Automatically calculates the bridgeAdapterAddress & bridgeAdapterPayload parameters for the targeted network.

        See

        enum BridgeTarget

      • maximumSlippagePercent: string

        Maximum slippage percent in pips percent format (ex 0.10000000 for 10%)

        Example

        // 10%
        '0.10000000'

    Returns Promise<string>

    • A value indicating the max gas fee that should be allowed (in USD) based on the core gas fee with your maximumSlippagePercent added. This value should always be validated by your application before calling withdraw method with this as your maximumGasFee parameter.

    Example

    // returns the max gas fee in USD you will accept for a withdrawal
    const maximumGasFee = await client.calculateWithdrawalMaximumGasFee({
    bridgeTarget: BridgeTarget.STARGATE_ETHEREUM,
    // 10% slippage alllowed (default)
    maximumSlippagePercent: '0.10000000'
    });

    // never pay more than $1 USD in gas fees to withdrawal
    if (Number(maximumGasFee) >= 1) {
    throw new Error('Too Much Gas cost to Withdraw! ${maximumGasFee} USD >= 1 USD!');
    }

    const withdrawal = await client.withdraw({
    nonce: uuidv1(),
    wallet: '0xA71C4aeeAabBBB8D2910F41C2ca3964b81F7310d',
    quantity: '100.00000000',
    maximumGasFee,
    bridgeTarget: BridgeTarget.STARGATE_ETHEREUM
    });


    See