Tutorial: push trading strategy notifications to your mobile!

Jacob Plaster
Bitfinex
Published in
3 min readNov 10, 2019

Maybe you want to be notified whenever the market is about to moon or perhaps you have a sophisticated algorithmic strategy that requires constant monitoring, push notifications to your device is reason 3829 why Bitfinex is the superior trading platform.

In this tutorial we will use Nodejs to send a post request to the “v2/auth/w/expo/notify” endpoint which will then forward that notification to all of the devices paired with my api key/secret.

The expo/notify endpoint uses the Bitfinex mobile application as a middle man to display the notification on the mobile operating system. For this reason, we will need to make sure that we have either the Iphone or the Android app installed on our device and paired with our account. For more info on how to pair your mobile device, please go to our website.

To get started we need to make sure we have the request library since we are going to be communicating with Bitfinex’s REST API.

npm install request

Next we need to require the packages that we are going to use and also create some variables to hold both our API key and secret.

const crypto = require('crypto')
const request = require('request')
const apiKey = 'tEVt*****************************'
const apiSecret = '0QeNT*********************************'

Now we will create the post payload to send to the server. Here, “title” will be the main subject of the notification and “body” will be the message.

const url = 'v2/auth/w/expo/notify'
const nonce = (Date.now() * 1000).toString()
const body = {
payload: {
title: 'EMA crossed',
body: 'BTC about to mooon!'
}
}
const rawBody = JSON.stringify(body)

Before we send out our notification we first need to sign the payload with our API keys, this proves to Bitfinex that we own the API keys and also that the payload data has not changed during transport.

let signature = `/api/${url}${nonce}${rawBody}`signature = crypto
.createHmac('sha384', apiSecret)
.update(signature)
.digest('hex')
const options = {
url: `https://api.bitfinex.com/${url}`,
headers: {
'bfx-nonce': nonce,
'bfx-apikey': apiKey,
'bfx-signature': signature
},
json: body
}
request.post(options, (error, response, body) => console.log(body))

Annnddd done! By running this script you should receive a notification directly to your phone with the text “EMA crossed — BTC about to moon!” which looks something like this:

For the full code example of the above then check out this gist.

For a full overview of the Bitfinex API documentation, refer to the following page: docs.bitfinex.com/docs. For any issues or concerns, please refer to bitfinex.com/support for assistance.

Stay up to date with Bitfinex on Twitter, Facebook, Telegram & Instagram.

We’ve recently open-sourced a number of the development libraries most essential to us. If you are interested in learning more about these, please visit our Github.

Join us on our mission to create the most innovative & industry-leading cryptocurrency exchange.

--

--