zerodha/phpkiteconnect

用于Kite Connect交易API资源的PHP客户端库

v4.2.0 2023-08-02 12:22 UTC

This package is auto-updated.

Last update: 2024-08-31 00:29:57 UTC


README

官方PHP客户端,用于与Kite Connect API进行通信。

注意:适用于PHP版本 < 8.0。您可以参考我们的旧版本
Kite Connect是一组类似REST的API,提供了构建完整投资和交易平台所需的各种功能。通过简单的HTTP API集合,您可以实时执行订单、管理用户投资组合等。

Zerodha Technology (c) 2021. 根据 MIT 许可证授权。

文档

安装

要求

  1. 安装PHP版本 8.0或更高。
  2. 安装Composer,它是用于安装PHP包的工具。

您可以通过Composer安装此包

composer require zerodha/phpkiteconnect

注意:对于PHP版本 < 8.0,您可以在此处参考我们的旧版本。

用法

<?php
    require_once __DIR__ . '/vendor/autoload.php';

    use KiteConnect\KiteConnect;

    // Initialise.
    $kite = new KiteConnect("your_api_key");

    // Assuming you have obtained the `request_token`
    // after the auth flow redirect by redirecting the
    // user to $kite->login_url()
    try {
        $user = $kite->generateSession("request_token_obtained", "your_api_secret");
        echo "Authentication successful. \n";
        print_r($user);
        $kite->setAccessToken($user->access_token);
    } catch(Exception $e) {
        echo "Authentication failed: ".$e->getMessage();
        throw $e;
    }

    echo $user->user_id." has logged in";

    // Get the list of positions.
    echo "Positions: \n";
    print_r($kite->getPositions());

    // Place order.
    $order = $kite->placeOrder("regular", [
        "tradingsymbol" => "INFY",
        "exchange" => "NSE",
        "quantity" => 1,
        "transaction_type" => "BUY",
        "order_type" => "MARKET",
        "product" => "NRML"
    ]);

    echo "Order id is ".$order->order_id;
?>

示例

查看示例文件夹获取更多示例。

有关支持方法的完整列表,请参阅PHP客户端文档

运行单元测试

phpunit tests/KiteConnectTest.php

生成文档

$ apt-get install wget
$ wget https://phpdoc.org/phpDocumentor.phar
$ chmod +x phpDocumentor.phar
$ ./phpDocumentor.phar run -d ./src/ -t ./doc/

变更日志

查看CHANGELOG.md