Giter Site home page Giter Site logo

sztheory / tai Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fremantle-industries/tai

0.0 1.0 0.0 3.46 MB

[mirror] A real time market data and trade execution toolkit. Built with Elixir, runs on the Erlang virtual machine

License: MIT License

Elixir 100.00%

tai's Introduction

Tai

Build Status Coverage Status

A composable real time market data and trade execution toolkit. Built with Elixir, runs on the Erlang virtual machine

Tai on GitHub | Install | Usage | Advisors | Configuration | Commands | Logging

What Can I Do? TLDR;

Stream market data to create and manage orders with a near-uniform API across multiple venues

Here's an example of an advisor that logs the spread between multiple products on multiple venues

asciicast

Supported Venues

Venues Live Order Book Account Balance Active Orders Passive Orders Products Fees
BitMEX [x] [x] [x] [x] [x] [x]
OkEx [x] [x] [x] [x] [x] [x]

Venues In Progress

Venue Live Order Book Account Balance Active Orders Passive Orders Products Fees
Binance [x] [x] [x] [ ] [x] [x]
GDAX [x] [x] [ ] [ ] [x] [x]
FTX [ ] [ ] [ ] [ ] [ ] [ ]
Deribit [ ] [ ] [ ] [ ] [ ] [ ]
Huobi [ ] [ ] [ ] [ ] [ ] [ ]
Coinflex [ ] [ ] [ ] [ ] [ ] [ ]

Planned Venues...

Install

tai requires Elixir 1.8+ & Erlang/OTP 21+. Add tai to your list of dependencies in mix.exs

def deps do
  [
    {:tai, "~> 0.0.43"}
  ]
end

Create an .iex.exs file in the root of your project and import the tai helper

# .iex.exs
Application.put_env(:elixir, :ansi_enabled, true)

import Tai.CommandsHelper

Usage

tai runs as an OTP application.

During development we can leverage mix to compile and run our application with an interactive Elixir shell that imports the set of tai helper commands.

iex -S mix

Advisors

Advisors are the brains of any tai application, they subscribe to changes in market data to record and analyze data or execute automated trading strategies.

Orders are created and managed through a uniform API across exchanges, with fast execution and reliability.

Take a look at some of the examples to understand what you can create with advisors.

Configuration

Each environment can have its own configuration. Take a look at the example dev configuration for available options.

Commands

To monitor your advisors, accounts and markets tai provides the following set of IEx commands.

help

Display the available commands and usage examples

iex(1)> help
* balance
* products
* fees
* markets
* orders
* settings
* advisors [where: [...], order: [...]]
* start_advisors [where: [...]]
* stop_advisors [where: [...]]
* enable_send_orders
* disable_send_orders

balance

Display all non-zero balances across configured accounts

iex(2)> balance
+-------+---------+--------+------------+------------+------------+
| Venue | Account | Symbol |       Free |     Locked |    Balance |
+-------+---------+--------+------------+------------+------------+
|  gdax |    main |    btc | 0.30000000 | 0.00000000 | 0.30000000 |
|  gdax |    main |    ltc | 1.80009170 | 1.10000000 | 2.90009170 |
|  gdax |    main |    usd |       0.01 |       0.00 |       0.01 |
+-------+---------+--------+------------+------------+------------+

products

Display the products provided by configured venues

iex(3)> products
+----------+----------+--------------+---------+-----------+-----------+
|    Venue |   Symbol | Venue Symbol |  Status | Maker Fee | Taker Fee |
+----------+----------+--------------+---------+-----------+-----------+
|     gdax |  btc_usd |      BTC-USD | trading |           |           |
|  binance | btc_usdt |      BTCUSDT | trading |           |           |
| poloniex | btc_usdt |     USDT_BTC | trading |           |           |
|     gdax |  ltc_usd |      LTC-USD | trading |           |           |
| poloniex | ltc_usdt |     USDT_LTC | trading |           |           |
|  binance | ltc_usdt |      LTCUSDT | trading |           |           |
|   bitmex |   xbth19 |       XBTH19 | trading |   -0.025% |    0.075% |
|   bitmex |   xbtz18 |       XBTZ18 | trading |   -0.025% |    0.075% |
+----------+----------+--------------+---------+-----------+-----------+

fees

Display the maker/taker fees for every product from configured venue accounts

iex(4)> fees
+---------+------------+-----------+-------+-------+
|   Venue | Account ID |    Symbol | Maker | Taker |
+---------+------------+-----------+-------+-------+
| binance |       main |   lsk_bnb |  0.1% |  0.1% |
| binance |       main |   rlc_eth |  0.1% |  0.1% |
| binance |       main |  aion_eth |  0.1% |  0.1% |
| binance |       main |   mft_bnb |  0.1% |  0.1% |
| binance |       main |  ardr_bnb |  0.1% |  0.1% |
| binance |       main |  iost_btc |  0.1% |  0.1% |
| binance |       main |   xlm_eth |  0.1% |  0.1% |
| binance |       main |   xem_eth |  0.1% |  0.1% |
| binance |       main |   kmd_btc |  0.1% |  0.1% |
| binance |       main | ncash_btc |  0.1% |  0.1% |
| binance |       main |   xrp_eth |  0.1% |  0.1% |
| binance |       main |   vet_bnb |  0.1% |  0.1% |
+---------+------------+-----------+-------+-------+

