Skip to content

Database Notifications

Gabrielle Zhou edited this page Oct 8, 2018 · 2 revisions

In CYBEX, the websocket connection is used for notifications when objects in the database change or a particular event (such as filled orders) occur.

We have the following subscriptions available:

set_subscribe_callback( int identifier, bool clear_filter ):


To simplify development a global subscription callback can be registered.


Every notification initiated by the full node will carry a particular id as defined by the user with the identifier parameter.


set_pending_transaction_callback(int identifier):


Notifications for incoming unconfirmed transactions.



subscribe_to_market(int identifier, asset_id a, asset_id b)):


Subscribes to market changes in market a:b and sends notifications with id identifier.


get_full_accounts(array account_ids, bool subscribe):


Returns the full account object for the accounts in array account_ids and subscribes to changed to that account if subscribe is set to True.



Let’s first get a global scubscription callback to disctinguish our notifications from regular RPC calls:

> {"id":4,"method":"call","params":[DATABASE_API_ID,"set_subscribe_callback",[SUBSCRIPTION_ID, true]]}

This call above will register SUBSCRIPTION_ID as id for notifications.

Now, whenever you get an object from the witness (e.g. via get_objects) you will automatically subscribe to any future changes of that object.

After calling set_subscribe_callback the witness will start to send notices every time the object changes:

< {
    "method": "notice"
    "params": [
        SUBSCRIPTION_ID,
        [[
            { "id": "2.1.0", ...  },
            { "id": ...  },
            { "id": ...  },
            { "id": ...  }
        ]]
    ],
}

Example Session

Here is an example of a full session:

> {"method": "call", "params": [1, "login", ["", ""]], "id": 2}
< {"id":2,"result":true}
> {"method": "call", "params": [1, "database", []], "id": 3}
< {"id":3,"result":2}
> {"method": "call", "params": [1, "history", []], "id": 4}
< {"id":4,"result":3}
> {"method": "call", "params": [2, "set_subscribe_callback", [5, false]], "id": 6}
< {"id":6,"result":null}
> {"method": "call", "params": [2, "get_objects", [["2.1.0"]]], "id": 7}
(plenty of data coming in from this point on)

开发者社区

了解CYBEX

文档中心

DEVELOPERS

GETTING STARTED

DOCUMENTATION

Clone this wiki locally