Trading

Create market/limit orders, stream order/trade changes across all of your exchanger accounts using unified API

Market order

Create Market order

Rest API

/**
 * @param exchanger: string
 * @param market: string
 * @param side: string [buy|sell]
 * @param amount: string
 */
const marketOrder = await egRest.createMarketOrder(
    'binance',
    'btc-usdt',
    'buy',
    '0.03'
);

/* Expected `marketOrder`:
{
    exchanger: string,
    market: string,
    order: {
        id: number,
        uuid: string,
        state: number,
        type: number,
        amountFilled: string,
        quoteAmountFilled: string,
        trades: [
            {
                id: number,
                price: string,
                amount: string,
                commission: string,
                commissionCurrency: string,
                commissionCurrencyId: number,
                execType: number
            },
            ...
        ]
    }
}*/

Socket RPC

/**
 * @param exchanger: string
 * @param market: string
 * @param side: string [buy|sell]
 * @param amount: string
 */
const marketOrder = await egRealtime.rpc.createMarketOrder(
    'binance',
    'btc-usdt',
    'sell',
    '0.003'
);

/* Expected `marketOrder`:
{
    exchanger: string,
    market: string,
    order: {
        id: number,
        uuid: string,
        state: number,
        type: number,
        amountFilled: string,
        quoteAmountFilled: string,
        trades: [
            {
                id: number,
                price: string,
                amount: string,
                commission: string,
                commissionCurrency: string,
                commissionCurrencyId: number,
                execType: number
            },
            ...
        ]
    }
}*/

Limit order

Create Limit order

Rest API

/**
 * @param exchanger: string
 * @param market: string
 * @param side: string [buy|sell]
 * @param amount: string
 */
const limitOrder = await egRest.createLimitOrder(
    'binance', 
    'btc-usdt',
    'buy',
    '1.03'
);

/* Expected `limitOrder`:
{
    exchanger: string,
    market: string,
    order: {
        id: number,
        uuid: string,
        state: number,
        type: number,
        amountFilled: string,
        quoteAmountFilled: string,
        trades: []
    }
}*/

Socket RPC

/**
 * @param exchanger: string
 * @param market: string
 * @param side: string [buy|sell]
 * @param amount: string
 */
const limitOrder = await egRealtime.rpc.createLimitOrder(
    'binance',
    'btc-usdt',
    'buy',
    '1.03'
);

/* Expected `limitOrder`:
{
    exchanger: string,
    market: string,
    order: {
        id: number,
        uuid: string,
        state: number,
        type: number,
        amountFilled: string,
        quoteAmountFilled: string,
        trades: []
    }
}*/

Cancel order

Cancel open order, using order UUID

Rest API

/**
 * @param exchanger: string
 * @param market: string
 * @param uuid: string
 */
const canceledOrder = await egRest.cancelOrder(
    'binance',
    'btc-usdt',
    '123e4567-e89b-12d3-a456-426614174000'
);

/* Expected `canceledOrder`:
{
    exchanger: string,
    market: string,
    order: {
        uuid: string,
        state: number,
        amountFilled: string,
        quoteAmountFilled: string
    }
}*/

Socket RPC

/**
 * @param exchanger: string
 * @param market: string
 * @param uuid: string
 */
const canceledOrder = await egRealtime.rpc.cancelOrder(
    'binance', 
    'btc-usdt',
    '123e4567-e89b-12d3-a456-426614174000'
);

/* Expected `canceledOrder`:
{
    exchanger: string,
    market: string,
    order: {
        uuid: string,
        state: number,
        amountFilled: string,
        quoteAmountFilled: string
    }
}*/

Open orders

Fetch Exchanger account open orders

Rest API

/**
 * @param exchanger: string
 * @param market: string
 */
const openOrders = await egRest.fetchOpenOrders(
    'binance',
    'btc-usdt'
);

/* Expected `openOrders`:
{
    exchanger: string,
    market: string,
    orders: [
        {
            market: string,
            uuid: string,
            side: number,
            state: number,
            limitPrice: string,
            amount: string,
            amountFilled: string,
            quoteAmountFilled: string
        },
        ...
    ]
}*/

Socket RPC

/**
 * @param exchanger: string
 * @param market: string
 */
const openOrders = await egRealtime.rpc.fetchOpenOrders(
    'binance',
    'btc-usdt'
);

/* Expected `openOrders`:
{
    exchanger: string,
    market: string,
    orders: [
        {
            market: string,
            uuid: string,
            side: number,
            state: number,
            limitPrice: string,
            amount: string,
            amountFilled: string,
            quoteAmountFilled: string
        },
        ...
    ]
}*/

Stream

Subscribe Open orders stream. New orders or any existing order changes

/**
 * @param exchanger: string
 * @param market: string
 */
const streamSubscription = egRealtime.stream.openOrders(
    'binance',
    'btc-usdt'
);

(async () => {
    for await (const event of streamSubscription.consumer()) {
        console.log('on-event', event.name, event.data);
        /* Expected `event.data`:
        {
            uuid: string,
            state: number,
            amount: string,
            amountFilled: string,
            quoteAmountFilled: string,
            eventType: number,
            market?: string,
            side?: number,
            limitPrice?: string
        }*/
    }
})();

My trades

Fetch Exchanger account trades

Rest API

/**
 * @param exchanger: string
 * @param market: string
 */
const myTrades = await egRest.fetchMyTrades(
    'binance',
    'btc-usdt'
);

/* Expected `myTrades`:
{
    exchanger: string,
    market: string,
    trades: [
        {
            id: number,
            orderId: string,
            time: number,
            price: string,
            amount: string,
            commission: string,
            side: number,
            execType: number
        },
        ...
    ]
}*/

Socket RPC

/**
 * @param exchanger: string
 * @param market: string
 */
const myTrades = await egRealtime.rpc.fetchMyTrades(
    'binance',
    'btc-usdt'
);

/* Expected `myTrades`:
{
    exchanger: string,
    market: string,
    trades: [
        {
            id: number,
            orderId: string,
            time: number,
            price: string,
            amount: string,
            commission: string,
            side: number,
            execType: number
        },
        ...
    ]
}*/

Stream

Subscribe my trades stream

/**
 * @param exchanger: string
 * @param market: string
 */
const streamSubscription = egRealtime.stream.myTrades(
    'binance',
    'btc-usdt'
);

(async () => {
    for await (const event of streamSubscription.consumer()) {
        console.log('event', event.name, event.data);
        /* Expected `event.data`:
        {
            id: number,
            orderId: string,
            time: number,
            price: string,
            amount: string,
            commission: string,
            side: number,
            execType: number
        }*/
    }
})();