I’m having a problem with my extension, I can’t complete it, I’m using Ide Niotron to generate the extension:
package com.Binance.Api;
import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import okhttp3.*;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
@DesignerComponent(
version = 1,
description = "Api modular Binance!",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "")
@SimpleObject(external = true)
public class ApiBinance extends AndroidNonvisibleComponent {
// Activity and Context
private Context context;
private Activity activity;
// API credentials
private String apiKey;
private String apiSecret;
// API endpoint
private String apiUrl;
// OkHttpClient instance
private OkHttpClient client;
// Additional parameters for order
private String timestamp;
private String recvWindow;
private String signature;
public ApiBinance(ComponentContainer container){
super(container.$form());
this.activity = container.$context();
this.context = container.$context();
client = new OkHttpClient();
}
@SimpleFunction(description = "Set API credentials and URL")
public void SetApiCredentials(String apiKey, String apiSecret, String apiUrl){
this.apiKey = apiKey;
this.apiSecret = apiSecret;
this.apiUrl = apiUrl;
}
@SimpleFunction(description = "Set additional parameters for order")
public void SetOrderParameters(String timestamp, String recvWindow, String signature) {
this.timestamp = timestamp;
this.recvWindow = recvWindow;
this.signature = signature;
}
@SimpleFunction(description = "Create a signature for the request")
public String CreateSignature(String data, String secretKey) throws NoSuchAlgorithmException, InvalidKeyException {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(secretKey.getBytes(), "HmacSHA256");
sha256_HMAC.init(secret_key);
return bytesToHex(sha256_HMAC.doFinal(data.getBytes()));
}
@SimpleFunction(description = "Make a buy order")
public void MakeBuyOrder(String symbol, String quoteOrderQty) throws IOException {
String data = "symbol=" + symbol + "&side=BUY"eOrderQty=" + quoteOrderQty + "×tamp=" + timestamp + "&recvWindow=" + recvWindow;
MakeOrder(data);
}
@SimpleFunction(description = "Make a sell order")
public void MakeSellOrder(String symbol, String quantity) throws IOException {
String data = "symbol=" + symbol + "&side=SELL&quantity=" + quantity + "×tamp=" + timestamp + "&recvWindow=" + recvWindow;
MakeOrder(data);
}
private void MakeOrder(String data) throws IOException {
RequestBody body = new FormBody.Builder()
.add("signature", signature)
.build();
Request request = new Request.Builder()
.url(apiUrl + "/v3/order")
.addHeader("X-MBX-APIKEY", apiKey)
.post(body)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
String responseData = response.body().string();
// Dispatch event or return data to Kodular
}
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
// Handle failure
}
});
}
// Other functions for getting account info, etc.
// Helper function to convert bytes to hexadecimal string
private static String bytesToHex(byte[] bytes) {
StringBuilder result = new StringBuilder();
for (byte b : bytes) {
result.append(String.format("%02x", b));
}
return result.toString();
}
}
When compiling and importing into Kodular I am getting the following error: invoke: no method named `SetApiCredentials’ in class java.lang.Boolean Note: You will not see errors announced for the next 5 seconds.
Akguma light, any solution?