Jump to content


  • Content count

  • Joined

  • Last visited

  1. Good day, I am curious if there is a way to pull daily rolloever rates (e.g. daily interest rate) for holding a position open overnight using the API? I searched the Gain docs library for information on "rollover" but didn't find much. I did find a couple references to "future rollover", "autorollover", etc. But I think this applies more to setting whether or not you want an options position to automatically rolloever near expiration. Rollover data would be very useful in calculating daily cost of maintaining an open position overnight and estimating or projecting cost for maitaining a position for a duration of time. Thanks in advance, Brent
  2. @Physicsman and Forum Good day everybody, Together with Physicsman we were able to resolve the above issue. Thanks again, Physicsman, for your assistance and determination in finding a solution. For those of you who are attempting to log onto the API using python, please review the following code snippet and result. NOTE language: python, platform: Google Colab RECOMMENDATIONS: 1.) Call customer service to confirm two things: 1.) there are NO security locks for multiple failed attempts on the account you are trying to log onto 2.) confirm you account details (username, password, and AppKey). I discovered that the accounts team accidentally sent me the account number as the username. But they were able to quickly correct this and provide me the correct username. So, make sure to confirm these details with customer service. Once you have done these things, try using the code below: Remember to substitute your credials for your specific account. Code import requests import json url = 'https://ciapi.cityindex.com/TradingAPI/session/' data = {'Password':'XXXXXXX', 'UserName':'DM123456', 'AppKey':'ABC' } response = requests.post(url, json=data) print(response.url) print(response.status_code) print(response.text) Result: Response 200 means successful connection. From the response you can get your session id for other API functions https://ciapi.cityindex.com/TradingAPI/session/ 200 {"Session":"081ei2-awe234322-we23dr-223serrwd","PasswordChangeRequired":false,"AllowedAccountOperator":false,"StatusCode":1,"AdditionalInfo":null,"Is2FAEnabled":false,"TwoFAToken":null,"Additional2FAMethods":null,"UserType":1}
  3. Good afternoon, PM. Ok, that sounds like a plan. I have sent my demo account credentials to you via private message. Please keep an eye out for that. I look forward to seeing what you discover. Thanks again, Brent
  4. @Physicsman Thanks very much, PM. I haven't any experience with Postman, but it looks like a useful app. I will try to come up to speed on that. Thanks for the assistance. God's blessings to you and yours. With Much Respect, Brent
  5. @Physicasman Good day, PM Thanks very much for your respose and assistance. My apologies, I should have mentioned the following in my original post, but I didn't want to confuse the issue. I did try the URL without the "/post" at the end, and I received a different error. (I will post the code and result below for details.) I am curious if maybe I need to identify something more regarding 'content-type' in the header or maybe something more in json. NOTE I don't know if this is significant or not, but I am trying to log onto a demo account. Also, my account is a commission based account. This is my code and error when I try without the "/post" at the end: import requests payload = {"Password":"openthedoor", "AppVersion":"1", "AppComments":"", "UserName":"DM123456", "AppKey":"ABC" } response = requests.post('https://ciapi.cityindex.com/TradingApi/session/', data=payload) print(response.url) print(response.status_code) print(response.text) Result: with error message ending with "ErrorCode":4005 https://ciapi.cityindex.com/TradingApi/session/ 400 {"HttpStatus":400,"ErrorMessage":"The request content-type is not supported","ErrorCode":4005} I did find a prior post regarding a similar issue for a person using java....But I am not sure if this would solve my issue or how to implement this in python... ============================================================================= Also, just out of curiousity, I found another potential solution online. I tried including more info in the header in hopes to trigger a content-type or other json response, and I got an even stranger error message yet.... This is the code of that example and the result: import requests import json Newheader = {'Content-type': 'application/json', 'Accept': 'text/plain'} payload = {"Password":"openthedoor", "AppVersion":"1", "AppComments":"", "UserName":"DM123456", "AppKey":"ABC" } response = requests.post('https://ciapi.cityindex.com/TradingAPI/session/', data=payload, headers=Newheader) print(response.url) print(response.status_code) print(response.text) Result: with error message ending with "ErrorCode":4002 https://ciapi.cityindex.com/TradingApi/session// 400 {"HttpStatus":400,"ErrorMessage":"The request body cannot be null.","ErrorCode":4002} ============================================================================= What else could we try to resolve this issue? I am more concerned about the first error than the second. Please let me know your thoughts. Thanks Much,
  6. Good evening, I thought I had my session code squared away, but appears I was wrong. I am new to the Forex API and I am experiencing a strange error when I try to create my first session. ISSUE: I am utilizing the 'requests' library in python and Google Colab to interact with the API. I am attempting to create a session per the URI in the 'LogOn' documentation combined with a payload containing the username, password and appkey provided to me when my API account was set up. I've confirmed and re-confirmed several times that I am using the correct URI, username, password, and appkey. (For this post, I've changed the payload values to generic values.) I've also included a few print statements to provide some visibility of the system responses. Upon running my code (please see below), the status code returns a value of 404. In: import requests payload = {"Password":"openthedoor", "AppVersion":"1", "AppComments":"", "UserName":"DM123456", "AppKey":"ABC" } response = requests.post('https://ciapi.cityindex.com/TradingAPI/session/post', data=payload) print(response.url) print(response.status_code) print(response.text) Out: https://ciapi.cityindex.com/TradingAPI/session/post 404 Does anybody know why this is occurring and what I might be able to do to resolve it? Thanks in advance, ....
  7. Good day, I am new to the Forex API and would appreciate some assistance. I performed a search on previous topics, but didn't find much addressing this issue. I am currently using python and executing code from Google Colab. Regarding being able to authenticate and 'LogOn' per the API documentation, I believe I have all that ready to go. MY GOAL: I want to be able to: 'LogOn' (create a session) # I have this part covered perform my code activities # I have this part covered then be able to log off rather than leaving my session in limbo until it expires thus having to deal with expired tokens, etc. Also, I believe this will free up resources for other users. MY ISSUE: Source: https://docs.labs.gaincapital.com/#HTTP Services/DeleteSession.htm?Highlight=Log out According to the API documentation, the URL call to log off and terminatate a session is as follows: POST https://ciapi.cityindex.com/TradingAPI/session/deleteSession?UserName=DM1234567&Session=ABCD890 My concern is the last part of this URL string calls for 'Session=ABCD890'. Clearly this is a generic example for documentation purposes. I am wondering once I open a session, where can my code find/read this session ID and the include it in the URL so as to effectively end the session? A sample python code snippet that would grab this value and add it to the URL would be greatly appreciated. Thanks in advance.