longportapp / openapi-sdk

LongPort OpenAPI SDK Base.
https://open.longportapp.com
Apache License 2.0
112 stars 11 forks source link

如何拉取期权的信息? #12

Open Endt4sk opened 8 months ago

Endt4sk commented 8 months ago
void on_quote_context_created(const struct lb_async_result_t* res)
{
    if (res->error) {
        printf("failed to create quote context: %s\n",
            lb_error_message(res->error));
        return;
    }

    *((const lb_quote_context_t**)res->userdata) = (const lb_quote_context_t*)res->ctx;

    const char* symbols[] = { "NVDA240301C800000.US" };
    lb_quote_context_quote((const struct lb_quote_context_t*)res->ctx, symbols, 1 on_quote, NULL);
}

拉取不到期权的信息。

huacnlee commented 8 months ago

你调用这个是个股行情接口,期权行情是另外一个函数:

Endt4sk commented 8 months ago

@huacnlee

你调用这个是个股行情接口,期权行情是另外一个函数:

谢谢,那用那个API可以获取期权的Gamma Delta这些数值?

sunli829 commented 7 months ago

https://open.longportapp.com/docs/quote/pull/calc-index

用这个接口

Endt4sk commented 7 months ago

@sunli829 感谢回复,我使用的C语言,用下面的方式获取的期权信息,怎么数据都是错的?除了收盘价行权价,其他的IV DELTA这些数据都对不上:

void OnSecurityCalcIndexCreated(const struct lb_async_result_t* res)
{
    if (res->error)
    {
        printf("failed to create quote context: %s\n", lb_error_message(res->error));
        return;
    }

    *((const lb_quote_context_t**)res->userdata) = (const lb_quote_context_t*)res->ctx;

    std::vector<const char*> symbols;
    symbols.push_back("NVDA240419C900000.US");
    lb_quote_context_calc_indexes((const struct lb_quote_context_t*)res->ctx, symbols.data(), symbols.size(), indexes, indexes_size, [](auto result)
        {
            if (!result)
            {
                //auto msg = lb_error_message(result->error);
                printf("failed to get quote!\n");
                return;
            }

            lb_security_calc_index_t* data = (lb_security_calc_index_t*)result->data;
            printf("Symbol: %s\n", data->symbol);
            printf("LastDone: %f\n", lb_decimal_to_double(data->last_done));
            printf("StrikePrice: %f\n", lb_decimal_to_double(data->strike_price));
            printf("Implied Volatility: %f\n", *data->implied_volatility);
            printf("Delta: %f\n", *data->delta);
            printf("Gamma: %f\n", *data->gamma);
            printf("Theta: %f\n", *data->theta);
            printf("Vega: %f\n", *data->vega);

        }, NULL);
}

Screenshot 2024-03-20 143258

QFCG commented 5 months ago

目前过期的期权行情只会保留 7 天,服务端返回的数据没有这个标的,您可以检查一下本地代码,打印的数据是哪里来的。