我在poloniex.com上製作軟件時需要倒賣 爲此,我需要獲得有關訂單的新信息。 API DOCUMENTATION說關於推動api。 按照我的理解正確的是這樣工作的:如何通過push api(WAMP協議)實現最新的poloniex訂單
- 使用returnOrderBook(public方法API)用於獲取快照 從性反應
- 採取序列號(seq鍵)訂閱推送API與快照序列號
收集新數據並對快照數據進行更正。
<?php namespace Crypto\Scalper\Cli; use AppConfig; use Monolog\Logger; use Monolog\Handler\StreamHandler; use AndreasGlaser\PPC\PPC; use Thruway\ClientSession; use Thruway\Peer\Client; use Thruway\Transport\PawlTransportProvider; use Psr\Log\NullLogger; /** * Class PoloniexSyncCli * @package Crypto\Scalper\Cli */ class PoloniexSyncCli { private $log; private $orderbooks; /** * Constructor. */ public function __construct() { // Logging $this->log = new Logger('PoloniexSyncCli'); $this->log->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG)); } public function loop() { $this->log->info('Sync poloniex data'); while (true) { $this->getOrderbooks(); $this->subscribe(); sleep(10); } } /** * Get orderbook snapshot */ private function getOrderbooks() { $this->log->info('Getting order book snapshot (REST API)'); $poloniex = AppConfig::get('poloniex'); $ppc = new PPC($poloniex['apiKey'], $poloniex['secret']); $result = $ppc->getOrderBook('USDT_BTC', 50); if (array_key_exists('error', $result->decoded)) { $this->log->error("Error on REST API request: {$result->decoded['error']}"); exit; } $this->orderbooks = $result->decoded; $this->log->info("Seq: {$this->orderbooks['seq']}"); // THIS IS sequence number } /** * Subscribe to feed for getting fresh orderbook data */ private function subscribe() { $this->log->info('Subscribe to feed (WAMP)'); $client = new Client("realm1"); $client->addTransportProvider(new PawlTransportProvider("wss://api.poloniex.com")); $client->on('open', function (ClientSession $session) { $marketEvent = function ($args, $argsKw, $details, $publicationId) { echo "Orderbook update: seq: $argsKw->seq, args count: ".count($args)."\n"; }; /** * All problem here * As i understand right i need send seq number on subscribe * and start recive data from that number * But i recive data with another numbers -( */ $session->subscribe('USDT_BTC', $marketEvent, ['seq' => $this->orderbooks['seq']]); }); $client->on('close', function ($reason){ $this->log->info("Соединение с Web socket было закрыто со стороны сервера, причина: $reason"); }); $client->on('error', function ($errorUri){ $this->log->error("Произошла ошибка во время синхронизации по Web socket, причина: $errorUri"); exit; }); $client->start(); } }
這是腳本日誌:
./poloniex-sync.php
PoloniexSyncCli.INFO: Sync poloniex data
PoloniexSyncCli.INFO: Getting order book snapshot (REST API)
PoloniexSyncCli.INFO: Seq: 106470819
PoloniexSyncCli.INFO: Subscribe to feed (WAMP)
Orderbook update: seq: 106307669, args count: 2
Orderbook update: seq: 106307670, args count: 2
Orderbook update: seq: 106307671, args count: 1
Orderbook update: seq: 106307672, args count: 5
Orderbook update: seq: 106307673, args count: 2
Orderbook update: seq: 106307674, args count: 2
Orderbook update: seq: 106307675, args count: 1
Orderbook update: seq: 106307676, args count: 2
Orderbook update: seq: 106307677, args count: 1
Orderbook update: seq: 106307678, args count: 1
Orderbook update: seq: 106307679, args count: 2
Orderbook update: seq: 106307680, args count: 1
Orderbook update: seq: 106307681, args count: 2
Orderbook update: seq: 106307682, args count: 1
Orderbook update: seq: 106307683, args count: 1
Orderbook update: seq: 106307684, args count: 1
正如你可以看到在快照序列號是:106470819 但是序列號從推送API recived不與快照序列號相關:106307669 ,106307670,...
與WAMP一起使用我使用高速公路。我閱讀文檔和谷歌搜索,但無法找到解決方案。
P.S. ( PPS抱歉,我的醜陋英語。它不是我的本地人
可能有人有JS例子的情況下? 1.獲取快照(public api) 2.訂閱推送API(使用快照中的SEQ號碼) –