Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
slvler committed Mar 4, 2023
0 parents commit 8b374fc
Show file tree
Hide file tree
Showing 22 changed files with 791 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
vendor
composer.lock
build
phpunit.xml
.phpunit.result.cache
.idea
.php_cs
.php-cs-fixer.cache
coverage
docs
psalm.xml
Empty file added CHANGELOG.md
Empty file.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2023 slvler <slvler@proton.me>

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.
174 changes: 174 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# PHP API client for btcturk.com

[![tests](https://github.com/slvler/Imdb-service/actions/workflows/tests.yml/badge.svg)](https://github.com/slvler/Imdb-service/actions/workflows/tests.yml)
[![Latest Stable Version](http://poser.pugx.org/slvler/imdb-service/v)](https://packagist.org/packages/slvler/imdb-service)
[![License](http://poser.pugx.org/slvler/imdb-service/license)](https://packagist.org/packages/slvler/imdb-service)


![image info](./btcturk-logo.png)

A simple API client, written with PHP for [btcturk.com](https://btckturk.com).

BtcTurk is a cryptocurrency exchange operating in Turkey. Offers crypto trading service. There are various crypto services available.

For additional information about API visit [https://docs.btcturk.com/](https://docs.btcturk.com/)

BtcTurk API [Terms of Service](https://pro.btcturk.com/en/legal-information/terms-of-use)

## Requirements

* PHP >= 7.2
* ext-json


## Installation

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```bash
$ composer require slvler/btckturk-api
```
or add

```json
"slvler/btckturk-api": "^1.0"
```


## Basic usage


### Example
```php
use slvler\BtcTurkApi\BtcTurkClient;

$client = new BtcTurkClient();
```

## Available methods

### Exchange

#### [exchange-info](https://docs.btcturk.com/public-endpoints/exchange-info)

You can use exchangeinfo endpoint for all tradable pairs and their quantity or price scales.

```php
$data = $client->exchange()->getList();
```


### Tickers

#### [Pair](https://docs.btcturk.com/public-endpoints/ticker#pair)

Using the pairSymbol parameter, you can send a request for a single pair.

```php
$data = $client->ticker()->getPair('BTCUSDT');
```

#### [currency](https://docs.btcturk.com/public-endpoints/ticker#currency)

currency parameter can be used for all symbol pairs.

```php
$data = $client->ticker()->getCurrency('usdt');
```

### OrderBook

#### [orderbook](https://docs.btcturk.com/public-endpoints/orderbook)

Get a list of all open orders for a product.

```php
$data = $client->orderBook()->getOrderBook('BTCUSDT', ['limit' => 10]);
```


### Trades

#### [trades](https://docs.btcturk.com/public-endpoints/trades)

Gets a list the latest trades for a product.

```php
$data = $client->trades()->getTrades('BTCUSDT', ['last' => 10]);
```


### OHLC Data

#### [OHLC](https://docs.btcturk.com/public-endpoints/ohcl-data#ohlc-data)

open, high, low, close, volume, total and average information can be viewed with OHLC enpoint.

```php
$data = $client->ohlcs()->getOhlcs('BTCUSDT', ['from' => 1638316800, 'to' => 1639526400]);
```

### Account Balance

#### [Balance](https://docs.btcturk.com/private-endpoints/account-balance)

For more information you can check our Authentication V1 article. All asset information can be viewed with the Account Balance endpoint.

```php
$data = $client->balance()->getBalances();
```


### Transactions

#### [Transactions](https://docs.btcturk.com/private-endpoints/user-transactions)

For more information you can check our Authentication V1 article. 6 parameters can be used to access user transactions.

```php
$data = $client->transaction()->getTransaction(['type' => 'buy', 'symbol' => 'btc', 'symbol' => 'usdt']);
```

#### [Fiat Transactions](https://docs.btcturk.com/private-endpoints/get-fiat-transactions)

For more information you can check our Authentication V1 article. 4 parameters can be used to access user fiat transactions.
```php
$data = $client->transaction()->getFiatTransactions(['symbol' => 'try']);
```

#### [Crypto Transactions](https://docs.btcturk.com/private-endpoints/get-crypto-transactions)

For more information you can check our Authentication V1 article. 4 parameters can be used to access user fiat transactions.
```php
$data = $client->transaction()->getCryptoTransactions(['symbol' => ['btc','etc']]);
```


### Orders

#### [Open Orders](https://docs.btcturk.com/private-endpoints/open-orders)

List your current open orders. Only open or un-settled orders are returned by default. As soon as an order is no longer open and settled, it will no longer appear in the default request.

```php
$data = $client->orders()->getOpenOrders('BTCTRY');
```


#### [All Orders](https://docs.btcturk.com/private-endpoints/all-orders)

Retrieve all orders of any status.

```php
$data = $client->orders()->getAllOrders(['pairSymbol' => 'BTCTRY', 'limit' => "1", 'page' => '10']);
```

#### [Single Order](https://docs.btcturk.com/private-endpoints/get-single-order)

Get a single order by orderId. For all transactions related to the private endpoint, you must authorize before sending your request.

```php
$data = $client->orders()->getSingleOrder('61912740');
```
Binary file added btcturk-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "slvler/btcturk-api",
"type": "library",
"description": "PHP REST API client for btcturk.com",
"homepage": "https://github.com/slvler/btcturk-api",
"keywords": ["client", "api", "php", "btcturk.com", "rest"],
"license": "MIT",
"authors": [
{
"name": "slvler",
"email": "slvler@proton.me",
"role": "Developer"
}
],
"require": {
"php": "^7.2|^8.0",
"ext-json": "*",
"guzzlehttp/guzzle": "~6.0|^7.0.1",
"monolog/monolog": "2.1"
},
"require-dev": {
"phpunit/phpunit": "^8.0"
},
"autoload": {
"psr-4": {
"slvler\\BtcTurkApi\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"slvler\\BtcTurkApi\\Tests\\": "tests/"
}
},
"scripts": {
"test": "vendor/bin/phpunit tests"
},
"prefer-stable": true
}
12 changes: 12 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="BtcTurkClient">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
30 changes: 30 additions & 0 deletions src/Api/Api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);

namespace slvler\BtcTurkApi\Api;

use slvler\BtcTurkApi\BtcTurkClient;
use slvler\BtcTurkApi\Message\ResponseTransformer;
use Exception;

class Api
{

protected $client;

protected $transformer;

public function __construct(BtcTurkClient $client)
{
$this->client = $client;
}

public function get(string $uri, string $version, array $option = [])
{
$response = $this->client->getHttpClient()->request("GET", $version . $uri , $option);
$this->transformer = new ResponseTransformer($response);
return $this->transformer->toArray();
}


}
25 changes: 25 additions & 0 deletions src/Api/Balance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace slvler\BtcTurkApi\Api;

class Balance extends Api
{
use Setting;

public function getBalances(): array
{
$headers = [
"X-PCK" => Setting::$API_KEY,
"X-Stamp" => Setting::getNonce(),
"X-Signature" => Setting::getBase64(),
'Cache-Control' => 'no-cache',
'Content-Type' => 'application/json',
];

return $this->get('/users/balances','v1', [
'base_uri' => 'https://api.btcturk.com/api/',
'headers' => $headers
]);
}

}
13 changes: 13 additions & 0 deletions src/Api/Exchange.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace slvler\BtcTurkApi\Api;

class Exchange extends Api
{
public function getList(): array
{
return $this->get('server/exchangeinfo','v2/', ['base_uri' => 'https://api.btcturk.com/api/']);
}
}
16 changes: 16 additions & 0 deletions src/Api/Ohlcs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace slvler\BtcTurkApi\Api;

class Ohlcs extends Api
{
public function getOhlcs(string $pair, array $params = []): array
{
$params['pair'] = $pair;
return $this->get('/ohlcs','v1', ['base_uri' => 'https://graph-api.btcturk.com', 'query' => $params]);
}


}
17 changes: 17 additions & 0 deletions src/Api/OrderBook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);


namespace slvler\BtcTurkApi\Api;

class OrderBook extends Api
{
public function getOrderBook(string $pairSymbol, array $params = []): array
{
$params['pairSymbol'] = $pairSymbol;
return $this->get('/orderbook','v2/', ['base_uri' => 'https://api.btcturk.com/api/', 'query' => $params]);
}


}
Loading

0 comments on commit 8b374fc

Please sign in to comment.