I’m trying to connect to https://collective2.com/world/apiv3/submitSignal to submit signals for my strategy, but I get a response stating:
{
"ok" : "0",
"error" : {
"title" : "Missing apikey",
"message" : "You need to send an apikey parameter. Think you sent one? Make sure you use https. Need key? Contact help@collective2.com"
}
}
I’m not exactly sure how to connect to the URL and send my apikey along with my command in JSON. What I’ve been able to do so far is establish a connection and try submitting signals. However, I get this error back even before I send any requests. I’m very new to this and haven’t been able to find anything online to help with establishing a proper connection.
Here is my code for connecting:
public static void initialize() throws IOException
{
String httpsURL = "https://collective2.com/world/apiv3/submitSignal";
URL myurl = new URL(httpsURL);
con = (HttpsURLConnection)myurl.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-Type","text/xml");
output = new OutputStreamWriter(con.getOutputStream());
input = new BufferedReader(new InputStreamReader(con.getInputStream()));
printFromWeb(); //Where I get the error message
}
//Place an order
@SuppressWarnings({ "unchecked"})
public static void placeOrder(String action, int quantity, String symbol, String typeOfSymbol, Double LMTPrice) throws IOException
{
JSONObject order = new JSONObject();
JSONObject signal = new JSONObject();
order.put("apikey", key); //Key is initialized somewhere else
order.put("systemid", systemID); //SystemID is initialized somewhere else
signal.put("action", "BTO");
signal.put("quant", quantity);
signal.put("typeofsymbol", typeOfSymbol);
signal.put("symbol", symbol);
if(LMTPrice == 0)
signal.put("market", 1);
else
signal.put("limit", LMTPrice);
signal.put("duration", "GTC");
order.put("signal", signal);
System.out.println("Delivered order to server: "+ order.toString());
output.write(order.toString());
output.flush();
}
public static void printFromWeb() throws IOException
{
System.out.println("From Website: ");
while(input.ready())
System.out.println(input.readLine());
}