Skip to content

Commit

Permalink
Merge pull request #203 from wavesplatform/matcher_api_fixes
Browse files Browse the repository at this point in the history
matcher_swagger_fixes
  • Loading branch information
alexeykiselev authored Mar 23, 2017
2 parents a9be958 + 10177f2 commit e98ca45
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
26 changes: 14 additions & 12 deletions src/main/scala/com/wavesplatform/matcher/api/MatcherApiRoute.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.wavesplatform.matcher.api

import javax.ws.rs.Path
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.util.{Failure, Success}

import akka.actor.ActorRef
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.{Directive1, Route}
Expand All @@ -23,6 +21,10 @@ import scorex.transaction.assets.exchange.{AssetPair, Order}
import scorex.transaction.state.database.blockchain.StoredState
import scorex.wallet.Wallet

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.util.{Failure, Success}

@Path("/matcher")
@Api(value = "/matcher/")
case class MatcherApiRoute(application: Application, matcher: ActorRef, settings: RestAPISettings, matcherSettings: MatcherSettings) extends ApiRoute {
Expand Down Expand Up @@ -51,12 +53,12 @@ case class MatcherApiRoute(application: Application, matcher: ActorRef, settings
.getOrElse[JsValue](JsString("")))
}

@Path("/orderbook/{asset1}/{asset2}")
@Path("/orderbook/{amountAsset}/{priceAsset}")
@ApiOperation(value = "Get Order Book for a given Asset Pair",
notes = "Get Order Book for a given Asset Pair", httpMethod = "GET")
@ApiImplicitParams(Array(
new ApiImplicitParam(name = "asset1", value = "First Asset Id in Pair, or 'WAVES'", dataType = "string", paramType = "path"),
new ApiImplicitParam(name = "asset2", value = "Second Asset Id in Pair, or 'WAVES'", dataType = "string", paramType = "path"),
new ApiImplicitParam(name = "amountAsset", value = "Amount Asset Id in Pair, or 'WAVES'", dataType = "string", paramType = "path"),
new ApiImplicitParam(name = "priceAsset", value = "Price Asset Id in Pair, or 'WAVES'", dataType = "string", paramType = "path"),
new ApiImplicitParam(name = "depth", value = "Limit the number of bid/ask records returned", required = false, dataType = "integer", paramType = "query")
))
def orderBook: Route = (path("orderbook" / Segment / Segment) & get) { (a1, a2) =>
Expand Down Expand Up @@ -92,15 +94,15 @@ case class MatcherApiRoute(application: Application, matcher: ActorRef, settings
}
}

