Placing/Retrieving orders

Hi,

I have already built most of the interface for my app. However, I can not crack what I’m doing wrong with placing bets. I keep getting the result “AUTH_REQUIRED”. I guess would be that it is something wrong with authorisation, but I add my Session key to the header or my request. Please see my code below:

public static PlaceOrderResponse PlaceOrder(long contractId, long marketId, long price, long quantity)
{
var client = new RestClient(“https://api.smarkets.com/v3/orders/”);
var request = new RestRequest(Method.POST);
request.AddHeader(“cache-control”, “no-cache”);
request.AddHeader(“Connection”, “keep-alive”);
request.AddHeader(“Accept-Encoding”, “gzip, deflate”);
request.AddHeader(“Authorization”, _sessionKey);
request.AddHeader(“accept”, “application/json”);
request.AddParameter(“undefined”, “{“contract_id”:”" + contractId + “”,“label”:“strategy_1”," +
““market_id”:”" + marketId + “”,“minimum_accepted_quantity”:1," +
““price”:” + price + “,” +
““quantity”:” + quantity + “,“side”:“buy”,“type”:“good_til_halted”}”, ParameterType.RequestBody);
var response = client.Execute(request);
var orderResponse = JsonWrapper.FromJson(response.Content);
return orderResponse;
}

Anyone have an idea what I am doing wrong here?

The code looks good to me.
Can you make sure that _sessionKey is in the format: ‘Session-Token < token >’ ?

Hi Joao,

Thanks for getting back to my initial post. Your response got me on track. apparently, rather than

it is ‘User-Session-Token=’ .

I have added the following line to my code
request.AddHeader(“Cookie”, “User-Session-Token=”+ _sessionKey);

and it works perfectly fine now.

Just in case anyone needs full working c# code, you can use the following:

public static PlaceOrderResponse PlaceOrder(long contractId, long marketId, long price, long quantity)
{
var client = new RestClient(“https://api.smarkets.com/v3/orders/”);
var request = new RestRequest(Method.POST);
request.AddHeader(“cache-control”, “no-cache”);
request.AddHeader(“Connection”, “keep-alive”);
request.AddHeader(“Accept-Encoding”, “gzip, deflate”);
request.AddHeader(“Cookie”, “User-Session-Token=” + _sessionKey);
request.AddHeader(“Content-Type”, “application/json”);
request.AddHeader(“Authorization”, _sessionKey);
request.AddHeader(“accept”, “application/json”);
request.AddParameter(“undefined”, “{“contract_id”:”" + contractId + “”,“label”:“strategy_1”,“market_id”:"" + marketId +
“”,“minimum_accepted_quantity”:1,“price”:" + price + “,“quantity”:” + quantity + “,“side”:“buy”,“type”:“good_til_halted”}”, ParameterType.RequestBody);
var response = client.Execute(request);
var orderResponse = JsonWrapper.FromJson(response.Content);
return orderResponse;
}

Have a nice day :slight_smile:

2 Likes