Filter on Coinbase Events#

DEPRECATED

Apperate and its features (including this feature) are deprecated.

Want to send alerts on real-time cryptocurrency pricing? Once you’ve connected to Coinbase data, you can filter on Coinbase events.

Here you’ll use the Rules API to filter on Coinbase events.

Here’s what you’ll do:

  • Identify your Coinbase connector’s target dataset

  • Determine crypto event criteria

  • Create a rule based on that criteria

Doing all these things empowers you to filter on and act on Coinbase events.

Identify Your Coinbase Target Dataset#

Each Coinbase connector streams cryptocurrency pricing data to an Apperate dataset–a database with additional services. The rule’s first ingredient is the Coinbase connector dataset. You can determine the dataset in the Console or using the API or Console.

API#

The following request uses the Connectors API to get connector information.

Example request:

https://api.iex.cloud/v1/connectors/connector/YOUR_CONNECTOR?token=YOUR_TOKEN

Example Response:

[
  {
    "connectorType": "COINBASE",
    "datasetId": "YOUR_DATASET",
    "description": "",
    "id": "YOUR_CONNECTOR",
    "selectedStream": "ticker",
    "state": {
      "jobId": "your-connector",
      "status": "running"
    },
    "streams": [
      {
        "id": "ticker"
      }
    ],
    "updated": "2023-04-10T14:51:52.000Z",
    "wait": false
  }
]

The datasetId attribute identifies the target dataset.

Console#

Go to Data Sources and click on your connector Data Source. Your Source details appear, including the name of your Target Dataset.

Now that your know the Coinbase dataset, you can determine event criteria to trigger on.

Determine Event Criteria#

Rule conditions compare a fact with a value. Decide on fact values to use in your rule conditions. You can get the dataset schema using the API or if you’re creating a rule in the console, select facts via the UI.

API#

Here’s how to use the GET /rules/schema endpoint to get facts from dataset entities.

Request:

curl -X GET "https://api.iex.cloud/v1/rules/schema?token=YOUR_SECRET_TOKEN" \
| jq '.schema.workspaces[] | select(.workspace=="YOUR_WORKSPACE").namespaces[] | select(.namespace=="DATASET").entities[]'

Response (truncated for demo purposes):

