Skip to main content

Spot Trading Endpoints

Place and manage orders on the Binance Spot exchange. All endpoints require HMAC-SHA256 signature (SecurityType: Trade).

Binance API Reference: Spot Account/Trade

warning

Trading endpoints modify your account. Always test with the Testnet first:

val config = BinanceConfig(mode = BinanceMode.Testnet)

New Order

Place a new order.

import io.github.rafafrdz.binance4s.api.spot.*

val order: F[OrderResponse] = client.newOrder(NewOrderReq(
symbol = "BTCUSDT",
side = OrderSide.BUY,
`type` = OrderType.LIMIT,
timeInForce = Some(TimeInForce.GTC),
quantity = Some(BigDecimal("0.001")),
price = Some(BigDecimal("50000"))
))
EndpointPOST /api/v3/order
AuthHMAC Signed
Weight1

Order Types

TypeRequired Fields
LIMITtimeInForce, quantity, price
MARKETquantity OR quoteOrderQty
STOP_LOSSquantity, stopPrice
STOP_LOSS_LIMITtimeInForce, quantity, price, stopPrice
TAKE_PROFITquantity, stopPrice
TAKE_PROFIT_LIMITtimeInForce, quantity, price, stopPrice
LIMIT_MAKERquantity, price

Test Order

Test new order creation without actually placing it. Same parameters as newOrder.

val test: F[Json] = client.testOrder(TestOrderReq(
symbol = "BTCUSDT",
side = OrderSide.BUY,
`type` = OrderType.MARKET,
quantity = Some(BigDecimal("0.001"))
))
EndpointPOST /api/v3/order/test
AuthHMAC Signed
Weight1

Cancel Order

Cancel an active order.

val cancelled: F[CancelOrderResponse] =
client.cancelOrder("BTCUSDT", orderId = Some(12345L))
EndpointDELETE /api/v3/order
AuthHMAC Signed
Weight1

Cancel All Open Orders

Cancel all open orders on a symbol.

val cancelled: F[List[CancelOrderResponse]] =
client.cancelAllOpenOrders("BTCUSDT")
EndpointDELETE /api/v3/openOrders
AuthHMAC Signed
Weight1

Cancel and Replace (Atomic)

Atomically cancel an existing order and place a new one.

val result: F[CancelReplaceResponse] = client.cancelReplaceOrder(
CancelReplaceOrderReq(
symbol = "BTCUSDT",
side = OrderSide.BUY,
`type` = OrderType.LIMIT,
cancelReplaceMode = CancelReplaceMode.STOP_ON_FAILURE,
cancelOrderId = Some(12345L),
quantity = Some(BigDecimal("0.002")),
price = Some(BigDecimal("51000")),
timeInForce = Some(TimeInForce.GTC)
)
)
EndpointPOST /api/v3/order/cancelReplace
AuthHMAC Signed
Weight1

OCO Order

Place a new OCO (One-Cancels-the-Other) order.

val oco: F[OrderListResponse] = client.newOco(NewOcoReq(
symbol = "BTCUSDT",
side = OrderSide.SELL,
quantity = BigDecimal("0.001"),
price = BigDecimal("70000"),
stopPrice = BigDecimal("60000")
))
EndpointPOST /api/v3/orderList/oco
AuthHMAC Signed
Weight1

SOR Order (Smart Order Routing)

Place a new order using Smart Order Routing.

val sor: F[OrderResponse] = client.sorOrder(SorOrderReq(
symbol = "BTCUSDT",
side = OrderSide.BUY,
`type` = OrderType.LIMIT,
quantity = BigDecimal("0.001"),
price = Some(BigDecimal("50000")),
timeInForce = Some(TimeInForce.GTC)
))
EndpointPOST /api/v3/sor/order
AuthHMAC Signed
Weight1