Scala client for Binance API

Build Status Latest version

A functional Scala client for Binance.

This client is rate limited, based on Binance API specification.

Getting started

If you use sbt add the following dependency to your build file:

libraryDependencies += "io.github.paoloboni" %% "binance-scala-client" % "<version>"

APIs supported

Example

This is a sample app to monitor the exchange prices (fetch every 5 seconds).

import io.github.paoloboni.binance.{BinanceClient, BinanceConfig}
import cats.effect.{ExitCode, IO, IOApp}
import fs2._
import log.effect.fs2.SyncLogWriter._

import scala.concurrent.duration._

object PriceMonitor extends IOApp {

  val config = BinanceConfig(
    scheme = "https",
    host = "api.binance.com",
    port = 443,
    infoUrl = "/api/v1/exchangeInfo",
    apiKey = "***",
    apiSecret = "***"
  )

  override def run(args: List[String]): IO[ExitCode] = {
    implicit val log = consoleLog[IO]
    BinanceClient[IO](config)
      .use { client =>
        Stream
          .awakeEvery[IO](5.seconds)
          .repeat
          .evalMap(_ => client.getPrices())
          .evalMap(prices => log.info("Current prices: " + prices))
          .compile
          .drain
      }
      .redeem(
        { t =>
          log.error("Something went wrong", t)
          ExitCode(1)
        },
        _ => ExitCode.Success
      )
  }
}