Intermittent 401 response when placing bets

I’m just getting my system up and running. Everything appears to be going well but I occasionally get 401 errors when placing bets. I’d say around 95% of the time it all works well.

Details below - any ideas why this is failing intermittently?

Here is my response/error from my log:
22/08/2019 13:31:47 : Failed to place bet : 401
22/08/2019 13:31:47 : {“data”:null,“error_type”:“AUTH_REQUIRED”}

Here is my code:
//Set up the bet
Bet TheBet = new Bet();
TheBet.contract_id = OutcomeID.ToString();
TheBet.market_id = MarketID.ToString();
TheBet.label = StrategyName;
TheBet.minimum_accepted_quantity = MinQuantity;
TheBet.price = Convertor.ConvertPriceToBasisPoints(Price);
TheBet.quantity = Convertor.ConvertStakeToQuantity(Stake,Price);
TheBet.minimum_accepted_quantity = MinQuantity;
TheBet.reference_id = UniqueID;
TheBet.side = Polarity.ToLower();
TheBet.type = BetType;

        string beturl;
        beturl = "https://api.smarkets.com/v3/orders/";

        //Get Token
        var client = new RestClient(beturl);
        var request = new RestRequest(Method.POST);
        request.AddCookie("__cfduid", _cfduid);
        request.AddCookie("User-Session-Token", _UserSessionToken);
        request.AddHeader("Cache-Control", "no-cache");
        request.AddHeader("Content-Type", "application/json");
        request.AddHeader("Authorization", _UserSessionToken);
        request.AddJsonBody(TheBet);

This actually looks to be caused by an earlier 504 response to a logon request. Will monitor the logs to see how often this is occurring

1 Like