Giter Club home page Giter Club logo

ex_twelve_data's Introduction

ExTwelveData

Unofficial Elixir client for Twelve Data.

Currently, it only covers the real-time prices WebSocket API.

Happy to accept contributions to support the other endpoints.

Usage

Real-time prices client

Twelve Data offers a WebSocket based API for real-time prices1. ExTwelveData uses the WebSockex library to access this endpoint. Because of this, the WebSocket client runs as a supervised process.

The ExTwelveData.RealTimePrices.Handler behaviour requires a single callback, invoked whenever the client receives a price update from Twelve Data.

defmodule Your.Handler do
  @behaviour ExTwelveData.RealTimePrices.Handler
  
  @impl true
  def handle_price_update(price) do
    # Here you can process inbound price updates
    :ok
  end  
end

defmodule Your.Application do
  use Application
  alias ExTwelveData.RealTimePrices
  
  def start(_type, _args) do
    children = [
      {RealTimePrices, name: Your.Name, api_key: "abc", handler: Your.Handler},
    ]
    
    Supervisor.start_link(children, strategy: :one_for_one)
  end
end

With the process running, you can now subscribe, unsubscribe, and reset the subscriptions.

# Send a list of Twelve Data symbols to subscribe to
ExTwelveData.RealTimePrices.subscribe(Your.Name, ["BTC/USD", "AAPL"])

# Use the PID or process name to address the messages
ExTwelveData.RealTimePrices.unsubscribe(Your.Name, ["AAPL"])

# This stops listening for all updates, while keeping the client running
ExTwelveData.RealTimePrices.reset(Your.Name)

The client currently takes care of reconnecting, and sending the heartbeat every 10 seconds.

Installation

If available in Hex, the package can be installed by adding ex_twelve_data to your list of dependencies in mix.exs:

def deps do
  [
    {:ex_twelve_data, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/ex_twelve_data.

Reference

Footnotes

  1. https://twelvedata.com/docs#real-time-price-websocket โ†ฉ

ex_twelve_data's People

Contributors

borgoat avatar

Stargazers

 avatar

Watchers

 avatar  avatar

ex_twelve_data's Issues

Contributing other endpoints

We are currently using Twelve Data in production but have yet to split out a separate open source library. We aren't using the Websockets API right now, but other endpoints, especially the time series endpoint.

For these API client libraries, our typical approach is to use Tesla for the client and write custom functions for each API. We like to translate the JSON into Structs with common Elixir formats, such as Date, DateTime, Decimal, Money and atoms for enumerations. We also like to translate HTTP status codes into error tuples so that HTTP and the client library used (Tesla) are implementation details that aren't exposed to the caller.

Does this align with what you'd like to see? If not, what changes would you make?

Will you have time to dedicate to reviewing contributions, and releasing the hex packages?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.