Build Status Codacy Badge

noobit-markets

Overview

Building Blocks for connecting and trading with cryptocurrency exchanges under a unified format.
Primarily meant to be integrated within larger applications, but also provides a basic CLI app.
Presently supported exchanges:

  • Kraken
  • Binance
  • Ftx

For now we restrict instruments to spot pairs.


Features

  • Unified API, independent of exchange
  • Fully typed with annotations and checked with mypy
  • Fully modeled domains relying on Pydantic models (for validation and serialization)
  • Safe and explicit function returns thanks to a railway oriented approach and Result containers
  • CLI app that bundles all lower level coroutines and websocket streams in a user friendly manner

Models & Pydantic:

  • We rely heavily on Pydantic to check the user input and what he receives, against what we expected
    (that is, the models we have defined and should represent our domains)
  • It is important to know that pydantic not only handles validation, but also serialization.
  • As such, it will serialize data to the declared type of the field before validation, if possible
    (e.g if the field “price” is declared as a Decimal, passing a float will not throw any ValidationError as a float can be cast to a Decimal)
  • You can browse our unified models here

Containers:

  • To provide the user with more explicit returns, responses are wrapped in a Result container object, which can either be of type Ok or Err.
    The Result object's .value() method gives access to the value it holds, which will either be a response (validated against its expected model) or an exception.
  • This allows to avoid having to raise Exceptions and stopping the program from running.
  • Additionally, we provide containers which give the user richer representations of the data. For now, this is limited to tables, but can easily be extended to include pandas dataframes for ex.

Railway oriented approach:

  • This approach seeks to ensure every function or method returns a success or a failure.
    When chaining multiple functions, in case of a failure, we immediately return the failure to the user and “stop the chain”.
  • See this article for a more detailed explanation.

Usage

  • For each exchange, an interface maps keys to coroutines or websocket APIs. For an example of Krakens interface see here
  • For how to use coroutines and websocket APIs within an async app, examples with annotations and comments are available for each exchange here
  • To start the CLI app, run the noobit-cli command. As a prerequisite for subsequent CLI command, run the symbols command in the CLI on each startup.

CLI Demo

  • Launching CLI app, caching all symbols and their infos, and displaying the data as a table


  • Showing how we can set variables and get help on a command using OHLC command as an example


  • Showing how explicit returned errors are