Skip to content

Latest commit

 

History

History
1111 lines (817 loc) · 13.2 KB

rpc.adoc

File metadata and controls

1111 lines (817 loc) · 13.2 KB

RPC protocol

Examples

See here

An npm package is available here

Connection

For each WS connection, gateway will send following message as initial message

Name Type Description

hello

object

        sid

string

Session id

        isNew

boolean

Whether or not session is a new one

Examples
{
    "hello":{
        "sid":"12345",
        "isNew":false
    }
}

Call a method

Name Type Description

m

string

Method name

p

object

Parameters dictionary

i

integer

Request id (use to match reply)

Note

If i property is not set, no reply or error will be returned by gateway

Examples
{
    "m":"subscribeToOrderBooks",
    "p":{
        "exchange":"bittrex",
        "pairs":["USDT-BTC","USDT-NEO"]
    },
    "i":1
}

Result for a successful method call

Name Type Description

i

integer

Request id (ie: as provided when calling method)

r

object,array,scalar

Result (type depends on method)

Examples
{
    "i":1,
    "r":true
}

Error for an unsuccessful method call

Name Type Description

i

integer

Request id (ie: as provided when calling method)

e

object

Error object

        t

string

Error type (internal_error,invalid_request,invalid_params,invalid_method)

        d

object,array,scalar

Extra error data (optional) (type depends on method)

Examples
{
    "e":{
        "t":"invalid_params",
        "m":"'dummy' exchange is not supported"
    },
    "i":2
}

Notifications

Name Type Description

n

string

Notification type

d

object

Notification data

Note

See Notifications documentation for a list of possible notifications

Examples
{
    "n":"trades",
    "d":{
        "pair":"USDT-BTC",
        "data":[
            {
                "quantity":0.04692557,
                "rate":8274.8261,
                "price":388.300931393377,
                "orderType":"sell",
                "timestamp":1511392363.357
            }
        ],
        "exchange":"bittrex"
    }
}

Supported methods

getPairs

Mandatory arguments
Name Type Description

exchange

string

Exchange identifier

Optional arguments

Name Type Default Description

filter

object

Used to list pairs matching a given currency or base currency

        currency

string

Used to list only pairs matching a given currency

        baseCurrency

string

Used to list only pairs matching a given base currency (will be ignored if filter.currency is set)

Result

Result will be a dictionary using pairs as keys

Name Type Description

pair

string

Pair name X-Y

        pair

string

Pair name X-Y (same as pair key)

        baseCurrency

string

Base currency (part X in pair X-Y)

        currency

string

Currency (part Y in pair X-Y)

Examples

Request

{
    "i":1,
    "m":"getPairs",
    "p":{
        "exchange":"bittrex"
    }
}

Reply

{
    "i":1,
    "r":{
        "BTC-1ST":{
            "pair":"BTC-1ST",
            "baseCurrency":"BTC",
            "currency":"1ST"
        },
        "BTC-2GIVE":{
            "pair":"BTC-2GIVE",
            "baseCurrency":"BTC",
            "currency":"2GIVE"
        },
        ...
        "USDT-BTG":{
            "pair":"USDT-BTG",
            "baseCurrency":"USDT",
            "currency":"BTG"
        }
    }
}

subscribeToTickers

Mandatory arguments
Name Type Description

exchange

string

Exchange identifier

pairs

string[]

Array of pairs to subscribe to (X-Y)

Optional arguments

Name Type Default Description

reset

boolean

false

If true, previous subscriptions will be discarded

Result

Result will be boolean value true if method executed successfully. An error will be returned otherwise

Examples

Request

{
    "i":1,
    "m":"subscribeToTickers",
    "p":{
        "exchange":"bittrex",
        "pairs":["USDT-BTC"],
        "reset":false
    }
}

Reply

{
    "i":1,
    "r":true
}

unsubscribeFromTickers

Mandatory arguments
Name Type Description

exchange

string

Exchange identifier

pairs

string[]

Array of pairs to unsubscribe from (X-Y)

Result

Result will be boolean value true if method executed successfully. An error will be returned otherwise

Examples

Request

{
    "i":1,
    "m":"unsubscribeFromTickers",
    "p":{
        "exchange":"bittrex",
        "pairs":["USDT-BTC"]
    }
}

Reply

{
    "i":1,
    "r":true
}

unsubscribeFromAllTickers

Mandatory arguments
Name Type Description

exchange

string

Exchange identifier

Result

Result will be boolean value true if method executed successfully. An error will be returned otherwise

Examples

Request

{
    "i":1,
    "m":"unsubscribeFromAllTickers",
    "p":{
        "exchange":"bittrex"
    }
}

Reply

{
    "i":1,
    "r":true
}

subscribeToOrderBooks

Mandatory arguments
Name Type Description

exchange

string

Exchange identifier

pairs

string[]

Array of pairs to subscribe to (X-Y)

Optional arguments

Name Type Default Description

reset

boolean

false

If true, previous subscriptions will be discarded

Result

Result will be boolean value true if method executed successfully. An error will be returned otherwise

Examples

Request

{
    "i":1,
    "m":"subscribeToOrderBooks",
    "p":{
        "exchange":"bittrex",
        "pairs":["USDT-BTC"],
        "reset":false
    }
}

