-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
69 lines (61 loc) · 2.42 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
use Oliver\{Application,Logger};
use Oliver\Reply\{Stocks,Orders,MarketOrderBuyStock,MarketOrderSellStock,Ping,ICanDo,Introduction,Repeat};
use jamesRUS52\TinkoffInvest\{TIClient,TISiteEnum,TIException};
use Symfony\Component\DependencyInjection\{ContainerBuilder,Reference};
function main($event, $context): array
{
require 'vendor/autoload.php'; // follow PSR-1
// https://cloud.yandex.ru/docs/functions/lang/php/context
$cloudRequestId = $context->getRequestId(); // @todo: error handling
$token = $_ENV['TINKOFF_OPEN_API_EXCHANGE'] ?? ''; // @todo: $_SERVER
$containerBuilder = new ContainerBuilder();
$containerBuilder->setParameter('yandex.cloud.request.id', $cloudRequestId);
$containerBuilder->setParameter('tinkoff.invest.token', $token);
$containerBuilder->setParameter('tinkoff.invest.site', TISiteEnum::EXCHANGE);
$containerBuilder
->register(Logger::class, Logger::class)
->addArgument('%yandex.cloud.request.id%')
;
$containerBuilder
->register(TIClient::class, TIClient::class)
->addArgument('%tinkoff.invest.token%')
->addArgument('%tinkoff.invest.site%')
;
$containerBuilder
->register(Application::class, Application::class)
->addMethodCall('setLogger', [new Reference(Logger::class)])
;
$containerBuilder
->register(Stocks::class, Stocks::class)
->addArgument(new Reference(TIClient::class))
;
$containerBuilder
->register(Orders::class, Orders::class)
->addArgument(new Reference(TIClient::class))
;
$containerBuilder
->register(MarketOrderBuyStock::class, MarketOrderBuyStock::class)
->addArgument(new Reference(TIClient::class))
->addArgument(new Reference(Logger::class))
;
$containerBuilder
->register(MarketOrderSellStock::class, MarketOrderSellStock::class)
->addArgument(new Reference(TIClient::class))
->addArgument(new Reference(Logger::class))
;
$app = $containerBuilder->get(Application::class);
$app->add(
new Ping(),
new ICanDo(),
new Introduction(),
new Repeat(),
$containerBuilder->get(Stocks::class),
$containerBuilder->get(Orders::class),
$containerBuilder->get(MarketOrderBuyStock::class),
$containerBuilder->get(MarketOrderSellStock::class),
);
$app->setEvent($event);
return $app->run();
}