Jump to content


  • Content count

  • Joined

  • Last visited

  1. 500 error?

    Hello! I have been testing and developing a trading app for the past few months, however recently I have not changed anything in my api calls and have been getting 500 errors coming back. I was wondering if I need to make any changes to my code. Here is an example of a call POST https://ciapi.cityindex.com/TradingAPI/order/newtradeorder?UserName=****&Session=**** { "MarketID": 401484347, "Direction": "buy", "BidPrice": 1.10294, "OfferPrice": 1.10335 , "Quantity": 1000 , "OrderID": 0, "positionMethodId": 1, "TradingAccountId": 0, "MarketName": "EUR/USD", "isTrade": true } I made a call to account help and the practice account I am using for development is still active and I was able to use this up until last Tuesday when my server crashed. I got it all back up and running but I haven't had a trade since I got it back up. Was there an update to the api? Please let me know if I need to elaborate more.
  2. In a java machine, I am trying to open up trades at specific positions. For the past few weeks I have been having trouble when I have positions opening pips away from the given opening price (IE: We try to call to open a trade on the EUR/USD for 1.11070 and the price it opened at was 1.11062, or 1.10162 opening at 1.10251) We are streaming prices with a light streamer process but our listings are stored in a database filled out by the end user so as of right now there is a query to get information to plug into a trade but the data is going directly into the process that fires the http call. I don;t know if I need to find a faster way of getting information or is this an issue going to Forex's side. A snippet for reference: String response = null; String trade_sql = "SELECT * FROM Listings WHERE "+ "Listings.entry_point = "+offer_price+ " AND Listings.status = 'NOT OPEN' "+ "AND Listings.auto_flag = 'AUTO';"; resultset rs = execQuery(trade_sql); while(rs.next()) { //openTrade(string username, string session, double bidPrice, double entryPoint, int quantity, string marketName, int marketID) response = openTrade(username_cache, session_cache, trading_account_cache bid_price, rs.getDouble("Listings.entry_point"), rs.getInt("Listings.lot_size"), rs.getString("Listings.currency_pair"), rs.getInt("Listings.marketID")); break; } if (response != null) { //Update Listings table and record a log. } // OpenTrade code public static String openTrade(String username, String session, String tradingAccountID, double bidPrice, double entryPoint, int quantity, String marketName, int marketID) { String TradeBaseUrl = "https://ciapi.cityindex.com/TradingAPI/order/newtradeorder"; CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost postRequest = new HttpPost(TradeBaseUrl + "?UserName=" + username + "&Session=" + session); String jsonBody = "{" + "\"MarketID\": " + marketID + ", " + "\"Direction\": \"buy\", " + "\"BidPrice\": " + bidPrice + " , " + "\"OfferPrice\": " + entryPoint + " , " + "\"Quantity\": " + quantity + " , " + "\"OrderID\": 0, " + "\"positionMethodId\": 1, " + "\"TradingAccountId\": " + tradingAccountID + ", " + "\"MarketName\": \"" + marketName + "\", " + "\"isTrade\": true" + "}"; try { postRequest.setEntity(new StringEntity(jsonBody, ContentType.APPLICATION_JSON)); CloseableHttpResponse response = httpclient.execute(postRequest); if (response.getStatusLine().getStatusCode() == 200) { String responseBody = EntityUtils.toString(response.getEntity()); JSONObject json = new JSONObject(responseBody); return json.toString(); } else { System.out.println(response.getStatusLine()); } } catch (IOException e) { System.out.println(e.getMessage()); } finally { try { httpclient.close(); } catch (IOException e) { System.out.println("GainCapitalAPI: ERROR: " + e.getMessage()); } } I don't know if I am going too slow or what my problem is. If anyone could help me out I would be much appreciated.
  3. Hello World. I have been lurking and going over old forum posts for the past few weeks and have been able to begin to delve into the Gain API. I have a primarily php project that stores username and session keys on login and so far have gotten GET and POST url requests done, but I am still having trouble with getting a lightstreamer to subscribe to a stream for showing bid and ask prices. So far for the body I want the Bid and Ask/Offer Prices to appear at the head of a table with the code for that below here: <table> <tr> <td>Currency Selected: <?php print_r($_SESSION["currency_pair"]);?> </td> <td> <div id="marketID" data-source="lightstreamer" data-grid="stocks" name="Offer" data-field="Offer" data-item="item1"></div> </td> <td> <div id="marketID" data-source="lightstreamer" data-grid="stocks" data-item="item1" name="Bid" data-field="Bid"></div> </td> </tr> </table> As for my lightstreamer client code I have that at the bottom of the page like this: <script src="assets/js/require.js"></script> <script src="assets/js/lightstreamer.js"></script> <script> define("js/lsClient", ["LightstreamerClient", "StatusWidget"], function(LightstreamerClient, StatusWidget) { var protocolToUse = document.location.protocol != "file:" ? document.location.protocol : "http:"; var portToUse = document.location.protocol == "https:" ? "443" : "80"; // // var lsClient = new LightstreamerClient(protocolToUse + "//push.lightstreamer.com:" + portToUse, "DEMO"); lsClient.connectionSharing.enableSharing("OnlineDemoCommonConnection", "ATTACH", "CREATE"); lsClient.addListener(new StatusWidget("left", "0px", true)); lsClient.connect(); return lsClient; }); </script> <script> require(["LightstreamerClient","Subscription","StaticGrid"],function(LightstreamerClient,Subscription,StaticGrid) { //var ls = require(['lightstreamer-client']); var lsClient = new LightstreamerClient("https://push.cityindex.com", "STREAMINGALL"); lsClient.connectionDetails.setUser("<?php echo $_SESSION["username"]?>"); lsClient.connectionDetails.setPassword("<?php echo $_SESSION["login_session"]?>"); lsClient.connect(); var stocksGrid = new StaticGrid("stocks",true); stocksGrid.setAutoCleanBehavior(true,false); stocksGrid.addListener({ onVisualUpdate: function(key,info) { if (info == null) { //cleaning return; } var cold = (key.substring(4) % 2 == 1) ? "#eeeeee" : "#ddddee"; info.setAttribute("yellow", cold, "backgroundColor"); } }); var marketId = "401484317"; var stockSubscription = new Subscription("MERGE", ["PRICE."+ marketID], ["Bid", "Offer"], true); stockSubscription.addListener(stocksGrid); //stockSubscription.setItems(["PRICE.99588"]) stockSubscription.setDataAdapter("PRICES"); stockSubscription.setRequestedSnapshot("yes"); lsClient.subscribe(stockSubscription); }); </script> But whenever I run it on a local instance for testing, I receive an error in my Chrome Console stating that "IllegalArgumentException", message: "An item name cannot contain spaces". I feel like I am missing something extremely obvious but I have been trying small tweaks for hours. I would like an outside perspective to help see what I have missed.
  4. Hello I am currently trying to see about connecting to Forex for a project but I am unsure where to start, I am using a .php environment currently. I am truly a novice when it comes to this but I was hoping that someone could help point me in the right way.