Skip to content
This repository has been archived by the owner on Nov 24, 2024. It is now read-only.

Commit

Permalink
SpotRestApiV3 (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloboni authored Aug 21, 2022
1 parent e5a7952 commit 821590b
Show file tree
Hide file tree
Showing 9 changed files with 795 additions and 216 deletions.
9 changes: 5 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ lazy val EndToEndTest = config("e2e") extend Test
lazy val e2eSettings =
inConfig(EndToEndTest)(Defaults.testSettings) ++
Seq(
EndToEndTest / fork := true,
EndToEndTest / parallelExecution := true,
EndToEndTest / scalaSource := baseDirectory.value / "src" / "e2e" / "scala"
EndToEndTest / fork := true,
EndToEndTest / testForkedParallel := true,
EndToEndTest / scalaSource := baseDirectory.value / "src" / "e2e" / "scala"
)

lazy val circeV = "0.14.1"
Expand Down Expand Up @@ -65,7 +65,8 @@ lazy val root = (project in file("."))
"org.http4s" %% "http4s-blaze-server" % http4sV % Test,
"org.http4s" %% "http4s-circe" % http4sV % Test,
"org.http4s" %% "blaze-http" % http4sBlazeV % Test,
"com.disneystreaming" %% "weaver-cats" % weaverV % Test
"com.disneystreaming" %% "weaver-cats" % weaverV % Test,
"com.disneystreaming" %% "weaver-scalacheck" % weaverV % Test
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, minor)) =>
Seq(
Expand Down
124 changes: 124 additions & 0 deletions src/e2e/scala/io/github/paoloboni/SpotLegacyE2ETests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package io.github.paoloboni

import cats.effect.{IO, Resource}
import cats.implicits._
import io.github.paoloboni.binance._
import io.github.paoloboni.binance.common.{Interval, OrderSide, SpotConfig}
import io.github.paoloboni.binance.spot._
import io.github.paoloboni.binance.spot.parameters._

import java.time.Instant
import scala.annotation.nowarn
import scala.concurrent.duration.Duration
import scala.util.Random

object SpotLegacyE2ETests extends BaseE2ETest[SpotApi[IO]] {

val config: SpotConfig = SpotConfig.Default(
apiKey = sys.env("SPOT_API_KEY"),
apiSecret = sys.env("SPOT_SECRET_KEY"),
testnet = true,
recvWindow = 20000
)

val sharedResource: Resource[IO, SpotApi[IO]] = BinanceClient.createSpotClient[IO](config)

test("getDepth") {
_.getDepth(common.parameters.DepthParams("BTCUSDT", common.parameters.DepthLimit.`500`))
.map(succeed): @nowarn
}

test("getPrices")(_.getPrices().map(res => expect(res.nonEmpty)): @nowarn)

test("getBalance")(_.getBalance().map(succeed): @nowarn)

test("getKLines") { client =>
val now = Instant.now()
client
.getKLines(common.parameters.KLines("BTCUSDT", Interval.`5m`, now.minusSeconds(3600), now, 100))
.compile
.toList
.map(res => expect(res.nonEmpty)): @nowarn
}

test("createOrder") { client =>
val side = Random.shuffle(OrderSide.values).head
client
.createOrder(
SpotOrderCreateParams.MARKET(
symbol = "TRXUSDT",
side = side,
quantity = BigDecimal(1000).some
)
)
.map(succeed): @nowarn
}

test("queryOrder") { client =>
val symbol = "TRXUSDT"
for {
createOrderResponse <- client.createOrder(
SpotOrderCreateParams.LIMIT(
symbol = symbol,
side = OrderSide.SELL,
timeInForce = SpotTimeInForce.GTC,
quantity = 1000,
price = 0.08
)
): @nowarn

_ <- client.queryOrder(
SpotOrderQueryParams(
symbol = symbol,
orderId = createOrderResponse.orderId.some,
origClientOrderId = None
)
): @nowarn
} yield success
}

test("cancelOrder") { client =>
val symbol = "TRXUSDT"
(for {
createOrderResponse <- client.createOrder(
SpotOrderCreateParams.LIMIT(
symbol = symbol,
side = OrderSide.SELL,
timeInForce = SpotTimeInForce.GTC,
quantity = 1000,
price = 0.08
)
): @nowarn

_ <- client
.cancelOrder(
SpotOrderCancelParams(
symbol = symbol,
orderId = createOrderResponse.orderId.some,
origClientOrderId = None
)
): @nowarn
} yield success).retryWithBackoff(initialDelay = Duration.Zero)
}

test("cancelAllOrders") { client =>
val symbol = "TRXUSDT"
(for {
_ <- client.createOrder(
SpotOrderCreateParams.LIMIT(
symbol = symbol,
side = OrderSide.SELL,
timeInForce = SpotTimeInForce.GTC,
quantity = 1000,
price = 0.08
)
): @nowarn

_ <- client
.cancelAllOrders(
SpotOrderCancelAllParams(symbol = symbol)
): @nowarn
} yield success).retryWithBackoff(initialDelay = Duration.Zero)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import io.github.paoloboni.binance.common.{Interval, OrderSide, SpotConfig}
import io.github.paoloboni.binance.spot._
import io.github.paoloboni.binance.spot.parameters._

import java.time.Instant
import scala.concurrent.duration.Duration
import scala.util.Random

object SpotE2ETests extends BaseE2ETest[SpotApi[IO]] {
object SpotV3E2ETests extends BaseE2ETest[SpotApi[IO]] {

val config: SpotConfig = SpotConfig.Default(
apiKey = sys.env("SPOT_API_KEY"),
Expand All @@ -23,27 +22,27 @@ object SpotE2ETests extends BaseE2ETest[SpotApi[IO]] {

val sharedResource: Resource[IO, SpotApi[IO]] = BinanceClient.createSpotClient[IO](config)

test("getDepth") {
_.getDepth(common.parameters.DepthParams("BTCUSDT", common.parameters.DepthLimit.`500`))
test("getDepth")(
_.V3
.getDepth(spot.parameters.v3.DepthParams("BTCUSDT", None))
.map(succeed)
}
)

test("getPrices") { _.getPrices().map(res => expect(res.nonEmpty)) }
test("getPrices")(_.V3.getPrices().map(res => expect(res.nonEmpty)))

test("getBalance") { _.getBalance().map(succeed) }
test("getBalance")(_.V3.getBalance().map(succeed))

test("getKLines") { client =>
val now = Instant.now()
client
.getKLines(common.parameters.KLines("BTCUSDT", Interval.`5m`, now.minusSeconds(3600), now, 100))
test("getKLines")(
_.V3
.getKLines(spot.parameters.v3.KLines("BTCUSDT", Interval.`5m`, None, None, 100))
.compile
.toList
.map(res => expect(res.nonEmpty))
}
)

test("createOrder") { client =>
val side = Random.shuffle(OrderSide.values).head
client
client.V3
.createOrder(
SpotOrderCreateParams.MARKET(
symbol = "TRXUSDT",
Expand All @@ -57,7 +56,7 @@ object SpotE2ETests extends BaseE2ETest[SpotApi[IO]] {
test("queryOrder") { client =>
val symbol = "TRXUSDT"
for {
createOrderResponse <- client.createOrder(
createOrderResponse <- client.V3.createOrder(
SpotOrderCreateParams.LIMIT(
symbol = symbol,
side = OrderSide.SELL,
Expand All @@ -67,7 +66,7 @@ object SpotE2ETests extends BaseE2ETest[SpotApi[IO]] {
)
)

_ <- client.queryOrder(
_ <- client.V3.queryOrder(
SpotOrderQueryParams(
symbol = symbol,
orderId = createOrderResponse.orderId.some,
Expand All @@ -80,7 +79,7 @@ object SpotE2ETests extends BaseE2ETest[SpotApi[IO]] {
test("cancelOrder") { client =>
val symbol = "TRXUSDT"
(for {
createOrderResponse <- client.createOrder(
createOrderResponse <- client.V3.createOrder(
SpotOrderCreateParams.LIMIT(
symbol = symbol,
side = OrderSide.SELL,
Expand All @@ -90,7 +89,7 @@ object SpotE2ETests extends BaseE2ETest[SpotApi[IO]] {
)
)

_ <- client
_ <- client.V3
.cancelOrder(
SpotOrderCancelParams(
symbol = symbol,
Expand All @@ -104,7 +103,7 @@ object SpotE2ETests extends BaseE2ETest[SpotApi[IO]] {
test("cancelAllOrders") { client =>
val symbol = "TRXUSDT"
(for {
_ <- client.createOrder(
_ <- client.V3.createOrder(
SpotOrderCreateParams.LIMIT(
symbol = symbol,
side = OrderSide.SELL,
Expand All @@ -114,59 +113,59 @@ object SpotE2ETests extends BaseE2ETest[SpotApi[IO]] {
)
)

_ <- client
_ <- client.V3
.cancelAllOrders(
SpotOrderCancelAllParams(symbol = symbol)
)
} yield success).retryWithBackoff(initialDelay = Duration.Zero)
}

test("tradeStreams") {
test("tradeStreams")(
_.tradeStreams("btcusdt")
.take(1)
.compile
.toList
.map(l => expect(l.size == 1))
}
)

test("kLineStreams") {
test("kLineStreams")(
_.kLineStreams("btcusdt", Interval.`1m`)
.take(1)
.compile
.toList
.map(l => expect(l.size == 1))
}
)

test("diffDepthStream") {
test("diffDepthStream")(
_.diffDepthStream("btcusdt")
.take(1)
.compile
.toList
.map(l => expect(l.size == 1))
}
)

test("partialBookDepthStream") {
test("partialBookDepthStream")(
_.partialBookDepthStream("btcusdt", Level.`5`)
.take(1)
.compile
.toList
.map(l => expect(l.size == 1))
}
)

test("allBookTickersStream") {
test("allBookTickersStream")(
_.allBookTickersStream()
.take(1)
.compile
.toList
.map(l => expect(l.size == 1))
}
)

test("aggregateTradeStreams") {
test("aggregateTradeStreams")(
_.aggregateTradeStreams("btcusdt")
.take(1)
.compile
.toList
.map(l => expect(l.size == 1))
}
)

}
Loading

0 comments on commit 821590b

Please sign in to comment.