Skip to content

Commit 402124e

Browse files
author
whitebit-robot
committed
feat: initial release
1 parent 7ec5699 commit 402124e

File tree

150 files changed

+10549
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+10549
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea
2+
vendor
3+
4+
# codegen files
5+
postman.json
6+
build

.gitlab-ci.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
stages:
2+
- build
3+
- test
4+
- security
5+
- deploy
6+
7+
include:
8+
- local: .gitlab/jobs/*.yml

.gitlab/jobs/build.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
build image:
2+
image: docker:dind
3+
stage: build
4+
variables:
5+
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
6+
DOCKER_BUILDKIT: 1
7+
cache:
8+
key:
9+
files:
10+
- Dockerfile
11+
script:
12+
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
13+
- docker build -t $IMAGE_TAG . --push
14+
15+
16+
build vendors:
17+
stage: build
18+
dependencies:
19+
- build image
20+
artifacts:
21+
paths:
22+
- vendor/
23+
cache:
24+
key:
25+
files:
26+
- composer.lock
27+
policy: pull-push
28+
image: composer:2
29+
script:
30+
- composer install --no-interaction --prefer-dist --optimize-autoloader

.gitlab/jobs/deploy.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
push to public:
2+
stage: build
3+
image: bitnami/git
4+
when: manual
5+
only:
6+
- tags
7+
before_script:
8+
- git fetch --unshallow
9+
- git config --global user.email "[email protected]"
10+
- git config --global user.name "whitebit-robot"
11+
- rm -rf .gitlab* Dockerfile docker-compose.yaml
12+
- git add .
13+
- git commit --amend --no-edit
14+
- git remote set-url origin $GITHUB_REPO
15+
- git filter-branch -f --env-filter "
16+
GIT_AUTHOR_NAME='whitebit-robot'
17+
GIT_AUTHOR_EMAIL='[email protected]'
18+
GIT_COMMITTER_NAME='whitebit-robot'
19+
GIT_COMMITTER_EMAIL='[email protected]'
20+
" HEAD
21+
script:
22+
- git push --tags -f origin 'HEAD:main'

.gitlab/jobs/security.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
.container_scanning:
2+
stage: security
3+
image:
4+
name: docker.io/aquasec/trivy:latest
5+
entrypoint: [ "" ]
6+
variables:
7+
GIT_STRATEGY: none
8+
TRIVY_USERNAME: "$CI_REGISTRY_USER"
9+
TRIVY_PASSWORD: "$CI_REGISTRY_PASSWORD"
10+
TRIVY_AUTH_URL: "$CI_REGISTRY"
11+
FULL_IMAGE_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
12+
script:
13+
- trivy --version
14+
# cache cleanup is needed when scanning images with the same tags, it does not remove the database
15+
- time trivy image --clear-cache
16+
# update vulnerabilities db
17+
- time trivy image --download-db-only --no-progress --cache-dir .trivycache/
18+
# Builds report and puts it in the default workdir $CI_PROJECT_DIR, so `artifacts:` can take it from there
19+
- time trivy image --exit-code 0 --cache-dir .trivycache/ --no-progress --format template --template "@/contrib/gitlab.tpl"
20+
--output "$CI_PROJECT_DIR/gl-container-scanning-report.json" "$FULL_IMAGE_NAME"
21+
# Prints full report
22+
- time trivy image --exit-code 0 --cache-dir .trivycache/ --no-progress "$FULL_IMAGE_NAME"
23+
# Fail on critical vulnerabilities
24+
- time trivy image --exit-code 1 --cache-dir .trivycache/ --severity CRITICAL --no-progress "$FULL_IMAGE_NAME"
25+
cache:
26+
paths:
27+
- .trivycache/
28+
artifacts:
29+
when: always
30+
reports:
31+
container_scanning: gl-container-scanning-report.json
32+
33+
package scan:
34+
stage: security
35+
needs:
36+
- build vendors
37+
dependencies:
38+
- build vendors
39+
image:
40+
name: docker.io/aquasec/trivy:latest
41+
entrypoint: [ "" ]
42+
variables:
43+
GIT_STRATEGY: none
44+
script:
45+
- trivy --version
46+
# update vulnerabilities db
47+
- time trivy fs --download-db-only --no-progress --cache-dir .trivycache/
48+
# Builds report and puts it in the default workdir $CI_PROJECT_DIR, so `artifacts:` can take it from there
49+
- time trivy fs --exit-code 0 --cache-dir .trivycache/ --no-progress --format template --template "@/contrib/gitlab.tpl"
50+
--output "$CI_PROJECT_DIR/gl-container-scanning-report.json" .
51+
# Prints full report
52+
- time trivy fs --exit-code 0 --cache-dir .trivycache/ --no-progress .
53+
# Fail on critical vulnerabilities
54+
- time trivy fs --exit-code 1 --cache-dir .trivycache/ --severity CRITICAL --no-progress .
55+
cache:
56+
paths:
57+
- .trivycache/
58+
artifacts:
59+
when: always
60+
reports:
61+
container_scanning: gl-container-scanning-report.json
62+
63+
image scan:
64+
extends: .container_scanning
65+
needs:
66+
- build image

.gitlab/jobs/test.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
tests:
2+
stage: test
3+
needs:
4+
- build image
5+
- build vendors
6+
artifacts:
7+
when: always
8+
reports:
9+
junit: phpunit-report.xml
10+
coverage_report:
11+
coverage_format: cobertura
12+
path: phpunit-coverage.xml
13+
cache:
14+
key:
15+
files:
16+
- composer.lock
17+
policy: pull
18+
image: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
19+
script:
20+
- ./vendor/bin/pest --coverage --log-junit phpunit-report.xml --coverage-cobertura phpunit-coverage.xml
21+
22+
pint:
23+
stage: test
24+
needs:
25+
- build image
26+
- build vendors
27+
cache:
28+
key:
29+
files:
30+
- composer.lock
31+
policy: pull
32+
image: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
33+
script:
34+
- ./vendor/bin/pint --test
35+
36+
phpstan:
37+
stage: test
38+
needs:
39+
- build image
40+
- build vendors
41+
cache:
42+
key:
43+
files:
44+
- composer.lock
45+
policy: pull
46+
image: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
47+
script:
48+
- ./vendor/bin/phpstan analyse ./src
49+
50+
rector:
51+
stage: test
52+
needs:
53+
- build image
54+
- build vendors
55+
cache:
56+
key:
57+
files:
58+
- composer.lock
59+
policy: pull
60+
image: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
61+
script:
62+
- ./vendor/bin/rector --dry-run

Dockerfile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Set the base image for subsequent instructions
2+
FROM php:8.2-cli
3+
4+
RUN apt-get update
5+
6+
RUN apt-get install -qq \
7+
git \
8+
curl \
9+
libmcrypt-dev \
10+
libjpeg-dev \
11+
libpng-dev \
12+
libfreetype6-dev \
13+
libbz2-dev \
14+
libzip-dev \
15+
zip
16+
17+
RUN apt-get clean
18+
19+
RUN pecl install pcov && \
20+
docker-php-ext-enable pcov
21+
22+
RUN docker-php-ext-install zip
23+
24+
RUN curl --silent --show-error "https://getcomposer.org/installer" | php -- --install-dir=/usr/local/bin --filename=composer
25+
26+
WORKDIR /app

README.md

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# WhiteBIT PHP SDK
2+
3+
[![Latest Version](https://img.shields.io/packagist/v/whitebit/php.svg)](https://packagist.org/packages/your-vendor/your-sdk)
4+
[![License](https://img.shields.io/github/license/whitebit/php.svg)](LICENSE)
5+
6+
Official PHP SDK for the [WhiteBIT](https://whitebit.com/) API. ([WhiteBIT API Documentation](docs.whitebit.com))
7+
8+
## Requirements
9+
* `PHP 8.2` or higher
10+
11+
## Installation
12+
13+
You can install this SDK via [Composer](https://getcomposer.org/):
14+
15+
```bash
16+
composer require whitebit/php
17+
```
18+
19+
## Usage
20+
21+
### Plain PHP with autoload
22+
```php
23+
<?php
24+
25+
use WhiteBIT\Sdk\Connectors\WhiteBITConnector;
26+
use WhiteBIT\Sdk\Connectors\ConnectorConfig;
27+
use WhiteBIT\Sdk\Requests\General\V1\KlineRequest;
28+
29+
$connector = new WhiteBITConnector(
30+
new ConnectorConfig('api_key', 'api_secret')
31+
);
32+
33+
$connector->send(new KlineRequest('BTC_USDT'))
34+
```
35+
36+
### Laravel
37+
Package automatically injects `WhiteBITServiceProvider.php` into your app.
38+
39+
#### Publish config
40+
```shell
41+
php artisan vendor:publish --provider="WhiteBIT\Sdk\WhiteBITServiceProvider"
42+
```
43+
44+
### Environment variables
45+
```dotenv
46+
WHITEBIT_PUBLIC_KEY=
47+
WHITEBIT_SECRET_KEY=
48+
```
49+
50+
#### Usage
51+
```php
52+
namespace App\Http\Controllers;
53+
54+
use Illuminate\View\View;
55+
use WhiteBIT\Sdk\Connectors\WhiteBITConnector;
56+
use WhiteBIT\Sdk\Requests\General\V1\KlineRequest;
57+
58+
class ExampleController extends Controller
59+
{
60+
61+
public function show(WhiteBITConnector $connector): View
62+
{
63+
$response = $connector->send(new KlineRequest('BTC_USDT'));
64+
65+
return response()->json(
66+
$response->json()
67+
);
68+
}
69+
}
70+
```
71+
72+
#### Notes
73+
`WhiteBITServiceProvider` registers `WhiteBITConnector` as singleton, use it with care in runtimes like `openswoole`, `roadrunner` etc.
74+
75+
## Available requests
76+
77+
```
78+
Requests
79+
├── General
80+
│   ├── AssetsRequest.php
81+
│   ├── CollateralMarketsRequest.php
82+
│   ├── FeeRequest.php
83+
│   ├── FutureMarketsRequest.php
84+
│   ├── HealthRequest.php
85+
│   ├── MarketActivityRequest.php
86+
│   ├── MarketsRequest.php
87+
│   ├── OrderBookRequest.php
88+
│   ├── TimeRequest.php
89+
│   ├── TradesRequest.php
90+
│   └── V1
91+
│   ├── KlineRequest.php
92+
│   ├── MarketActivityRequest.php
93+
│   ├── SingleMarketActivityRequest.php
94+
│   └── TradeHistoryRequest.php
95+
└── Private
96+
├── AddressRequest.php
97+
├── Codes
98+
│   ├── ApplyCodeRequest.php
99+
│   ├── CodesHistoryRequest.php
100+
│   ├── CreateCodeRequest.php
101+
│   └── MyCodesRequest.php
102+
├── Main
103+
│   ├── CreateNewAddressRequest.php
104+
│   ├── CreateWithdrawPayRequest.php
105+
│   ├── CreateWithdrawRequest.php
106+
│   ├── FiatDepositUrlRequest.php
107+
│   ├── HistoryRequest.php
108+
│   └── TransferBetweenBalancesRequest.php
109+
├── MainBalanceRequest.php
110+
└── Trade
111+
├── Spot
112+
│   ├── DealsHistoryRequest.php
113+
│   ├── OrderDealsRequest.php
114+
│   ├── OrderHistoryRequest.php
115+
│   ├── Orders
116+
│   │   ├── CancelOrderRequest.php
117+
│   │   ├── CreateBulkLimitOrderRequest.php
118+
│   │   ├── CreateLimitOrderRequest.php
119+
│   │   ├── CreateMarketOrderRequest.php
120+
│   │   ├── CreateStockMarketOrderRequest.php
121+
│   │   ├── CreateStopLimitOrderRequest.php
122+
│   │   └── CreateStopMarketOrderRequest.php
123+
│   └── UnexecutedOrdersRequest.php
124+
├── StatusKillSwitchRequest.php
125+
├── SyncKillSwitchRequest.php
126+
└── TradeBalanceRequest.php
127+
```

0 commit comments

Comments
 (0)