Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_tinkoff_invest_robot-main/src/algotrading/get_candles.py
7815 views
1
import time
2
from datetime import timedelta
3
4
from tinkoff.invest import (
5
CandleInstrument,
6
MarketDataRequest,
7
SubscribeCandlesRequest,
8
SubscriptionAction,
9
SubscriptionInterval,
10
CandleInterval,
11
)
12
13
from tinkoff.invest.utils import now
14
15
from src.algotrading import glossary
16
17
18
def get_all_candles(client, figi, periud_day, timeframe):
19
candles = client.get_all_candles(
20
figi=figi,
21
from_=now() - timedelta(days=periud_day),
22
interval=timeframe,
23
)
24
25
return candles
26
27
28
def request_iterator(figi, timeframe):
29
print(timeframe)
30
if timeframe == 1:
31
interval = SubscriptionInterval.SUBSCRIPTION_INTERVAL_ONE_MINUTE
32
else:
33
interval = SubscriptionInterval.SUBSCRIPTION_INTERVAL_FIVE_MINUTES
34
35
yield MarketDataRequest(
36
subscribe_candles_request=SubscribeCandlesRequest(
37
subscription_action=SubscriptionAction.SUBSCRIPTION_ACTION_SUBSCRIBE,
38
instruments=[
39
CandleInstrument(
40
figi=figi,
41
interval=interval,
42
)
43
],
44
)
45
)
46
while True:
47
time.sleep(10)
48
49