正在显示
5 个修改的文件
包含
90 行增加
和
0 行删除
examples/okBroker.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +require_once __DIR__ . '/../trader/CmBroker.php'; | ||
| 4 | +require_once __DIR__ . '/../trader/struct/ApiInfo.php'; | ||
| 5 | +require_once __DIR__ . '/../jytools/BinanceFutures.php'; | ||
| 6 | +require_once __DIR__ . '/../jytools/func.php'; | ||
| 7 | + | ||
| 8 | +use trader\struct\ApiInfo; | ||
| 9 | +use trader\struct\WsData; | ||
| 10 | +use trader\CmBroker; | ||
| 11 | +use function jytools\output; | ||
| 12 | + | ||
| 13 | +$key = ""; | ||
| 14 | +$secret = ""; | ||
| 15 | +$passphrse = ""; | ||
| 16 | +$apiInfo = new ApiInfo($key, $secret, $passphrse); | ||
| 17 | +$wsHost = "ws://okws.keetu.com"; | ||
| 18 | +$restHost = "http://okapi.keetu.com"; | ||
| 19 | +$broker = new CmBroker(CmBroker::PLAT_OKX, $apiInfo, $wsHost, $restHost); | ||
| 20 | + | ||
| 21 | +output("开始测试"); | ||
| 22 | + | ||
| 23 | +$res = $broker->getIndexTickers(); | ||
| 24 | +output($res); |
| @@ -17,6 +17,7 @@ require_once __DIR__ . '/struct/WsDataOrder.php'; | @@ -17,6 +17,7 @@ require_once __DIR__ . '/struct/WsDataOrder.php'; | ||
| 17 | require_once __DIR__ . '/struct/WsDataAccount.php'; | 17 | require_once __DIR__ . '/struct/WsDataAccount.php'; |
| 18 | require_once __DIR__ . '/struct/Pos.php'; | 18 | require_once __DIR__ . '/struct/Pos.php'; |
| 19 | require_once __DIR__ . '/struct/Premium.php'; | 19 | require_once __DIR__ . '/struct/Premium.php'; |
| 20 | +require_once __DIR__ . '/struct/IndexTicker.php'; | ||
| 20 | require_once __DIR__ . '/../jytools/func.php'; | 21 | require_once __DIR__ . '/../jytools/func.php'; |
| 21 | require_once __DIR__ . '/../jytools/Websocket.php'; | 22 | require_once __DIR__ . '/../jytools/Websocket.php'; |
| 22 | 23 | ||
| @@ -36,6 +37,7 @@ use trader\struct\WsDataOrder; | @@ -36,6 +37,7 @@ use trader\struct\WsDataOrder; | ||
| 36 | use trader\struct\WsDataAccount; | 37 | use trader\struct\WsDataAccount; |
| 37 | use trader\struct\Pos; | 38 | use trader\struct\Pos; |
| 38 | use trader\struct\Premium; | 39 | use trader\struct\Premium; |
| 40 | +use trader\struct\IndexTicker; | ||
| 39 | use \Exception; | 41 | use \Exception; |
| 40 | use function jytools\timeFormat; | 42 | use function jytools\timeFormat; |
| 41 | use function jytools\getMicrotime; | 43 | use function jytools\getMicrotime; |
| @@ -842,4 +844,12 @@ class CmBroker | @@ -842,4 +844,12 @@ class CmBroker | ||
| 842 | { | 844 | { |
| 843 | $this->exBroker->subDepth($symbol, $onData); | 845 | $this->exBroker->subDepth($symbol, $onData); |
| 844 | } | 846 | } |
| 847 | + public function getIndexTickers() | ||
| 848 | + { | ||
| 849 | + $res = $this->exBroker->getIndexTickers(); | ||
| 850 | + if ($res && $res['code'] == '0') { | ||
| 851 | + return IndexTicker::transferOkxData($res['data']); | ||
| 852 | + } | ||
| 853 | + return []; | ||
| 854 | + } | ||
| 845 | } | 855 | } |
| @@ -62,6 +62,14 @@ class Api | @@ -62,6 +62,14 @@ class Api | ||
| 62 | return $this->request($path, $method, $param); | 62 | return $this->request($path, $method, $param); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | + //获取指数行情 | ||
| 66 | + public function indexTickers($param) | ||
| 67 | + { | ||
| 68 | + $path = '/api/v5/market/index-tickers'; | ||
| 69 | + $method = 'GET'; | ||
| 70 | + return $this->request($path, $method, $param); | ||
| 71 | + } | ||
| 72 | + | ||
| 65 | //-----------private interface ------------ | 73 | //-----------private interface ------------ |
| 66 | // 查询杠杆 | 74 | // 查询杠杆 |
| 67 | public function leverageInfo($param) | 75 | public function leverageInfo($param) |
| @@ -421,4 +421,12 @@ class ExBroker | @@ -421,4 +421,12 @@ class ExBroker | ||
| 421 | ]; | 421 | ]; |
| 422 | return $this->api->getOrderPending($param); | 422 | return $this->api->getOrderPending($param); |
| 423 | } | 423 | } |
| 424 | + public function getIndexTickers() | ||
| 425 | + { | ||
| 426 | + $param = [ | ||
| 427 | + 'quoteCcy' => 'USDT', | ||
| 428 | + ]; | ||
| 429 | + $res = $this->api->indexTickers($param); | ||
| 430 | + return $res; | ||
| 431 | + } | ||
| 424 | } | 432 | } |
trader/struct/IndexTicker.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace trader\struct; | ||
| 4 | + | ||
| 5 | +class IndexTicker | ||
| 6 | +{ | ||
| 7 | + public string $symbol = ""; | ||
| 8 | + public float $price = 0.0; | ||
| 9 | + public float $high24 = 0.0; | ||
| 10 | + public float $low24 = 0.0; | ||
| 11 | + public float $open24 = 0.0; | ||
| 12 | + | ||
| 13 | + public function __construct($symbol, $price, $high24, $low24, $open24) | ||
| 14 | + { | ||
| 15 | + $this->symbol = $symbol; | ||
| 16 | + $this->price = $price; | ||
| 17 | + $this->high24 = $high24; | ||
| 18 | + $this->low24 = $low24; | ||
| 19 | + $this->open24 = $open24; | ||
| 20 | + } | ||
| 21 | + public function toArray() | ||
| 22 | + { | ||
| 23 | + return [ | ||
| 24 | + 'symbol' => $this->symbol, | ||
| 25 | + 'price' => $this->price, | ||
| 26 | + 'high24' => $this->high24, | ||
| 27 | + 'low24' => $this->low24, | ||
| 28 | + 'open24' => $this->open24, | ||
| 29 | + ]; | ||
| 30 | + } | ||
| 31 | + public static function transferOkxData($data): array | ||
| 32 | + { | ||
| 33 | + $res = []; | ||
| 34 | + foreach ($data as $item) { | ||
| 35 | + $symbol = str_replace('-', '', $item['instId']); | ||
| 36 | + $res[] = new IndexTicker($symbol, $item['idxPx'], $item['high24h'], $item['low24h'], $item['open24h']); | ||
| 37 | + } | ||
| 38 | + return $res; | ||
| 39 | + } | ||
| 40 | +} |
-
请 注册 或 登录 后发表评论