-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsandboxConfig.ts
More file actions
55 lines (43 loc) · 1.51 KB
/
sandboxConfig.ts
File metadata and controls
55 lines (43 loc) · 1.51 KB
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
// https://articles.opexflow.com/trading-training/kak-poluchit-SANDBOXtoken-dlya-tinkoff-investicii.htm
// Для игнорирования файла в git (чтобы случайно не закоммитить):
import { MoneyValue } from 'tinkoff-sdk-grpc-js/dist/generated/common';
import { logger } from './src/utils';
import { createSdk } from 'tinkoff-sdk-grpc-js';
import { Accounts } from './bots/sandboxer/accounts';
// git update-index --assume-unchanged config.ts
const SANDBOXTOKEN = '';
if (!SANDBOXTOKEN) {
throw 'Заполните токен в файле config.ts';
}
const sdk = createSdk(SANDBOXTOKEN, 'sandboxer', logger, {
isSandbox: true,
});
// Сумма пополнения демо счёта.
const payInAmount: MoneyValue = {
units: 100000,
nano: 0,
currency: '',
};
const account = new Accounts(sdk);
const getSandboxAccoutId = async (resetAccount?: boolean) => {
const list = await account.list();
const accountId = list?.accounts?.[0]?.id;
if (!accountId || resetAccount) {
await account.resetAllAccounts();
await account.payIn({
amount: payInAmount,
accountId,
});
}
console.log('Подключён sandbox счёт.'); // eslint-disable-line no-console
console.log((await account.getPortfolio({ // eslint-disable-line no-console
accountId,
})).totalAmountPortfolio);
return accountId;
};
const SANDBOXSDK = sdk;
export {
SANDBOXSDK,
SANDBOXTOKEN,
getSandboxAccoutId,
};