From aca3483f82a902d0665e130d88c6c853e8698063 Mon Sep 17 00:00:00 2001 From: komarov Date: Mon, 20 Apr 2020 02:36:31 +0300 Subject: [PATCH] [WIP] kuna --- project/composer.json | 3 + project/composer.lock | 311 +++++++++++++++++- project/config/packages/nyholm_psr7.yaml | 21 ++ project/src/Exchanges/ExchangeInterface.php | 16 + .../src/Exchanges/Kuna/KunaApiExecutor.php | 47 +++ project/src/Exchanges/Kuna/KunaExchange.php | 40 +++ project/src/Exchanges/Kuna/KunaMarket.php | 51 +++ project/src/Exchanges/Kuna/KunaSigner.php | 30 ++ project/src/Exchanges/MarketInterface.php | 16 + project/src/Utils/Money/Currency.php | 22 ++ project/src/Utils/Money/CurrencyPair.php | 30 ++ project/src/Utils/Money/Money.php | 39 +++ project/src/Utils/Order/Book/OrderBook.php | 36 ++ project/symfony.lock | 27 ++ 14 files changed, 688 insertions(+), 1 deletion(-) create mode 100644 project/config/packages/nyholm_psr7.yaml create mode 100644 project/src/Exchanges/ExchangeInterface.php create mode 100644 project/src/Exchanges/Kuna/KunaApiExecutor.php create mode 100644 project/src/Exchanges/Kuna/KunaExchange.php create mode 100644 project/src/Exchanges/Kuna/KunaMarket.php create mode 100644 project/src/Exchanges/Kuna/KunaSigner.php create mode 100644 project/src/Exchanges/MarketInterface.php create mode 100644 project/src/Utils/Money/Currency.php create mode 100644 project/src/Utils/Money/CurrencyPair.php create mode 100644 project/src/Utils/Money/Money.php create mode 100644 project/src/Utils/Order/Book/OrderBook.php diff --git a/project/composer.json b/project/composer.json index 84cf62a..1cc27ae 100644 --- a/project/composer.json +++ b/project/composer.json @@ -5,6 +5,9 @@ "php": "^7.2.5", "ext-ctype": "*", "ext-iconv": "*", + "myclabs/php-enum": "^1.7", + "nyholm/psr7": "^1.2", + "psr/http-client": "^1.0", "symfony/console": "5.0.*", "symfony/dotenv": "5.0.*", "symfony/flex": "^1.3.1", diff --git a/project/composer.lock b/project/composer.lock index 589e4f6..d19fd05 100644 --- a/project/composer.lock +++ b/project/composer.lock @@ -4,8 +4,166 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7f769bc9dabc952a9e9210886c4900c8", + "content-hash": "ed2d4bb6d2a2abe584b5f0867281d0ab", "packages": [ + { + "name": "myclabs/php-enum", + "version": "1.7.6", + "source": { + "type": "git", + "url": "https://github.com/myclabs/php-enum.git", + "reference": "5f36467c7a87e20fbdc51e524fd8f9d1de80187c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/php-enum/zipball/5f36467c7a87e20fbdc51e524fd8f9d1de80187c", + "reference": "5f36467c7a87e20fbdc51e524fd8f9d1de80187c", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7", + "squizlabs/php_codesniffer": "1.*", + "vimeo/psalm": "^3.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "MyCLabs\\Enum\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP Enum contributors", + "homepage": "https://github.com/myclabs/php-enum/graphs/contributors" + } + ], + "description": "PHP Enum implementation", + "homepage": "http://github.com/myclabs/php-enum", + "keywords": [ + "enum" + ], + "time": "2020-02-14T08:15:52+00:00" + }, + { + "name": "nyholm/psr7", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/Nyholm/psr7.git", + "reference": "55ff6b76573f5b242554c9775792bd59fb52e11c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Nyholm/psr7/zipball/55ff6b76573f5b242554c9775792bd59fb52e11c", + "reference": "55ff6b76573f5b242554c9775792bd59fb52e11c", + "shasum": "" + }, + "require": { + "php": "^7.1", + "php-http/message-factory": "^1.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "http-interop/http-factory-tests": "dev-master", + "php-http/psr7-integration-tests": "dev-master", + "phpunit/phpunit": "^7.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Nyholm\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com" + }, + { + "name": "Martijn van der Ven", + "email": "martijn@vanderven.se" + } + ], + "description": "A fast PHP7 implementation of PSR-7", + "homepage": "http://tnyholm.se", + "keywords": [ + "psr-17", + "psr-7" + ], + "time": "2019-09-05T13:24:16+00:00" + }, + { + "name": "php-http/message-factory", + "version": "v1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-http/message-factory.git", + "reference": "a478cb11f66a6ac48d8954216cfed9aa06a501a1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/message-factory/zipball/a478cb11f66a6ac48d8954216cfed9aa06a501a1", + "reference": "a478cb11f66a6ac48d8954216cfed9aa06a501a1", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com" + } + ], + "description": "Factory interfaces for PSR-7 HTTP Message", + "homepage": "http://php-http.org", + "keywords": [ + "factory", + "http", + "message", + "stream", + "uri" + ], + "time": "2015-12-19T14:08:53+00:00" + }, { "name": "psr/cache", "version": "1.0.1", @@ -147,6 +305,157 @@ ], "time": "2019-01-08T18:20:26+00:00" }, + { + "name": "psr/http-client", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "496a823ef742b632934724bf769560c2a5c7c44e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/496a823ef742b632934724bf769560c2a5c7c44e", + "reference": "496a823ef742b632934724bf769560c2a5c7c44e", + "shasum": "" + }, + "require": { + "php": "^7.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "time": "2018-10-30T23:29:13+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "time": "2019-04-30T12:38:16+00:00" + }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06T14:39:51+00:00" + }, { "name": "psr/log", "version": "1.1.3", diff --git a/project/config/packages/nyholm_psr7.yaml b/project/config/packages/nyholm_psr7.yaml new file mode 100644 index 0000000..f135723 --- /dev/null +++ b/project/config/packages/nyholm_psr7.yaml @@ -0,0 +1,21 @@ +services: + # Register nyholm/psr7 services for autowiring with PSR-17 (HTTP factories) + Psr\Http\Message\RequestFactoryInterface: '@nyholm.psr7.psr17_factory' + Psr\Http\Message\ResponseFactoryInterface: '@nyholm.psr7.psr17_factory' + Psr\Http\Message\ServerRequestFactoryInterface: '@nyholm.psr7.psr17_factory' + Psr\Http\Message\StreamFactoryInterface: '@nyholm.psr7.psr17_factory' + Psr\Http\Message\UploadedFileFactoryInterface: '@nyholm.psr7.psr17_factory' + Psr\Http\Message\UriFactoryInterface: '@nyholm.psr7.psr17_factory' + + # Register nyholm/psr7 services for autowiring with HTTPlug factories + Http\Message\MessageFactory: '@nyholm.psr7.httplug_factory' + Http\Message\RequestFactory: '@nyholm.psr7.httplug_factory' + Http\Message\ResponseFactory: '@nyholm.psr7.httplug_factory' + Http\Message\StreamFactory: '@nyholm.psr7.httplug_factory' + Http\Message\UriFactory: '@nyholm.psr7.httplug_factory' + + nyholm.psr7.psr17_factory: + class: Nyholm\Psr7\Factory\Psr17Factory + + nyholm.psr7.httplug_factory: + class: Nyholm\Psr7\Factory\HttplugFactory diff --git a/project/src/Exchanges/ExchangeInterface.php b/project/src/Exchanges/ExchangeInterface.php new file mode 100644 index 0000000..95fcc69 --- /dev/null +++ b/project/src/Exchanges/ExchangeInterface.php @@ -0,0 +1,16 @@ +client = $client; + $this->signer = $signer; + } + + public function getMarkets(): array + { + $response = $this + ->client + ->sendRequest( + new Request( + 'GET', + self::API_BASE_URL . '/v3/markets' + ) + ); + + return json_decode($response->getBody(), true); + } +} \ No newline at end of file diff --git a/project/src/Exchanges/Kuna/KunaExchange.php b/project/src/Exchanges/Kuna/KunaExchange.php new file mode 100644 index 0000000..4219c23 --- /dev/null +++ b/project/src/Exchanges/Kuna/KunaExchange.php @@ -0,0 +1,40 @@ +apiExecutor = $apiExecutor; + } + + /** + * @inheritDoc + */ + public function getMarkets(): array + { + $data = $this->apiExecutor->getMarkets(); + + $markets = []; + foreach ($data as $marketData) { + $markets[] = KunaMarket::createFromApiData($marketData, $this->apiExecutor); + } + + return $markets; + } +} \ No newline at end of file diff --git a/project/src/Exchanges/Kuna/KunaMarket.php b/project/src/Exchanges/Kuna/KunaMarket.php new file mode 100644 index 0000000..17d3dad --- /dev/null +++ b/project/src/Exchanges/Kuna/KunaMarket.php @@ -0,0 +1,51 @@ +apiExecutor = $apiExecutor; + $this->currencyPair = $currencyPair; + $this->id = $id; + } + + public function getPair(): CurrencyPair + { + return $this->currencyPair; + } +} \ No newline at end of file diff --git a/project/src/Exchanges/Kuna/KunaSigner.php b/project/src/Exchanges/Kuna/KunaSigner.php new file mode 100644 index 0000000..8994f8a --- /dev/null +++ b/project/src/Exchanges/Kuna/KunaSigner.php @@ -0,0 +1,30 @@ +publicKey = $publicKey; + $this->privateKey = $privateKey; + } + + public function signRequest(RequestInterface $request): void + { + + } +} \ No newline at end of file diff --git a/project/src/Exchanges/MarketInterface.php b/project/src/Exchanges/MarketInterface.php new file mode 100644 index 0000000..3912b1c --- /dev/null +++ b/project/src/Exchanges/MarketInterface.php @@ -0,0 +1,16 @@ +code = $code; + $this->precision = $precision; + } +} \ No newline at end of file diff --git a/project/src/Utils/Money/CurrencyPair.php b/project/src/Utils/Money/CurrencyPair.php new file mode 100644 index 0000000..ca4ea34 --- /dev/null +++ b/project/src/Utils/Money/CurrencyPair.php @@ -0,0 +1,30 @@ +base = $base; + $this->quote = $quote; + } + + public function getBase(): Currency + { + return $this->base; + } + + public function getQuote(): Currency + { + return $this->quote; + } +} \ No newline at end of file diff --git a/project/src/Utils/Money/Money.php b/project/src/Utils/Money/Money.php new file mode 100644 index 0000000..9d86da2 --- /dev/null +++ b/project/src/Utils/Money/Money.php @@ -0,0 +1,39 @@ +amount = $amount; + $this->currency = $currency; + } + + /** + * @return Currency + */ + public function getCurrency(): Currency + { + return $this->currency; + } + + /** + * @return string + */ + public function getAmount(): string + { + return $this->amount; + } +} \ No newline at end of file diff --git a/project/src/Utils/Order/Book/OrderBook.php b/project/src/Utils/Order/Book/OrderBook.php new file mode 100644 index 0000000..14132e8 --- /dev/null +++ b/project/src/Utils/Order/Book/OrderBook.php @@ -0,0 +1,36 @@ +bids = $bids; + $this->asks = $asks; + } +} \ No newline at end of file diff --git a/project/symfony.lock b/project/symfony.lock index 012c29b..2768b9d 100644 --- a/project/symfony.lock +++ b/project/symfony.lock @@ -1,7 +1,25 @@ { + "myclabs/php-enum": { + "version": "1.7.6" + }, + "nyholm/psr7": { + "version": "1.0", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "1.0", + "ref": "7c0a9352a57376f04f5444e74565102c3a23d0c7" + }, + "files": [ + "config/packages/nyholm_psr7.yaml" + ] + }, "php": { "version": "7.4" }, + "php-http/message-factory": { + "version": "v1.0.2" + }, "psr/cache": { "version": "1.0.1" }, @@ -11,6 +29,15 @@ "psr/event-dispatcher": { "version": "1.0.0" }, + "psr/http-client": { + "version": "1.0.0" + }, + "psr/http-factory": { + "version": "1.0.1" + }, + "psr/http-message": { + "version": "1.0.1" + }, "psr/log": { "version": "1.1.3" },