markets

Displays the live top of the order book for the configured feeds. It includes the time they were processed locally and if supported, the time they were sent from the venue. This allows you to monitor if a feed is under backpressure and starting to fall behind as it updates it's order books.

iex(5)> markets
+---------+----------+-----------+-----------+------------+--------------+
|   Venue |   Symbol | Bid Price | Ask Price |   Bid Size |     Ask Size |
+---------+----------+-----------+-----------+------------+--------------+
| binance | btc_usdt |    8430.0 |   8439.91 |   0.349355 |     1.021896 |
| binance | ltc_usdt |    159.53 |    159.58 |   10.54534 |      1.02855 |
| binance | eth_usdt |    519.67 |     520.0 |    0.08984 |      2.33198 |
|    gdax |  btc_usd |   8430.86 |   8430.87 | 0.01448655 |  24.32791169 |
|    gdax |  ltc_usd |    159.97 |    159.98 |    0.00002 | 478.22565196 |
|    gdax |  eth_usd |    520.93 |    520.94 | 9.48431449 |  79.37008001 |
+---------+----------+-----------+-----------+------------+--------------+

orders

Displays the list of orders and their details.

As the lifecycle of the order changes it's details will be updated. You can view these changes by running the orders command again.

iex(6)> orders
+--------+---------+--------+------+-------+--------+-----+------------+----------------+---------------+--------+-----------+----------------+----------------+------------------+----------------------+----------------+--------------+
|  Venue | Account | Symbol | Side |  Type |  Price | Qty | Leaves Qty | Cumulative Qty | Time in Force | Status | Client ID | Venue Order ID |    Enqueued At | Last Received At | Last Venue Timestamp |     Updated At | Error Reason |
+--------+---------+--------+------+-------+--------+-----+------------+----------------+---------------+--------+-----------+----------------+----------------+------------------+----------------------+----------------+--------------+
| bitmex |    main | xbtm19 |  buy | limit | 3622.5 |  15 |         15 |              0 |           gtc |   open | 78f616... |      fe7486... | 11 seconds ago |   11 seconds ago |       11 seconds ago | 11 seconds ago |              |
+--------+---------+--------+------+-------+--------+-----+------------+----------------+---------------+--------+-----------+----------------+----------------+------------------+----------------------+----------------+--------------+

settings

Displays the current runtime settings

iex(7)> settings
+-------------+-------+
|        Name | Value |
+-------------+-------+
| send_orders | false |
+-------------+-------+

advisors

List advisors that can optionally be filtered and ordered

iex(8)> advisors where: [status: :unstarted], order: [:group_id]
+---------------------------------+-------------------+-----------+-----+
|                        Group ID |        Advisor ID |    Status | PID |
+---------------------------------+-------------------+-----------+-----+
| create_and_cancel_pending_order |      gdax_btc_usd | unstarted |   - |
|             fill_or_kill_orders |  binance_btc_usdt | unstarted |   - |
|                      log_spread |  binance_btc_usdt | unstarted |   - |
|                      log_spread |      gdax_btc_usd | unstarted |   - |
|                      log_spread | poloniex_btc_usdt | unstarted |   - |
+---------------------------------+-------------------+-----------+-----+

start_advisors

Starts advisors with an optional filter

iex(9)> start_advisors where: [status: :unstarted]
Started advisors: 5 new, 0 already running

stop_advisors

Stops advisors with an optional filter

iex(10)> stop_advisors where: [status: :running]
Stopped advisors: 5 new, 0 already stopped

Logging

tai uses a system wide event bus and forwards these events to the Elixir logger. By default Elixir will use the console logger to print logs to stdout in the main process running tai. You can configure your Elixir logger to format or change the location of the output.

For example. To write to a file, add a file logger:

# mix.exs
defp deps do
  {:logger_file_backend, "~> 0.0.10"}
end

And configure it's log location:

# config/config.exs
use Mix.Config

config :logger, :file_log, path: "./log/#{Mix.env()}.log"
config :logger, backends: [{LoggerFileBackend, :file_log}]

If you intend to deploy tai to a service that ingests structured logs, you will need to use a supported backed. For Google Cloud Stackdriver you can use logger_json

# mix.exs
defp deps do
  {:logger_json, "~> 2.0.1"}
end

# config/config.exs
use Mix.Config

config :logger_json, :backend, metadata: :all
config :logger, backends: [LoggerJSON]

Secrets

Managing secrets is a complex and opinionated topic. We recommend that you avoid compiling application secrets into your OTP release and regularly rotate them. This can be achieved in many different ways, tai has chosen to use confex to manage this workflow. confex provides the ability to read secrets from environment variables or the file system out of the box. It also has the ability to read secrets from your any location you wish via a custom adapter.

Take a look at our example dev configuration which reads secrets from the file system.

Help Wanted :)

If you think this tai thing might be worthwhile and you don't see a feature or venue listed we would love your contributions to add them! Feel free to drop us an email or open a Github issue.

Authors

License

tai is released under the MIT license

tai's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar renovate-bot avatar rupurt avatar yurikoval avatar

Watchers

 avatar

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.