Tradehub.Stream (Tradehub v0.1.7) View Source

This module enables a power to connect with the official Tradehub Demex websocket gateway and provides all functionalities described in this module.

The module uses Phoenix PubSub to broadcast messages across the system

Link to this section Summary

Functions

Subscribes to the account_trades.[account] channel to request upto 100 trades of the given account.

Subscribes to the account_trades_by_market.[market].[account] channel to request trades of the given account within a market.

Subscribes to the balances.[account] channel of the given account to request latest balance updates.

Subscribes to the books.[market] channel to request the latest orderbook of the given market.

Subscribes to the candlesticks.[market].[resolution] channel to request latest candlesticks of the market in the resolution timeframe.

Subscribes to the leverages.[account] channel to request latest leverages information of the given account.

Subscribes to the leverages_by_market.[market].[account] channel to request latest leverages information of the given account within a market.

Subscribes to the market_stats channel to request the latest statistics of the market.

Subscribes to the orders.[account] channel to request the latest orders of the given account.

Subscribes to the orders_by_market.[market].[account] channel to request the latest orders of the given account within a specific market.

Subscribes to the positions.[account] channel to request the latest positions of the given account.

Subscribes to the positions_by_market.[market].[account] channel to request the latest positions of the given account within a particular market

Subscribes to the recent_trades.[market] channel to request the recent trades of the given market.

The utility function to subscribe into the channel, and broadcast messages if any to the Tradehub.PubSub with a specific topic name.

The utility function to unsubscribe an available channel

Link to this section Functions

Specs

account_trades(String.t()) :: :ok | {:error, reason :: any()}

Subscribes to the account_trades.[account] channel to request upto 100 trades of the given account.

A topic named account_trades.[account] in the Tradehub.PubSub will automatically created to handle incomming messages of this subscription.

Examples

iex> alias Phoenix.PubSub
iex> PubSub.subscribe Tradehub.PubSub, "account_trades.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"
iex> Tradehub.Stream.account_trades("swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a")
iex> Process.info(self(), :messages)
iex> Tradehub.Stream.unsubscribe "account_trades.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"
Link to this function

account_trades_by_market(market, account)

View Source

Specs

account_trades_by_market(String.t(), String.t()) ::
  :ok | {:error, reason :: any()}

Subscribes to the account_trades_by_market.[market].[account] channel to request trades of the given account within a market.

A topic named account_trades_by_market.[market].[account] in the Tradehub.PubSub will automatically created to handle incomming messages of this subscription.

Examples

iex> alias Phoenix.PubSub
iex> PubSub.subscribe Tradehub.PubSub, "account_trades_by_market.swth_eth1.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"
iex> Tradehub.Stream.account_trades_by_market("swth_eth1", "swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a")
iex> Process.info(self(), :messages)
iex> Tradehub.Stream.unsubscribe "account_trades.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"

Specs

balances(String.t()) :: :ok | {:error, reason :: any()}

Subscribes to the balances.[account] channel of the given account to request latest balance updates.

A topic named balances.[account] in the Tradehub.PubSub will automatically created to handle incomming messages of this subscription.

Examples

iex> alias Phoenix.PubSub
iex> PubSub.subscribe Tradehub.PubSub, "balances.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"
iex> Tradehub.Stream.balances("swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a")
iex> Process.info(self(), :messages)
iex> Tradehub.Stream.unsubscribe "balances.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"

Specs

books(String.t()) :: :ok | {:error, reason :: any()}

Subscribes to the books.[market] channel to request the latest orderbook of the given market.

A topic named books.[market] in the Tradehub.PubSub will automatically created to handle incomming messages of this subscription.

Examples

iex> alias Phoenix.PubSub
iex> PubSub.subscribe Tradehub.PubSub, "books.swth_eth1"
iex> Tradehub.Stream.books("swth_eth1")
iex> Process.info(self(), :messages)
iex> Tradehub.Stream.unsubscribe "books.swth_eth1"
Link to this function

candlesticks(market, resolution)

View Source

Specs

candlesticks(String.t(), String.t()) :: :ok | {:error, reason :: any()}

Subscribes to the candlesticks.[market].[resolution] channel to request latest candlesticks of the market in the resolution timeframe.

A topic named candlesticks.[market].[resolution] in the Tradehub.PubSub will automatically created to handle incomming messages of this subscription.

Examples

iex> alias Phoenix.PubSub
iex> PubSub.subscribe Tradehub.PubSub, "candlesticks.swth_eth1.30"
iex> Tradehub.Stream.candlesticks("swth_eth1", 30)
iex> Process.info(self(), :messages)
iex> Tradehub.Stream.unsubscribe "candlesticks.swth_eth1.30"

Specs

leverages(String.t()) :: :ok | {:error, reason :: any()}

Subscribes to the leverages.[account] channel to request latest leverages information of the given account.

A topic named leverages.[account] in the Tradehub.PubSub will automatically created to handle incomming messages of this subscription.

Examples

iex> alias Phoenix.PubSub
iex> PubSub.subscribe Tradehub.PubSub, "leverages.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"
iex> Tradehub.Stream.leverages("swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a")
iex> Process.info(self(), :messages)
iex> Tradehub.Stream.unsubscribe "leverages.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"
Link to this function

leverages_by_market(market, account)

View Source

Specs

leverages_by_market(String.t(), String.t()) :: :ok | {:error, reason :: any()}

Subscribes to the leverages_by_market.[market].[account] channel to request latest leverages information of the given account within a market.

A topic named leverages_by_market.[market].[account] in the Tradehub.PubSub will automatically created to handle incomming messages of this subscription.

Examples

iex> alias Phoenix.PubSub
iex> PubSub.subscribe Tradehub.PubSub, "leverages_by_market.swth_eth1.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"
iex> Tradehub.Stream.leverages_by_market("swth_eth1", "swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a")
iex> Process.info(self(), :messages)
iex> Tradehub.Stream.unsubscribe "leverages_by_market.swth_eth1.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"

Specs

market_stats() :: :ok | {:error, reason :: any()}

Subscribes to the market_stats channel to request the latest statistics of the market.

A topic named market_stats in the Tradehub.PubSub will automatically created to handle incomming messages of this subscription.

Examples

iex> alias Phoenix.PubSub
iex> PubSub.subscribe Tradehub.PubSub, "market_stats"
iex> Tradehub.Stream.market_stats
iex> Process.info(self(), :messages)
iex> Tradehub.Stream.unsubscribe "market_stats"

Specs

orders(String.t()) :: :ok | {:error, reason :: any()}

Subscribes to the orders.[account] channel to request the latest orders of the given account.

A topic named orders.[account] in the Tradehub.PubSub will automatically created to handle incomming messages of this subscription.

Examples

iex> alias Phoenix.PubSub
iex> PubSub.subscribe Tradehub.PubSub, "orders.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"
iex> Tradehub.Stream.orders("swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a")
iex> Process.info(self(), :messages)
iex> Tradehub.Stream.unsubscribe "orders.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"
Link to this function

orders_by_market(market, account)

View Source

Specs

orders_by_market(String.t(), String.t()) :: :ok | {:error, reason :: any()}

Subscribes to the orders_by_market.[market].[account] channel to request the latest orders of the given account within a specific market.

A topic named orders_by_market.[market].[account] in the Tradehub.PubSub will automatically created to handle incomming messages of this subscription.

Examples

iex> alias Phoenix.PubSub
iex> PubSub.subscribe Tradehub.PubSub, "orders_by_market.swth_eth1.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"
iex> Tradehub.Stream.orders_by_market("swth_eth1", "swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a")
iex> Process.info(self(), :messages)
iex> Tradehub.Stream.unsubscribe "orders_by_market.swth_eth1.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"

Specs

positions(String.t()) :: :ok | {:error, reason :: any()}

Subscribes to the positions.[account] channel to request the latest positions of the given account.

A topic named positions.[account] in the Tradehub.PubSub will automatically created to handle incomming messages of this subscription.

Examples

iex> alias Phoenix.PubSub
iex> PubSub.subscribe Tradehub.PubSub, "positions.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"
iex> Tradehub.Stream.positions("swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a")
iex> Process.info(self(), :messages)
iex> Tradehub.Stream.unsubscribe "positions.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"
Link to this function

positions_by_market(market, account)

View Source

Specs

positions_by_market(String.t(), String.t()) :: :ok | {:error, reason :: any()}

Subscribes to the positions_by_market.[market].[account] channel to request the latest positions of the given account within a particular market

A topic named positions_by_market.[market].[account] in the Tradehub.PubSub will automatically created to handle incomming messages of this subscription.

Examples

iex> alias Phoenix.PubSub
iex> PubSub.subscribe Tradehub.PubSub, "positions_by_market.swth_eth1.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"
iex> Tradehub.Stream.positions_by_market("swth_eth1", "swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a")
iex> Process.info(self(), :messages)
iex> Tradehub.Stream.unsubscribe "positions_by_market.swth_eth1.swth1gdm8rvlfxjapvh2paswx7td9fcrq3r7cavkd2a"

Specs

recent_trades(String.t()) :: :ok | {:error, reason :: any()}

Subscribes to the recent_trades.[market] channel to request the recent trades of the given market.

A topic named recent_trades.[market] in the Tradehub.PubSub will automatically created to handle incomming messages of this subscription.

Examples

iex> alias Phoenix.PubSub
iex> PubSub.subscribe Tradehub.PubSub, "recent_trades.swth_eth1"
iex> Tradehub.Stream.recent_trades("swth_eth1")
iex> Process.info(self(), :messages)
iex> Tradehub.Stream.unsubscribe "recent_trades.swth_eth1"

Specs

subscribe(String.t()) :: :ok | {:error, reason :: any()}

The utility function to subscribe into the channel, and broadcast messages if any to the Tradehub.PubSub with a specific topic name.

Examples

iex> Tradehub.Stream.subscribe("market_stats")
Link to this function

unsubscribe(channel_uri)

View Source

Specs

unsubscribe(String.t()) :: :ok | {:error, reason :: any()}

The utility function to unsubscribe an available channel

Examples

iex> Tradehub.Stream.unsubscribe("market_stats")