相关疑难解决方法(0)

从控制台应用程序发出 POST 请求会导致错误 403 - 访问被拒绝

我正在尝试使用新的 IBKR 客户端 API。我编写了一个简单的控制台程序来访问 API,但它导致错误 403 - 访问被拒绝。如果我尝试邮递员的相同请求,它似乎有效。我尝试使用 fiddler 查看控制台应用程序发送的请求,但这会导致单独的错误。我该如何诊断这个问题?

using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var baseURL = "https://localhost:5000/v1/portal";
            HttpClientHandler handler = new HttpClientHandler();
            handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
            var client = new HttpClient(handler);
            client.DefaultRequestHeaders.Add("Cookie", "ibkr.il = 123456789.123456.0000");
            client.DefaultRequestHeaders.Add("AcceptEncoding", "gzip, deflate, br");
            var response = await client.GetAsync(baseURL + "/sso/validate");
            string result = response.Content.ReadAsStringAsync().Result;
            Console.WriteLine(result);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# interactive-brokers .net-core

5
推荐指数
1
解决办法
793
查看次数

使用 API 请求在盈透证券下订单

首先,我成功地使用 TWS API 下了订单。然而,据我了解,为此,我需要在后台运行 TWS 桌面版本。但我需要在我的远程服务器上运行它。因此,我使用了名为 IBeam 的第三方 API,并在远程服务器中使用它创建了一个网关。现在它运行良好,可以满足我从盈透证券请求的 GET 请求。

现在,我想使用 API 请求在 Interactive Broker 中下订单,并通过 IB找到了此文档。然而,对我来说,不清楚他们每个论点的含义,所以到目前为止我陷入了困境。即,从文档中,我需要使用请求正文将 POST 请求发送到 https://localhost:5000/v1/api/iserver/account/{accountId}/orders (IB 网关在 localhost:5000 中运行)

{
  "orders": [
    {
      "acctId": "string",
      "conid": 0,
      "secType": "secType = 265598:STK",
      "cOID": "string",
      "parentId": "string",
      "orderType": "string",
      "listingExchange": "string",
      "isSingleGroup": true,
      "outsideRTH": true,
      "price": 0,
      "auxPrice": null,
      "side": "string",
      "ticker": "string",
      "tif": "string",
      "referrer": "QuickTrade",
      "quantity": 0,
      "fxQty": 0,
      "useAdaptive": true,
      "isCcyConv": true,
      "allocationMethod": "string",
      "strategy": "string",
      "strategyParameters": {}
    } …
Run Code Online (Sandbox Code Playgroud)

python api gateway interactive-brokers

5
推荐指数
1
解决办法
2422
查看次数

标签 统计

interactive-brokers ×2

.net-core ×1

api ×1

c# ×1

gateway ×1

python ×1