Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 795 | blopes | 1 | package br.com.kronus.binance.testes; |
| 2 | |||
| 3 | public class TestBracketOrderMain { |
||
| 4 | |||
| 5 | public static void main(String[] args) { |
||
| 6 | try { |
||
| 7 | /* |
||
| 8 | BinanceFuturesConfig config = |
||
| 9 | BinanceFuturesConfig.fromProperties("binance-futures.properties"); |
||
| 10 | |||
| 11 | System.out.println("API KEY carregada: " + config.getApiKey()); |
||
| 12 | System.out.println("SECRET KEY carregada: " + config.getSecretKey().substring(0, 5) + "*****"); |
||
| 13 | |||
| 14 | BinanceFuturesHttpClient httpClient = new BinanceFuturesHttpClient(config); |
||
| 15 | httpClient.syncServerTime(); |
||
| 16 | |||
| 17 | BinanceFuturesMarketDataService marketDataService = |
||
| 18 | new BinanceFuturesMarketDataService(httpClient); |
||
| 19 | |||
| 20 | BinanceFuturesTradeService tradeService = |
||
| 21 | new BinanceFuturesTradeService(httpClient); |
||
| 22 | |||
| 23 | String symbol = "BTCUSDT"; |
||
| 24 | |||
| 25 | // 1) Descobrir o mark price atual |
||
| 26 | BigDecimal markPrice = marketDataService.getMarkPrice(symbol); |
||
| 27 | System.out.println("Mark price atual de " + symbol + " = " + markPrice); |
||
| 28 | |||
| 29 | // 2) Definir quantidade garantindo notional >= 100 USDT |
||
| 30 | // notional = markPrice * qty |
||
| 31 | BigDecimal qty = new BigDecimal("0.002"); // ajusta se precisar |
||
| 32 | BigDecimal notional = markPrice.multiply(qty); |
||
| 33 | System.out.println("Notional da ordem = " + notional); |
||
| 34 | |||
| 35 | if (notional.compareTo(new BigDecimal("100")) < 0) { |
||
| 36 | // se ficar menor que 100, ajusta a qty |
||
| 37 | BigDecimal minQty = new BigDecimal("100") |
||
| 38 | .divide(markPrice, 6, BigDecimal.ROUND_UP); |
||
| 39 | qty = minQty; |
||
| 40 | notional = markPrice.multiply(qty); |
||
| 41 | System.out.println("Ajustando qty para " + qty + " (notional=" + notional + ")"); |
||
| 42 | } |
||
| 43 | |||
| 44 | // 3) Definir stop e alvo RELATIVOS ao preço atual (exemplo: -1% e +1%) |
||
| 45 | BigDecimal stopLossPrice = markPrice.multiply(new BigDecimal("0.99")); // -1% |
||
| 46 | BigDecimal takeProfitPrice = markPrice.multiply(new BigDecimal("1.01")); // +1% |
||
| 47 | |||
| 48 | // Arredonda para 2 casas (ajusta conforme o tickSize do símbolo depois) |
||
| 49 | stopLossPrice = stopLossPrice.setScale(2, BigDecimal.ROUND_HALF_UP); |
||
| 50 | takeProfitPrice = takeProfitPrice.setScale(2, BigDecimal.ROUND_HALF_UP); |
||
| 51 | |||
| 52 | System.out.println("StopLoss = " + stopLossPrice + |
||
| 53 | " | TakeProfit = " + takeProfitPrice); |
||
| 54 | |||
| 55 | // 4) Montar o bracket: LONG (BUY) |
||
| 56 | BracketOrderRequest bracket = new BracketOrderRequest() |
||
| 57 | .setSymbol(symbol) |
||
| 58 | .setSide(OrderSide.BUY) |
||
| 59 | .setQuantity(qty) |
||
| 60 | .setEntryType(OrderType.MARKET) // entra a mercado |
||
| 61 | .setStopLossPrice(stopLossPrice) // SL < markPrice |
||
| 62 | .setTakeProfitPrice(takeProfitPrice) // TP > markPrice |
||
| 63 | .setWorkingType("MARK_PRICE"); // dispara pelo mark price |
||
| 64 | |||
| 65 | // 5) Enviar bracket |
||
| 66 | tradeService.placeBracketOrder(bracket); |
||
| 67 | |||
| 68 | System.out.println("Bracket enviado com sucesso (entrada + SL + TP)."); |
||
| 69 | */ |
||
| 70 | } catch (Exception e) { |
||
| 71 | System.err.println("ERRO EM TestBracketOrderMain:"); |
||
| 72 | e.printStackTrace(); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |