Jump to content
Sign in to follow this  
aperson

Cant place trade on Demo account

Recommended Posts

Hi,

I tried the example post request body in the trade section of the CIAPI HTTP Reference under "Trades and Orders"  to make a sample trade with my credentials in the header section, but the response status is 2 instead of 200 and I got an empty array response when "GET"ing my open positions. 

 

Response after making a trade:

{
  Status: 2,
  StatusReason: 75,
  OrderId: 0,
  Orders: [
    {
      OrderId: 0,
      StatusReason: 160,
      Status: 10,
      OrderTypeId: 1,
      Price: 0,
      Quantity: 1,
      TriggerPrice: 0,
      CommissionCharge: 0,
      IfDone: [],
      GuaranteedPremium: 0,
      OCO: null,
      AssociatedOrders: [Object],
      Associated: false
    }
  ],
  Quote: null,
  Actions: [],
  ErrorMessage: null
}

 

My API CALL in Node.Js using node-fetch:

fetch('https://ciapi.cityindex.com/TradingAPI/order/newtradeorder',{
    method:'POST',
    headers:{
      'Accept': 'application/jso5n',
      'Content-Type':'application/json',
      'Session':session_id,
      'UserName':myid,
      'AppKey':'myappkey,
      'PassWord':'mypass'
    },
    body:JSON.stringify({"IfDone":[],"Direction":"buy","ExpiryDateTimeUTCDate":null,"LastChangedDateTimeUTCDate":null,
      "OcoOrder":null,"Type":null,"ExpiryDateTimeUTC":null,"Applicability":null,"TriggerPrice"
      :null,"BidPrice":1.4395,"AuditId":"8327595-0-0-0-R","AutoRollover":false,"MarketId":401166448,"OfferPrice"
      :1.4397,"Currency":null,"Quantity":1,"QuoteId":null,"LastChangedDateTimeUTC":null,"PositionMethodId"
      :1,"TradingAccountId":account_data.trade_account_id,
      "MarketName":"GBP/USD","Status":null,"isTrade":true})
    }).then(res=>res.json())
    .then(res=>{
      console.log(res);
    })

 

Share this post


Link to post

Hi,

The examples are not intended to be used verbatim in a users code. In this particular instance, you don't have access to the market used in the example. This is indicated by the error code of 160, which can be looked up at: http://docs.labs.gaincapital.com/#APICodesList.htm%3FTocPath%3DGetting%20Started|Lookup%20Values|_____1

You will need to substitute in correct values for the parameters in the call as appropriate. EG. a MarketId for a market that you do have access to trade.

Kind Regards, PM

Share this post


Link to post

I'm confused what the correct parameters are. Like if im just trying to do a simple buy/sell on the current market price for like USD/JPY for 1000 units, can you paste a sample of that?

 

Thanks

Share this post


Link to post

Hi,

Sure. The following is the body of a successful trade request. Please note, you should follow the directoins in http://docs.labs.gaincapital.com/#How Do I/Find Market ID.htm%3FTocPath%3DHow%20Do%20I...%3F|_____1 to find the MarketID for the USD/JPY market that you can trade.

{
    "MarketId": 401484414,
    "Direction": "buy",
    "Quantity": 1000,
    "BidPrice": 105.024,
    "OfferPrice": 105.04,
    "AuditId": "EF128019220",
    "TradingAccountId": 401637645,
    "PositionMethodId": 1,
    "IfDone": []
}

 

Kind Regards, PM

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×