Reply

{
    "i":1,
    "r":true
}

unsubscribeFromOrderBooks

Mandatory arguments
Name Type Description

exchange

string

Exchange identifier

pairs

string[]

Array of pairs to unsubscribe from (X-Y)

Result

Result will be boolean value true if method executed successfully. An error will be returned otherwise

Examples

Request

{
    "i":1,
    "m":"unsubscribeFromOrderBooks",
    "p":{
        "exchange":"bittrex",
        "pairs":["USDT-BTC"]
    }
}

Reply

{
    "i":1,
    "r":true
}

unsubscribeFromAllOrderBooks

Mandatory arguments
Name Type Description

exchange

string

Exchange identifier

Result

Result will be boolean value true if method executed successfully. An error will be returned otherwise

Examples

Request

{
    "i":1,
    "m":"unsubscribeFromAllOrderBooks",
    "p":{
        "exchange":"bittrex"
    }
}

Reply

{
    "i":1,
    "r":true
}

resyncOrderBooks

Mandatory arguments
Name Type Description

exchange

string

Exchange identifier

pairs

string[]

Array of pairs to resync order books for (X-Y)

Result

Result will be boolean value true if method executed successfully. An error will be returned otherwise

Examples

Request

{
    "i":1,
    "m":"resyncOrderBooks",
    "p":{
        "exchange":"bittrex",
        "pairs":["USDT-BTC"]
    }
}

Reply

{
    "i":1,
    "r":true
}

subscribeToTrades

Mandatory arguments
Name Type Description

exchange

string

Exchange identifier

pairs

string[]

Array of pairs to subscribe to (X-Y)

Optional arguments

Name Type Default Description

reset

boolean

false

If true, previous subscriptions will be discarded

Result

Result will be boolean value true if method executed successfully. An error will be returned otherwise

Examples

Request

{
    "i":1,
    "m":"subscribeToTrades",
    "p":{
        "exchange":"bittrex",
        "pairs":["USDT-BTC"],
        "reset":false
    }
}

Reply

{
    "i":1,
    "r":true
}

unsubscribeFromTrades

Mandatory arguments
Name Type Description

exchange

string

Exchange identifier

pairs

string[]

Array of pairs to unsubscribe from (X-Y)

Result

Result will be boolean value true if method executed successfully. An error will be returned otherwise

Examples

Request

{
    "i":1,
    "m":"unsubscribeFromTrades",
    "p":{
        "exchange":"bittrex",
        "pairs":["USDT-BTC"]
    }
}

Reply

{
    "i":1,
    "r":true
}

unsubscribeFromAllTrades

Mandatory arguments
Name Type Description

exchange

string

Exchange identifier

Result

Result will be boolean value true if method executed successfully. An error will be returned otherwise

Examples

Request

{
    "i":1,
    "m":"unsubscribeFromAllTrades",
    "p":{
        "exchange":"bittrex"
    }
}

Reply

{
    "i":1,
    "r":true
}

subscribeToKlines

Mandatory arguments
Name Type Description

exchange

string

Exchange identifier

pairs

string[]

Array of pairs to subscribe to (X-Y)

Optional arguments

Name Type Default Description

interval

string

Depends on exchange

Klines interval (ex: 5m)

reset

boolean

false

If true, previous subscriptions will be discarded

Result

Result will be boolean value true if method executed successfully. An error will be returned otherwise

Examples

Request

{
    "i":1,
    "m":"subscribeToKlines",
    "p":{
        "exchange":"binance",
        "pairs":["USDT-NEO"],
        "interval":"5m",
        "reset":false
    }
}

Reply

{
    "i":1,
    "r":true
}

unsubscribeFromKlines

Mandatory arguments
Name Type Description

exchange

string

Exchange identifier

pairs

string[]

Array of pairs to unsubscribe from (X-Y)

Optional arguments

Name Type Default Description

interval

string

None

Klines interval (ex: 5m). If not set, will unsubscribe for all intervals

Result

Result will be boolean value true if method executed successfully. An error will be returned otherwise

Examples

Request

{
    "i":1,
    "m":"unsubscribeFromKlines",
    "p":{
        "exchange":"binance",
        "pairs":["USDT-NEO"]
    }
}

Reply

{
    "i":1,
    "r":true
}

unsubscribeFromAllKlines

Mandatory arguments
Name Type Description

exchange

string

Exchange identifier

Result

Result will be boolean value true if method executed successfully. An error will be returned otherwise

Examples

Request

{
    "i":1,
    "m":"unsubscribeFromAllKlines",
    "p":{
        "exchange":"binance"
    }
}

Reply

{
    "i":1,
    "r":true
}

unsubscribe

Used to cancel all subscriptions for a given exchange or all exchanges

Mandatory arguments
Name Type Description

Optional arguments

Name Type Default Description

exchange

string

Exchange identifier (if not defined, subscriptions will be cancelled for all exchanges)

Result

Result will be boolean value true if method executed successfully. An error will be returned otherwise

Examples

Request

{
    "i":1,
    "m":"unsubscribe",
    "p":{
        "exchange":"bittrex"
    }
}

Reply

{
    "i":1,
    "r":true
}