Skip to content

Http

interface cAlgo.API

DesktopCLICloud

The Https interface contains the methods necessary for sending HTTP requests.

Environment behaviour

Cloud — not supported. No request is sent. The response, or the callback, has IsSuccessful false, StatusCode 403 and Body null. No exception is thrown.

Definition

public interface Http

Namespace: cAlgo.API · Group: HTTP

Examples

Example 1

using cAlgo.API;

namespace cAlgo.Robots;

public partial class Test : Robot
{
    protected override void OnStart()
    {
        var response = Http.Get("https://api.restful-api.dev/objects");

        if (!response.IsSuccessful)
        {
            Print("HTTP request failed");
            return;
        }

        Print(response.Body);
    }
}
import clr

clr.AddReference("cAlgo.API")

# Import cAlgo API types
from cAlgo.API import *
# Import trading wrapper functions
from robot_wrapper import *

class Test():
    def on_start(self):
        response = api.Http.Get("https://api.restful-api.dev/objects")

        if response.IsSuccessful == False:
            print("HTTP request failed")
            return

        print(response.Body)
{
  "AccessRights": "None"
}

Example 2

using cAlgo.API;

namespace cAlgo.Robots;

public partial class Test : Robot
{
    protected override void OnStart()
    {
        var request = new HttpRequest(new("https://api.restful-api.dev/objects"));

        request.Headers.Add("Authorization", "Bearer token");

        var response = Http.Send(request);

        if (!response.IsSuccessful)
        {
            Print("HTTP request failed");
            return;
        }

        Print(response.Body);
    }
}
import clr

clr.AddReference("cAlgo.API")

# Import cAlgo API types
from cAlgo.API import *
# Import trading wrapper functions
from robot_wrapper import *
from System import Uri

class Test():
    def on_start(self):
        request = HttpRequest(Uri("https://api.restful-api.dev/objects"))
        request.Headers.Add("Authorization", "Bearer token")

        response = api.Http.Send(request)

        if response.IsSuccessful == False:
            print("HTTP request failed")
            return

        print(response.Body)
{
  "AccessRights": "None"
}

Methods

Name Description
Get 2 overloadsDesktopCLICloudHttpResponse Performs a GET request to the specified URI.
GetAsync 2 overloadsDesktopCLICloudvoid Performs a GET request to the specified URI asynchronously.
SendDesktopCLICloudHttpResponse Performs a request to the specified URI. The request method depends on the value of the request.Method property.
SendAsyncDesktopCLICloudvoid Performs a request to the specified URI. The request method depends on the value of the request.Method property.

See also