VictoryCodeDev / metaapi-cloud-php-sdk
MetaApi的专业云外汇API的PHP SDK
Requires
- php: ^8.1|^8.2
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpunit/phpunit: ^10.0
README
一个PHP包,让您无缝执行对Metapapi https://metaapi.cloud/ 的API调用。注意:此包不包含Metapi中的所有API调用。您可以进行CopyTrade、账户管理和指标。
安装
要将SDK安装到您的项目中,您需要通过composer安装此包
composer require victorycodedev/metaapi-cloud-php-sdk
用法
账户管理
您可以这样创建SDK实例以进行账户管理
use Victorycodedev\MetaapiCloudPhpSdk\AccountApi; $account = new AccountApi('AUTH_TOKEN');
所有方法在请求不成功时都会抛出异常,因此请确保将您的代码放在try和catch块中。
when statusCode >= 200 && statusCode < 300;
您可以这样添加交易账户并启动云API服务器
try { return $account->create([ "login" => "123456", "password" => "password", "name" => "testAccount", "server" => "ICMarketsSC-Demo", "platform" => "mt5", "magic" => 123456 ]); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
如果请求成功,您将获得账户ID和状态,否则将抛出异常
[ "id" => "1eda642a-a9a3-457c-99af-3bc5e8d5c4c9", "state" => "DEPLOYED" ]
您可以通过ID读取账户
try { return $account->readById("1eda642a-a9a3-457c-99af-3bc5e8d5c4c9"); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
您可以读取您的MetaApi账户中的所有交易账户
try { return $account->readAll(); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
您可以更新账户
try { return $account->update("1eda642a-a9a3-457c-99af-3bc5e8d5c4c9",[ "password" => "password", "name" => "testAccount", "server" => "ICMarketsSC-Demo", ]); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
取消部署账户
try { return $account->unDeploy("1eda642a-a9a3-457c-99af-3bc5e8d5c4c9"); // you can pass other parameters return $account->unDeploy("1eda642a-a9a3-457c-99af-3bc5e8d5c4c9", false); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
部署账户
try { return $account->deploy("1eda642a-a9a3-457c-99af-3bc5e8d5c4c9"); // you can pass other parameters return $account->deploy("1eda642a-a9a3-457c-99af-3bc5e8d5c4c9", false); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
重新部署账户
try { return $account->reDeploy("1eda642a-a9a3-457c-99af-3bc5e8d5c4c9"); // you can pass other parameters return $account->reDeploy("1eda642a-a9a3-457c-99af-3bc5e8d5c4c9", false); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
删除账户
try { return $account->delete("1eda642a-a9a3-457c-99af-3bc5e8d5c4c9"); // you can pass other parameters return $account->delete("1eda642a-a9a3-457c-99af-3bc5e8d5c4c9", true); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
CopyFactory
您可以这样创建SDK实例以进行Copyfactory
use Victorycodedev\MetaapiCloudPhpSdk\CopyFactory; $copyfactory = new CopyFactory('AUTH_TOKEN');
生成策略ID
try { return $copyfactory->generateStrategyId(); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
获取所有策略
try { return $copyfactory->strategies(); //you can also pass in other parameters like so return $copyfactory->strategies(includeRemoved: true, limit: 1000, offset: 0 ); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
获取单个策略
try { return $copyfactory->strategy("strategid"); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
更新策略
try { return $copyfactory->updateStrategy("strategid", [ "name" => "Test strategy", "description" => "Some useful description about your strategy", "accountId" => "105646d8-8c97-4d4d-9b74-413bd66cd4ed" ]); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
删除策略
try { return $copyfactory->removeStrategy("strategid"); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
获取所有订阅者
try { return $copyfactory->subscribers(); //you can also pass in other parameters like so return $copyfactory->subscribers(includeRemoved: true, limit: 1000, offset: 0 ); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
获取订阅者
try { return $copyfactory->subscriber("subscriberiId"); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
更新订阅者数据
try { return $copyfactory->updateSubscriber("subsciberId", [ 'name' => "Copy Trade Subscriber", 'subscriptions' => [ [ 'strategyId' => 'dJZq', 'multiplier' => 1, ] ] ]); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
删除订阅者
try { return $copyfactory->removeSubscriber("subsciberId"); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
删除订阅
try { return $copyfactory->deleteSubscription("subsciberId", "strategyId"); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
Copy Trade
从提供者复制交易到订阅者。建议您在执行复制交易之前创建一个策略并将其保存到数据库中,但这不是强制性的,因为包会为您创建一个。您始终可以通过 "$copyfactory->strategies()" 读取账户中的所有策略。
进行复制交易的操作
try { $strategyId = "yd24"; $providerAccountId = "Enter your provider account ID"; $subAccountId = "Enter Subscriber Account ID"; return $copyfactory->copy($providerAccountId, $subAccountId, $strategyId); /* * You can ommit the strategy Id and just copy the trade * The package will create a strategy as part of the copy process. */ return $copyfactory->copy($providerAccountId, $subAccountId); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
注意:复制交易可能需要一些时间才能完成,您可以在反馈中使用加载指示器。
MetaStats
您可以为您的账户获取指标
您可以这样创建SDK实例以进行MetaStats
use Victorycodedev\MetaapiCloudPhpSdk\MetaStats; $stats = new MetaStats('AUTH_TOKEN');
获取指标
try { return $stats->metrics("accountId"); // You can pass a boolean as second parameter if you want to include open positions in your metrics return $stats->metrics("accountId", true); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
获取MetaApi账户的开放交易
try { return $stats->openTrades("accountId"); } catch (\Throwable $th) { $response = json_decode($th->getMessage()); return $response->message; }
测试
composer test
API参考
所有API参考都可以在Metaapi文档网站上找到。 https://metaapi.cloud/
安全
如果您发现任何与安全相关的问题,请提交问题。
贡献
欢迎拉取请求。
我该如何感谢您呢?
为什么不星标GitHub仓库?我非常希望得到关注!您可以在Twitter或HackerNews上分享此存储库的链接?
别忘了关注我在Twitter上!
谢谢!Efekpogua Victory。
许可证
MIT许可证(MIT)。请参阅许可证文件或更多信息。