Giter VIP home page Giter VIP logo

binance-scala-client's Introduction

Scala client for Binance API

All Contributors

Build Status Latest version License: MIT Join the chat at https://gitter.im/binance-scala-client/community Join the chat on Discord at https://discord.gg/7KrBehYs55 Support

A functional Scala client for Binance, powered by cats-effect and fs2.

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

Version compatibility table

JDK LTS version Scala version
11 2.12.x, 2.13.x, 3.0.x, 3.1.x
17 2.12.x, 2.13.x, 3.0.x, 3.1.x

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

WebSocket

Future API

Rest

WebSocket

Initialise the client

The client initialisation returns an API object as a Cats Resource. There are two factories available at the moment, one for Spot API and the other one for Future API.

Spot client

import cats.effect.{IO, Resource}
import io.github.paoloboni.binance.BinanceClient
import io.github.paoloboni.binance.common.SpotConfig
import io.github.paoloboni.binance.spot.SpotApi

val config = SpotConfig.Default(
  apiKey = "***",     // your api key
  apiSecret = "***"   // your api secret
)
val client: Resource[IO, SpotApi[IO]] = BinanceClient.createSpotClient[IO](config)

Future client

import cats.effect.{IO, Resource}
import io.github.paoloboni.binance.BinanceClient
import io.github.paoloboni.binance.common.FapiConfig
import io.github.paoloboni.binance.fapi.FutureApi

val config = FapiConfig.Default(
  apiKey = "***",     // your api key
  apiSecret = "***"   // your api secret
)
val client: Resource[IO, FutureApi[IO]] = BinanceClient.createFutureClient[IO](config)

Documentation

The API documentation is available here.

Example app

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

import cats.effect.std.Console
import cats.effect.{IO, IOApp}
import fs2.Stream
import io.github.paoloboni.binance.BinanceClient
import io.github.paoloboni.binance.common.SpotConfig

import scala.concurrent.duration.DurationInt

object PriceMonitor extends IOApp.Simple {

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

  override def run: IO[Unit] =
    BinanceClient
      .createSpotClient[IO](config)
      .use { client =>
        Stream
          .awakeEvery[IO](5.seconds)
          .repeat
          .evalMap(_ => client.V3.getPrices())
          .evalMap(prices => Console[IO].println("Current prices: " + prices))
          .compile
          .drain
      }
}

Contributing

How to run unit and integration tests

sbt test

How to run end-to-end tests

FAPI_API_KEY=<your-fapi-api-key> \
    FAPI_SECRET_KEY=<your-fapi-secret-key> \
    SPOT_API_KEY=<your-spot-api-key> \
    SPOT_SECRET_KEY=<your-spot-secret-key> \
    sbt e2e:test

How to get Spot API and secret keys

  • Navigate to https://testnet.binance.vision
  • Login with your Github account
  • Click on "Generate HMAC_SHA256 Key"
  • Enter a description and press "Generate"
  • Take note of the generated values

How to get Future API and secret keys

  • Navigate to https://testnet.binancefuture.com
  • Register a new account or login with an existing one
  • Click on "API key" link in the lower part of the screen
  • Take note of the values

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


DarkWingMcQuack

๐Ÿ’ป

Swoorup Joshi

๐Ÿ’ป

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

binance-scala-client's People

Contributors

allcontributors[bot] avatar benhutchison avatar bpsoftwareconsulting avatar codecombiner avatar darkwingmcquack avatar dengbn2 avatar github-actions[bot] avatar gitter-badger avatar paoloboni avatar swoorup 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.