paoloboni / binance-scala-client

A functional Scala client for Binance

Version Matrix

Scala client for Binance API

All Contributors

Build Status Latest version License: MIT Join the chat at https://gitter.im/binance-scala-client/community

A functional Scala client for Binance, powered by cats-effect 3.x.

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

Spot API

Rest

Future API

Rest

WebSocket

  • Aggregate trade streams: The Aggregate Trade Streams push trade information that is aggregated for a single taker order every 100 milliseconds.
  • Kline/Candlestick Streams: The Kline/Candlestick Stream push updates to the current klines/candlestick every 250 milliseconds (if existing).

Example

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

import cats.effect.{ExitCode, IO, IOApp}
import fs2.Stream
import io.github.paoloboni.binance.BinanceClient
import io.github.paoloboni.binance.common.SpotConfig
import log.effect.LogWriter
import log.effect.fs2.SyncLogWriter.consoleLog

import scala.concurrent.duration.DurationInt

object PriceMonitor extends IOApp {

  val config = SpotConfig.Default(
    apiKey = "***",
    apiSecret = "***"
  )

  override def run(args: List[String]): IO[ExitCode] = {
    implicit val log: LogWriter[IO] = consoleLog[IO]

    BinanceClient
      .createSpotClient[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
      )
  }
}

Contributors

Thanks goes to these wonderful people (emoji key):


DarkWingMcQuack

💻

This project follows the all-contributors specification. Contributions of any kind welcome!