{
  "entity": "JIM_COIN_03",
  "description": "Platform Dataset",
  "facts": [
    {
      "label": "COLUMN: best_ask",
      "value": "best_ask",
      "type": "number",
      "isLookup": false,
      "weightKey": "PLATFORM_DATASET"
    },
    {
      "label": "COLUMN: best_ask_size",
      "value": "best_ask_size",
      "type": "number",
      "isLookup": false,
      "weightKey": "PLATFORM_DATASET"
    },
    // ... more facts
},
// ... more entities

The response includes facts for each dataset entity, including your Coinbase connector’s target dataset.

Console#

In the Console, you can browse Coinbase target dataset facts.

Important

As you examine your dataset schema and data, make sure to determine the following items for your rule:

  • Property conditions to trigger on.

  • Additional properties to optionally include in your output.

Examine Fact Values#

You can use the GET /data to get fact values.

Request:

https://api.iex.cloud/v1/data/YOUR_WORKSPACE/YOUR_DATASET?last=50&token=YOUR_TOKEN

Response (truncated for demo purposes):

[
  {
    "best_ask": 28540.14,
    "best_ask_size": 0.01979051,
    "best_bid": 28538.7,
    "best_bid_size": 0.03036077,
    "high_24h": 28595.33,
    "last_size": 3.5e-7,
    "low_24h": 27892.76,
    "open_24h": 27918.82,
    "price": 28540.14,
    "product_id": "BTC-USD",
    "sequence": 58226268645,
    "side": "buy",
    "time": "2023-04-10T16:33:16.271763Z",
    "trade_id": 519670179,
    "type": "ticker",
    "volume_24h": 8394.30464029,
    "volume_30d": 549665.54274759
  },
  {
    "best_ask": 28540.9,
    "best_ask_size": 0.03788009,
    "best_bid": 28538.7,
    "best_bid_size": 0.03036077,
    "high_24h": 28595.33,
    "last_size": 0.00104439,
    "low_24h": 27892.76,
    "open_24h": 27918.82,
    "price": 28540.9,
    "product_id": "BTC-USD",
    "sequence": 58226268608,
    "side": "buy",
    "time": "2023-04-10T16:33:16.228944Z",
    "trade_id": 519670178,
    "type": "ticker",
    "volume_24h": 8394.30463994,
    "volume_30d": 549665.54274724
  },
  // ...

The response above includes BitCoin bid and ask prices and volume.

See also

See Querying Data to learn more about querying dataset data.

Create a Rule#

You can create rules programatically using Rules API’s POST /rules/create method or create rules manually in the Console.

Here’s JavaScript code that demonstrates creating a rule:

'use strict';

const Request = require('request-promise-native');

function connect() {
  Request({
    method: 'POST',
    url: 'https://api.iex.cloud/v1/rules/create',
    json: {
      token: 'YOUR_SECRET_TOKEN',
      ruleName: "Your Rule",
      type: "any",
      index: [ "YOUR_WORKSPACE:DATASET:YOUR_COINBASE_DATASET:price" ],
      conditions: [
        ["$index[0]",">",28000],
      ],
      outputs: [
        {
          method: "dataset",
          dataset: "YOUR_OUTPUT_DATASET",
          frequency: 60
        }
      ],
      additionalIndex: [
        "YOUR_WORKSPACE:DATASET:YOUR_COINBASE_DATASET:volume_24h",
        "YOUR_WORKSPACE:DATASET:YOUR_COINBASE_DATASET:volume_30d",
      ]
    },
  }).then((body) => {
    console.log(body);
  }).catch((err) => {
    console.log("Error in request", err);
  });
}

connect();

The code above creates a rule that triggers if the Coinbase product price exceeds 28000. The index and conditions elements specify the fact and fact condition, respectively.

index: [ "YOUR_WORKSPACE:DATASET:YOUR_COINBASE_DATASET:price" ],
conditions: [
  ["$index[0]",">",28000],
],

See also

Please see Fact Characteristics to learn more about specifying rule facts.

On triggering, the rule sends output to a dataset called YOUR_OUTPUT_DATASET waiting 60 seconds between sending subsequent messages. The outputs element specifies this.

outputs: [
  {
    method: "dataset",
    dataset: "YOUR_OUTPUT_DATASET",
    frequency: 60
  }
],

Apperate also supports these output methods:

The output includes the cryptocurrency product’s price and the product’s average trade volume over the past 24 hours and average trade volume over the past 30 days. The request’s index array and additionalIndex array specify these facts respectively.

index: [ "YOUR_WORKSPACE:DATASET:YOUR_COINBASE_DATASET:price" ],
// ...
additionalIndex: [
  "YOUR_WORKSPACE:DATASET:YOUR_COINBASE_DATASET:volume_24h",
  "YOUR_WORKSPACE:DATASET:YOUR_COINBASE_DATASET:volume_30d",
]

Create Your Rule Using JavaScript#

You can copy the above code into a .js file and modify the code to create your rule. You can execute your script using Node, like this:

node your-file.js

Example response:

{ id: '3df67331-2ae9-4f26-ad30-47051dd7ad57', weight: 1 }

Apperate creates the rule and activates it automatically.

Apperate tracks the events that ran, those events that passed and failed the rule conditions, and the outputs sent.

Note

See Managing Rules for pausing and restarting your rule.

You can check your rule’s statistics at Rules or using the Rules API. Use either to monitor the total number of events, the number of those events that pass matching your criteria, and the number outputs sent.

Request:

https://api.iex.cloud/v1/rules/info/YOUR_RULE_ID?token=YOUR_TOKEN

Response:

[
  {
    "id": "53b60659-02ab-475e-ad18-7adc9d29cd9d",
    "name": "Your Rule",
    "dateCreated": "2023-04-10",
    "dateUpdated": "2023-04-10",
    "isActive": true,
    "ran": "256",
    "passed": "256",
    "sent": "2",
    "failed": 0,
    "evaluated": "1681144401671"
  }
]

There you have it! Now you know how to filter on Coinbase data events and notifications about them.

Additional Resources#

Connect to Coinbase Data

Create a Rule Using the API

Output Rule Event Data to a Dataset

Rules API

Connectors API

Datasets API