lupecode/php-trader-native

PHP Trader 扩展的本地版本。

v2.1.0 2023-11-26 19:16 UTC

This package is auto-updated.

Last update: 2024-09-24 23:17:00 UTC


README

这是一个 PHP 端的 Trader 扩展,它是 TA-LIB C/Java 代码的移植。

这个移植版本是用 PHP 编写的,且没有其他要求。

目标是让那些无法安装 PHP Trader 扩展的人也能使用这个库。

PHPUnit Tests

要求

  • PHP >= 8.0.0

这就是你需要的一切!正如所述,你不需要为这个库安装任何扩展。

安装

这个库旨在使用 composer 安装。

composer require lupecode/php-trader-native

使用

直接替换

这个库旨在作为 Trader 扩展的直接替换,它包含了对 Trader 扩展的 polyfill。

友好命名的替换

这个包提供的另一个选项是使用更易理解的函数名称。

如果你不想使用 adosc,因为它不够描述性,你可以使用 chaikinAccumulationDistributionOscillator,如下所示: TraderFriendly::chaikinAccumulationDistributionOscillator($high, $low, $close, $volume, $fastPeriod, $slowPeriod)

关于默认值的说明

TA-LIB 的 PECL 版本 "Trader" 中的函数没有正确的默认值。快速查看显示,许多函数使用可选参数的最小值,而不是 TA-LIB C/Java 版本中使用的默认值。一些测试,如 testAdOscDefaultsDifferent,只要 PECL Trader 库使用与 C/Java 代码中不同的默认值,就会通过。

对于好奇的人,AdOsc 的 TA-LIB 源代码可以在 这里 查看,默认值为 3 和 10,而 PECL Trader 的源代码可以在 这里 查看,默认值为 2 和 2。

这个包使用 C/Java 的默认值,而不是 PECL 的默认值。

速度

鉴于这个库是用纯 PHP 编写的,所以它的运行速度比用 C 编写的 PECL 扩展慢。我的基准测试显示,根据函数的不同,速度慢 5 倍到 30 倍。

我欢迎任何优化方面的帮助! 我没有对这个库进行优化;它只是从 C 到 PHP 的简单转换。

贡献/开发

要求

  • PHP >= 8.0.0
  • ext_trader >= 0.4.1 这里

设置

检出存储库,然后使用 composer 安装。

git checkout git@github.com:LupeCode/phpTraderNative.git
cd phpTraderNative
composer install --dev

目录结构

  • source - 库的源代码。
  • tests - 库的 PHPUnit 测试。
  • pecl - PECL Trader 扩展的源代码。
  • talib - PECL Trader 扩展使用的 TA-LIB 源代码。

测试

包含两个 PHPUnit XML 文件,一个用于测试,另一个用于覆盖率。这是由于当一些测试与覆盖率一起运行时,PHP 会挂起且永远不会结束。

使用以下命令运行测试:

php -dxdebug.coverage_enable=0 ./vendor/phpunit/phpunit/phpunit --configuration ./phpunit.xml ./tests

使用以下命令运行覆盖率:

php -dxdebug.coverage_enable=1 ./vendor/phpunit/phpunit/phpunit --configuration ./phpunit_coverage.xml ./tests

许可协议

以下是从源代码中找到的 TA-LIB 版权信息。

TA-LIB Copyright (c) 1999-2007, Mario Fortier
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice,
 this list of conditions and the following disclaimer.

- Redistributions in binary form must reproduce the above copyright
 notice, this list of conditions and the following disclaimer in the
 documentation and/or other materials provided with the distribution.

- Neither name of author nor the names of its contributors may be used
 to endorse or promote products derived from this software without
 specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

以下是将代码移植到 PHP 的许可协议。

MIT License

Copyright (C) Lupe Code, LLC.; Joshua Lopez

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.