joaopsilva / binance-java-api

binance-java-api is a lightweight Java library for the Binance API, supporting synchronous and asynchronous requests, as well as event streaming using WebSockets.
208 stars 803 forks source link

"For" with 3 Apikey runs all purchases only for the first (apikey) account of the list. #18

Open csdiftec opened 5 years ago

csdiftec commented 5 years ago

I have 3 'ApiKey' different accounts and 1 invalid, but no matter what I do in the for the purchase is only posted to the account of the first ApiKey, example; if the first one is invalid all are invalid, if you launch the purchase and it is validated, all are being validated for the same account but with the correct values ​​of each purchase. I do not know how to close or open each "session" something of the type. What should I do?

              List<Ticket> listTicket = (List<Ticket>) ticketServiceImpl.findAll(); 
               for (int i = 0; i < listTicket.size(); i++) {

            String apiKey = listTicket.get(i).getUser().getApiKey().toString();
            String secretKey = listTicket.get(i).getUser().getSecretKey().toString();   

            buy(currencyPair, stringAmountBuy, apiKey, secretKey, purchasePrice);           
            }
         }

`public class Buy {

public  void buy(String currencyPair,String amountBTC,String apiKey,String secretKey,BigDecimal purchasePrice) {

    BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(apiKey,secretKey);
    BinanceApiRestClient client = factory.newRestClient();

    String purchasePriceString = String.valueOf(purchasePrice);

    NewOrderResponse newOrderResponse = client.newOrder(limitBuy(currencyPair, TimeInForce.GTC, amountBTC, purchasePriceString));

    System.out.println("Class buy..."+ newOrderResponse);

}

}`