# Tradehub

[![Coverage Status](](
[![Hex pm](](
[![ downloads](](


Welcome to the Tradehub SDK for Elixir language. The goal of building this project is to empower
developers by offering an client that is easily to interact with all aspects of the Switheo Tradehub
blockchain, and the [DEMEX]( decentralized exchange via its REST/Websocket endpoints.

> The code found in this repository is unaudited and incomplete. Switcheo is not responsible for any losses incurred when using this code.

## General

Switcheo Tradehub is a blockchain protocol built on top of [Tendermint]( which allows for fair, efficient, and transparent trading on platforms such as Demex. The protocol
designed to allow anyone to create a market for any underlying. Head over to its
[landing page](, and its official [API documetation]( more details.

Head over to [Tradehub Faucet]( get receive free TestNet tokens.

## Installation

The package can be installed by adding `tradehub` to your dependencies in `mix.exs`.

``` elixir
def deps do
    {:tradehub, "~> 0.1.5"}

## Basic Usage

Configure Tradehub network in your `config.exs` [OPTIONAL].

``` elixir
config :tradehub,
  network: "", # default value
  ws: "wss://" # default value

Make a simple REST call to get the block time of the chain.

``` elixir
iex(1)> Tradehub.Protocol.block_time

## Websocket subscribe

This example will do a subscription onto the channel `market_stats`, and print out the received messages.

``` elixir
defmodule WatchMarketStats do
  use GenServer

  def start_link(state) do
    GenServer.start_link(__MODULE__, state, name: __MODULE__)

  ## Callbacks

  def init(stack) do
    # Start listening on the `market_stats` channel

    # Register myself as the client to handle message from the channel
    Phoenix.PubSub.subscribe(Tradehub.PubSub, "market_stats")

    {:ok, stack}

  # Handle latest message from the `market_stats` channel
  def handle_info(msg, state) do
    IO.puts("Receive message -- #{inspect(msg)}")

    {:noreply, state}

``` elixir
iex(1)> WatchMarketStats.start_link {}

Full documentation can be found at [](

## Features

* [ ] Implementation of all general information endpoints
  * [x] Public endpoints
  * [x] Websocket
  * [ ] Handling of authentication and private endpoints