@Path("/orderbook/{asset1}/{asset2}/cancel")
@Path("/orderbook/{amountAsset}/{priceAsset}/cancel")
@ApiOperation(value = "Cancel order",
notes = "Cancel previously submitted order if it's not already filled completely",
httpMethod = "POST",
produces = "application/json",
consumes = "application/json")
@ApiImplicitParams(Array(
new ApiImplicitParam(name = "asset1", value = "First Asset Id in Pair, or 'WAVES'", dataType = "string", paramType = "path"),
new ApiImplicitParam(name = "asset2", value = "Second Asset Id in Pair, or 'WAVES'", dataType = "string", paramType = "path"),
new ApiImplicitParam(name = "amountAsset", value = "Amount Asset Id in Pair, or 'WAVES'", dataType = "string", paramType = "path"),
new ApiImplicitParam(name = "priceAsset", value = "Price Asset Id in Pair, or 'WAVES'", dataType = "string", paramType = "path"),
new ApiImplicitParam(
name = "body",
value = "Json with data",
Expand All @@ -119,13 +121,13 @@ case class MatcherApiRoute(application: Application, matcher: ActorRef, settings
}
}

@Path("/orderbook/{asset1}/{asset2}/{orderId}")
@Path("/orderbook/{amountAsset}/{priceAsset}/{orderId}")
@ApiOperation(value = "Order Status",
notes = "Get Order status for a given Asset Pair during the last 30 days",
httpMethod = "GET")
@ApiImplicitParams(Array(
new ApiImplicitParam(name = "asset1", value = "First Asset Id in Pair, or 'WAVES'", dataType = "string", paramType = "path"),
new ApiImplicitParam(name = "asset2", value = "Second Asset Id in Pair, or 'WAVES'", dataType = "string", paramType = "path"),
new ApiImplicitParam(name = "amountAsset", value = "Amount Asset Id in Pair, or 'WAVES'", dataType = "string", paramType = "path"),
new ApiImplicitParam(name = "priceAsset", value = "Price Asset Id in Pair, or 'WAVES'", dataType = "string", paramType = "path"),
new ApiImplicitParam(name = "orderId", value = "Order Id", required = true, dataType = "string", paramType = "path")
))
def orderStatus: Route = (path("orderbook" / Segment / Segment / Segment) & get) { (a1, a2, orderId) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ case class OrderBookResult(timestamp: Long, pair: AssetPair, bids: Seq[LevelAgg]
object OrderBookResult {
implicit val assetPairWrites = new Writes[AssetPair] {
def writes(pair: AssetPair) = Json.obj(
"asset1" -> pair.priceAssetStr,
"asset2" -> pair.amountAssetStr
"amountAsset" -> pair.amountAssetStr,
"priceAsset" -> pair.priceAssetStr
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package scorex.transaction.assets.exchange

import io.swagger.annotations.ApiModelProperty
import play.api.libs.json.{JsObject, Json}
import scorex.crypto.encode.Base58
import scorex.transaction._
Expand All @@ -9,8 +10,11 @@ import scorex.transaction.assets.exchange.Validation.booleanOperators

import scala.util.{Success, Try}

case class AssetPair(amountAsset: Option[AssetId], priceAsset: Option[AssetId]) {
case class AssetPair(@ApiModelProperty(dataType = "java.lang.String") amountAsset: Option[AssetId],
@ApiModelProperty(dataType = "java.lang.String") priceAsset: Option[AssetId]) {
@ApiModelProperty(hidden = true)
lazy val priceAssetStr: String = priceAsset.map(Base58.encode).getOrElse(AssetPair.WavesName)
@ApiModelProperty(hidden = true)
lazy val amountAssetStr: String = amountAsset.map(Base58.encode).getOrElse(AssetPair.WavesName)

override def hashCode(): Int = toString.hashCode()
Expand Down Expand Up @@ -45,9 +49,9 @@ object AssetPair {
case other => Base58.decode(other).map(Option(_))
}

def createAssetPair(asset1: String, asset2: String): Try[AssetPair] =
def createAssetPair(amountAsset: String, priceAsset: String): Try[AssetPair] =
for {
a1 <- extractAssetId(asset1)
a2 <- extractAssetId(asset2)
a1 <- extractAssetId(amountAsset)
a2 <- extractAssetId(priceAsset)
} yield AssetPair(a1, a2)
}
24 changes: 12 additions & 12 deletions waves-testnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ waves {

price-assets = [
"WAVES",
"7g151iXK8fyxB5sBUHkwQNXhVBuXdbK8ftPB3h1NrrYV",
"2aSqCbvCTgvCpwkGsk4mea4tCLG4Zgp69aQDhHNvRUZv",
"8zEZuJcKPQmFuYgVe5ZMpxgiPLu5zBhjA6xgdGomQDaP",
"D2MNuUyA38pSKoV7F7vpS15Uhw9nw5qfbrGUfCLRNuRo"
"Fmg13HEHJHuZYbtJq8Da8wifJENq8uBxDuWoP9pVe2Qe",
"HyFJ3rrq5m7FxdkWtQXkZrDat1F7LjVVGfpSkUuEXQHj",
"2xnE3EdpqXtFgCP156qt1AbyjpqdZ5jGjWo3CwTawcux",
"6pmDivReTLikwYqQtJTv6dTcE59knriaodB3AK8T9cF8"
]

predefined-pairs = [
{amountAsset = "WAVES", priceAsset = "7g151iXK8fyxB5sBUHkwQNXhVBuXdbK8ftPB3h1NrrYV"},
{amountAsset = "WAVES", priceAsset = "2aSqCbvCTgvCpwkGsk4mea4tCLG4Zgp69aQDhHNvRUZv"},
{amountAsset = "WAVES", priceAsset = "8zEZuJcKPQmFuYgVe5ZMpxgiPLu5zBhjA6xgdGomQDaP"},
{amountAsset = "WAVES", priceAsset = "D2MNuUyA38pSKoV7F7vpS15Uhw9nw5qfbrGUfCLRNuRo"},
{amountAsset = "7g151iXK8fyxB5sBUHkwQNXhVBuXdbK8ftPB3h1NrrYV", priceAsset = "2aSqCbvCTgvCpwkGsk4mea4tCLG4Zgp69aQDhHNvRUZv"},
{amountAsset = "7g151iXK8fyxB5sBUHkwQNXhVBuXdbK8ftPB3h1NrrYV", priceAsset = "8zEZuJcKPQmFuYgVe5ZMpxgiPLu5zBhjA6xgdGomQDaP"},
{amountAsset = "7g151iXK8fyxB5sBUHkwQNXhVBuXdbK8ftPB3h1NrrYV", priceAsset = "D2MNuUyA38pSKoV7F7vpS15Uhw9nw5qfbrGUfCLRNuRo"},
{amountAsset = "8zEZuJcKPQmFuYgVe5ZMpxgiPLu5zBhjA6xgdGomQDaP", priceAsset = "2aSqCbvCTgvCpwkGsk4mea4tCLG4Zgp69aQDhHNvRUZv"}
{amountAsset = "WAVES", priceAsset = "Fmg13HEHJHuZYbtJq8Da8wifJENq8uBxDuWoP9pVe2Qe"},
{amountAsset = "WAVES", priceAsset = "HyFJ3rrq5m7FxdkWtQXkZrDat1F7LjVVGfpSkUuEXQHj"},
{amountAsset = "WAVES", priceAsset = "2xnE3EdpqXtFgCP156qt1AbyjpqdZ5jGjWo3CwTawcux"},
{amountAsset = "WAVES", priceAsset = "6pmDivReTLikwYqQtJTv6dTcE59knriaodB3AK8T9cF8"},
{amountAsset = "Fmg13HEHJHuZYbtJq8Da8wifJENq8uBxDuWoP9pVe2Qe", priceAsset = "2aSqCbvCTgvCpwkGsk4mea4tCLG4Zgp69aQDhHNvRUZv"},
{amountAsset = "Fmg13HEHJHuZYbtJq8Da8wifJENq8uBxDuWoP9pVe2Qe", priceAsset = "8zEZuJcKPQmFuYgVe5ZMpxgiPLu5zBhjA6xgdGomQDaP"},
{amountAsset = "Fmg13HEHJHuZYbtJq8Da8wifJENq8uBxDuWoP9pVe2Qe", priceAsset = "D2MNuUyA38pSKoV7F7vpS15Uhw9nw5qfbrGUfCLRNuRo"},
{amountAsset = "2xnE3EdpqXtFgCP156qt1AbyjpqdZ5jGjWo3CwTawcux", priceAsset = "HyFJ3rrq5m7FxdkWtQXkZrDat1F7LjVVGfpSkUuEXQHj"}
]
}

Expand Down

0 comments on commit e98ca45

Please sign in to comment.