-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinkoff-invest-simple.gs
34 lines (32 loc) · 1.09 KB
/
tinkoff-invest-simple.gs
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
function MarketPrice(ticker) {
var res = UrlFetchApp.fetch("https://api.tinkoff.ru/trading/stocks/get", {
method: "post",
contentType: "application/json",
payload: JSON.stringify({ "ticker": ticker })
});
var json = JSON.parse(res.getContentText());
return [[json.payload.price.value, json.payload.price.currency]];
}
function Portfolio(apiKey, brokerAccountId) {
var res = UrlFetchApp.fetch("https://api-invest.tinkoff.ru/openapi/portfolio" + (brokerAccountId ? "?brokerAccountId=" + brokerAccountId : "") , {
method: "get",
contentType: "application/json",
headers: { Authorization: "Bearer " + apiKey }
});
var json = JSON.parse(res.getContentText());
var result = [];
json.payload.positions.forEach(function (position) {
result.push(
[
position.instrumentType,
position.ticker,
position.balance,
position.averagePositionPrice.currency,
position.averagePositionPrice.value,
position.averagePositionPrice.value * position.balance,
position.expectedYield.value
]
);
});
return result;
}