RAPTOR v18.4: Исправлена отчетность, активированы выходные
This commit is contained in:
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
*.env
|
||||||
|
tok.env
|
||||||
|
state_prod.json
|
||||||
|
*.csv
|
||||||
|
*.log
|
||||||
|
venv/
|
||||||
|
__pycache__/
|
||||||
38
audit_report.py
Normal file
38
audit_report.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import os
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
os.environ['SSL_CERT_FILE'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
os.environ['GRPC_DEFAULT_SSL_ROOTS_FILE_PATH'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
|
||||||
|
load_dotenv("/root/sber_bot/tok.env")
|
||||||
|
TOKEN = os.getenv("TINKOFF_TOKEN")
|
||||||
|
|
||||||
|
def q_to_f(q): return q.units + q.nano/1e9 if q else 0
|
||||||
|
|
||||||
|
with Client(TOKEN, target="invest-public-api.tbank.ru:443") as client:
|
||||||
|
# 1. Загружаем справочник тикеров, чтобы не мучить API в цикле
|
||||||
|
instr_dict = {i.figi: i.ticker for i in client.instruments.shares().instruments}
|
||||||
|
accounts = client.users.get_accounts().accounts
|
||||||
|
|
||||||
|
print(f"{'Дата (MSK)':<15} | {'Тикер':<6} | {'Тип':<8} | {'Цена':<8} | {'Кол':<4} | {'Сумма':<10}")
|
||||||
|
print("-" * 65)
|
||||||
|
|
||||||
|
for acc in accounts:
|
||||||
|
ops = client.operations.get_operations(
|
||||||
|
account_id=acc.id,
|
||||||
|
from_=datetime.now(timezone.utc) - timedelta(days=7),
|
||||||
|
to=datetime.now(timezone.utc)
|
||||||
|
).operations
|
||||||
|
|
||||||
|
for o in ops:
|
||||||
|
if o.operation_type.name in ['OPERATION_TYPE_BUY', 'OPERATION_TYPE_SELL']:
|
||||||
|
ticker = instr_dict.get(o.figi, "N/A")
|
||||||
|
date = o.date.astimezone(timezone(timedelta(hours=3))).strftime("%d.%m %H:%M")
|
||||||
|
op_type = "BUY" if "BUY" in o.operation_type.name else "SELL"
|
||||||
|
price = q_to_f(o.price)
|
||||||
|
payment = q_to_f(o.payment)
|
||||||
|
|
||||||
|
print(f"{date:<15} | {ticker:<6} | {op_type:<8} | {price:<8.2f} | {int(o.quantity):<4} | {payment:<10.2f}")
|
||||||
|
EOF
|
||||||
106
bot.py
Normal file
106
bot.py
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
import time, os, requests, json, urllib3
|
||||||
|
from datetime import datetime, timedelta, timezone, time as dtime
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||||
|
load_dotenv("tok.env")
|
||||||
|
|
||||||
|
TOKEN = os.getenv("TINKOFF_TOKEN")
|
||||||
|
TG_TOKEN = os.getenv("TG_TOKEN")
|
||||||
|
TG_CHAT_ID = os.getenv("TG_CHAT_ID")
|
||||||
|
ACC_ID = os.getenv("ACCOUNT_ID")
|
||||||
|
|
||||||
|
INSTRUMENT_UID = "a78b8349-a1dc-447d-9277-1d75826d089a"
|
||||||
|
BASE_URL = "https://invest-public-api.tbank.ru/rest"
|
||||||
|
STATE_FILE = "bot_state_prod.json"
|
||||||
|
|
||||||
|
s = requests.Session()
|
||||||
|
s.headers.update({"Authorization": f"Bearer {TOKEN}", "Content-Type": "application/json"})
|
||||||
|
|
||||||
|
def get_price():
|
||||||
|
path = f"{BASE_URL}/tinkoff.public.invest.api.contract.v1.MarketDataService/GetLastPrices"
|
||||||
|
try:
|
||||||
|
r = s.post(path, json={"instrumentId": [INSTRUMENT_UID]}, timeout=5)
|
||||||
|
if r.status_code != 200: return None
|
||||||
|
res = r.json()
|
||||||
|
if 'lastPrices' in res and res['lastPrices']:
|
||||||
|
p = res['lastPrices'][0]['price']
|
||||||
|
return int(p.get('units', 0)) + int(p.get('nano', 0)) / 1e9
|
||||||
|
except: return None
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_atr_steps():
|
||||||
|
path = f"{BASE_URL}/tinkoff.public.invest.api.contract.v1.MarketDataService/GetCandles"
|
||||||
|
try:
|
||||||
|
now_utc = datetime.now(timezone.utc)
|
||||||
|
payload = {
|
||||||
|
"instrumentId": INSTRUMENT_UID,
|
||||||
|
"from": (now_utc - timedelta(days=2)).strftime('%Y-%m-%dT%H:%M:%SZ'),
|
||||||
|
"to": now_utc.strftime('%Y-%m-%dT%H:%M:%SZ'),
|
||||||
|
"interval": "CANDLE_INTERVAL_HOUR"
|
||||||
|
}
|
||||||
|
r = s.post(path, json=payload, timeout=10)
|
||||||
|
candles = r.json().get('candles', [])
|
||||||
|
if len(candles) < 2: return 1.1, 1.5
|
||||||
|
|
||||||
|
def to_f(p): return int(p.get('units', 0)) + int(p.get('nano', 0)) / 1e9
|
||||||
|
trs = [to_f(c['high']) - to_f(c['low']) for c in candles[-14:]]
|
||||||
|
atr = sum(trs) / len(trs)
|
||||||
|
|
||||||
|
buy_step = max(round(atr * 0.45, 2), 0.5)
|
||||||
|
return buy_step, round(buy_step * 1.2, 2)
|
||||||
|
except: return 1.1, 1.5
|
||||||
|
|
||||||
|
def post_order(direction):
|
||||||
|
path = f"{BASE_URL}/tinkoff.public.invest.api.contract.v1.OrdersService/PostOrder"
|
||||||
|
payload = {
|
||||||
|
"instrumentId": INSTRUMENT_UID, "quantity": 1,
|
||||||
|
"direction": direction, "orderType": "ORDER_TYPE_MARKET",
|
||||||
|
"accountId": ACC_ID, "orderId": f"p_{int(time.time())}"
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
r = s.post(path, json=payload, timeout=10)
|
||||||
|
return r.status_code == 200
|
||||||
|
except: return False
|
||||||
|
|
||||||
|
def run():
|
||||||
|
print("🚀 БОТ ЗАПУЩЕН")
|
||||||
|
state = {"phase": "BUY", "base_price": None}
|
||||||
|
if os.path.exists(STATE_FILE):
|
||||||
|
try:
|
||||||
|
with open(STATE_FILE, 'r') as f: state = json.load(f)
|
||||||
|
except: pass
|
||||||
|
|
||||||
|
buy_step, profit_step = get_atr_steps()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
price = get_price()
|
||||||
|
if price:
|
||||||
|
if state['base_price'] is None:
|
||||||
|
state['base_price'] = price
|
||||||
|
with open(STATE_FILE, 'w') as f: json.dump(state, f)
|
||||||
|
print(f"\n🎯 База установлена: {price}")
|
||||||
|
|
||||||
|
if state['phase'] == "BUY":
|
||||||
|
target = round(state['base_price'] - buy_step, 2)
|
||||||
|
else:
|
||||||
|
target = round(state['base_price'] + profit_step, 2)
|
||||||
|
|
||||||
|
print(f"[{datetime.now().strftime('%H:%M:%S')}] Цена: {price:.2f} | Цель: {target:.2f} | {state['phase']} ", end='\r')
|
||||||
|
|
||||||
|
if state['phase'] == "BUY" and price <= target:
|
||||||
|
if post_order("ORDER_DIRECTION_BUY"):
|
||||||
|
state.update({"phase": "SELL", "base_price": price})
|
||||||
|
with open(STATE_FILE, 'w') as f: json.dump(state, f)
|
||||||
|
print(f"\n🛒 КУПЛЕНО по {price}")
|
||||||
|
|
||||||
|
elif state['phase'] == "SELL" and price >= target:
|
||||||
|
if post_order("ORDER_DIRECTION_SELL"):
|
||||||
|
state.update({"phase": "BUY", "base_price": price})
|
||||||
|
with open(STATE_FILE, 'w') as f: json.dump(state, f)
|
||||||
|
print(f"\n💰 ПРОДАНО по {price}")
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
1
bot_state_prod.json
Normal file
1
bot_state_prod.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"phase": "BUY", "base_price": 305.98}
|
||||||
11
check_acc.py
Normal file
11
check_acc.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import os, requests, json
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv("tok.env")
|
||||||
|
TOKEN = os.getenv("TINKOFF_TOKEN")
|
||||||
|
URL = "https://sandbox-invest-public-api.tinkoff.ru/rest/tinkoff.public.invest.api.contract.v1.SandboxService/GetSandboxAccounts"
|
||||||
|
|
||||||
|
headers = {"Authorization": f"Bearer {TOKEN}", "Content-Type": "application/json"}
|
||||||
|
r = requests.post(URL, json={}, headers=headers)
|
||||||
|
|
||||||
|
print(json.dumps(r.json(), indent=4))
|
||||||
18
check_me.py
Normal file
18
check_me.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
load_dotenv("tok.env")
|
||||||
|
TOKEN = os.getenv("TINKOFF_TOKEN")
|
||||||
|
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
accounts = client.users.get_accounts().accounts
|
||||||
|
print("--- ДОСТУПНЫЕ СЧЕТА ---")
|
||||||
|
for acc in accounts:
|
||||||
|
print(f"ID: {acc.id} | Имя: {acc.name} | Статус: {acc.status.name}")
|
||||||
|
|
||||||
|
# Прямой запрос цены Сбера
|
||||||
|
price = client.market_data.get_last_prices(instrument_id=["a78b8349-a1dc-447d-9277-1d75826d089a"])
|
||||||
|
p = price.last_prices[0].price
|
||||||
|
print(f"\n--- ЦЕНА ИЗ API ---")
|
||||||
|
print(f"Цена: {p.units + p.nano / 1e9} руб.")
|
||||||
28
check_real.py
Normal file
28
check_real.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
os.environ['SSL_CERT_FILE'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
os.environ['GRPC_DEFAULT_SSL_ROOTS_FILE_PATH'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
|
||||||
|
load_dotenv("tok.env")
|
||||||
|
TOKEN = os.getenv("TINKOFF_TOKEN")
|
||||||
|
|
||||||
|
with Client(TOKEN, target="invest-public-api.tbank.ru:443") as client:
|
||||||
|
# 1. Получаем инфо о счете
|
||||||
|
accounts = client.users.get_accounts().accounts
|
||||||
|
for acc in accounts:
|
||||||
|
print(f"\n--- ИНФОРМАЦИЯ О СЧЕТЕ ---")
|
||||||
|
print(f"Имя: {acc.name} | ID: {acc.id}")
|
||||||
|
print(f"Тип счета (API): {acc.type.name}") # Ищем ACCOUNT_TYPE_T_INVESTMENTS
|
||||||
|
|
||||||
|
# 2. Проверяем баланс (реальный или фантики)
|
||||||
|
p = client.operations.get_portfolio(account_id=acc.id)
|
||||||
|
print(f"Баланс: {p.total_amount_currencies.units} {p.total_amount_currencies.currency}")
|
||||||
|
|
||||||
|
# 3. Проверяем цену Сбера по актуальному UID
|
||||||
|
SBER_UID = "e6123145-9665-43e0-8413-cd61b8aa9b13"
|
||||||
|
lp = client.market_data.get_last_prices(instrument_id=[SBER_UID]).last_prices[0]
|
||||||
|
print(f"\n--- ПРОВЕРКА РЫНКА ---")
|
||||||
|
print(f"Цена SBER в API: {lp.price.units + lp.price.nano / 1e9}")
|
||||||
|
print(f"Дата цены (UTC): {lp.time.strftime('%Y-%m-%d %H:%M:%S')}")
|
||||||
BIN
cloudflared.deb
Normal file
BIN
cloudflared.deb
Normal file
Binary file not shown.
21
config.json
Normal file
21
config.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"TICKER": "SBER",
|
||||||
|
"CLASS_CODE": "TQBR",
|
||||||
|
"ACCOUNT_ID": "2009330616",
|
||||||
|
"MAX_TICKER_BUDGET": 50000,
|
||||||
|
"WEB_PORT": 5000,
|
||||||
|
"DCA_STEPS": [0.15, 0.15, 0.2, 0.2, 0.3],
|
||||||
|
"RISK_FRACTION": 0.95,
|
||||||
|
"STEP_DISTANCE_ATR": 1.0,
|
||||||
|
"ATR_COEFF": 0.5,
|
||||||
|
"PROFIT_COEFF": 2.5,
|
||||||
|
"SL_COEFF": 2.0,
|
||||||
|
"TRAILING_REBOUND": 0.3,
|
||||||
|
"EARLY_EXIT_PCT": 0.010,
|
||||||
|
"RSI_BUY_THRESHOLD": 42,
|
||||||
|
"TREND_CANDLES": 20,
|
||||||
|
"COOLDOWN_MINUTES": 60,
|
||||||
|
"MAX_HOLD_HOURS": 48,
|
||||||
|
"DAILY_LOSS_LIMIT": -600,
|
||||||
|
"MAX_SPREAD": 0.0015
|
||||||
|
}
|
||||||
48
diag_session.py
Normal file
48
diag_session.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import os
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from t_tech.invest import Client, InstrumentIdType
|
||||||
|
|
||||||
|
# Настройка SSL для российских сертификатов (уже настроена на вашем сервере)
|
||||||
|
os.environ['SSL_CERT_FILE'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
os.environ['GRPC_DEFAULT_SSL_ROOTS_FILE_PATH'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
|
||||||
|
load_dotenv("tok.env")
|
||||||
|
TOKEN = os.getenv("TINKOFF_TOKEN")
|
||||||
|
SBER_UID = "a78b8349-a1dc-447d-9277-1d75826d089a"
|
||||||
|
|
||||||
|
print("\n--- ЗАПУСК ДЕТЕКТОРА ЛЖИ API ---")
|
||||||
|
|
||||||
|
try:
|
||||||
|
with Client(TOKEN, target="invest-public-api.tbank.ru:443") as client:
|
||||||
|
# 1. Проверяем статус торгов прямо сейчас
|
||||||
|
status = client.market_data.get_trading_status(instrument_id=SBER_UID)
|
||||||
|
print(f"🔹 Статус торгов: {status.trading_status.name}")
|
||||||
|
|
||||||
|
# 2. Запрашиваем цену и ВРЕМЯ этой цены
|
||||||
|
lp_resp = client.market_data.get_last_prices(instrument_id=[SBER_UID])
|
||||||
|
lp = lp_resp.last_prices[0]
|
||||||
|
actual_price = lp.price.units + lp.price.nano / 1e9
|
||||||
|
|
||||||
|
print(f"\n🔹 Цена в API: {actual_price} руб.")
|
||||||
|
print(f"🔹 Время цены (UTC): {lp.time.strftime('%Y-%m-%d %H:%M:%S')}")
|
||||||
|
|
||||||
|
# Сравниваем время
|
||||||
|
now_utc = datetime.now(timezone.utc)
|
||||||
|
print(f"🔹 Ваше время (UTC): {now_utc.strftime('%Y-%m-%d %H:%M:%S')}")
|
||||||
|
|
||||||
|
# 3. Список ваших счетов
|
||||||
|
accounts = client.users.get_accounts().accounts
|
||||||
|
print("\n--- ВАШИ ДОСТУПНЫЕ СЧЕТА ---")
|
||||||
|
for acc in accounts:
|
||||||
|
portfolio = client.operations.get_portfolio(account_id=acc.id)
|
||||||
|
print(f"ID: {acc.id} | Имя: {acc.name:10} | Тип: {acc.type.name} | Баланс: {portfolio.total_amount_currencies.units} руб.")
|
||||||
|
|
||||||
|
if actual_price < 310:
|
||||||
|
print("\n🚨 ЗАКЛЮЧЕНИЕ: Ваш API-токен подключен к ДЕМО-КОНТУРУ.")
|
||||||
|
print("Цена 305.98 — это исторические данные мая 2024 года.")
|
||||||
|
else:
|
||||||
|
print("\n📈 ЗАКЛЮЧЕНИЕ: Вы на реальном рынке.")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"\n❌ ОШИБКА: {e}")
|
||||||
53
final_audit.py
Normal file
53
final_audit.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import os
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
# Настройка SSL для вашего сервера
|
||||||
|
os.environ['SSL_CERT_FILE'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
os.environ['GRPC_DEFAULT_SSL_ROOTS_FILE_PATH'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
|
||||||
|
load_dotenv("/root/sber_bot/tok.env")
|
||||||
|
TOKEN = os.getenv("TINKOFF_TOKEN")
|
||||||
|
|
||||||
|
def q_to_f(q):
|
||||||
|
if not q: return 0.0
|
||||||
|
return q.units + q.nano/1e9
|
||||||
|
|
||||||
|
with Client(TOKEN, target="invest-public-api.tbank.ru:443") as client:
|
||||||
|
# 1. Загружаем справочник акций, чтобы знать тикеры
|
||||||
|
print("⏳ Загрузка справочника инструментов...")
|
||||||
|
shares = client.instruments.shares().instruments
|
||||||
|
ticker_map = {s.uid: s.ticker for s in shares}
|
||||||
|
figi_map = {s.figi: s.ticker for s in shares}
|
||||||
|
|
||||||
|
# 2. Получаем все счета
|
||||||
|
accounts = client.users.get_accounts().accounts
|
||||||
|
|
||||||
|
print(f"\n{'ДАТА (MSK)':<15} | {'СЧЕТ':<15} | {'ТИКЕР':<6} | {'ТИП':<12} | {'СУММА':<12}")
|
||||||
|
print("-" * 70)
|
||||||
|
|
||||||
|
for acc in accounts:
|
||||||
|
# Запрашиваем абсолютно все операции за 14 дней
|
||||||
|
ops = client.operations.get_operations(
|
||||||
|
account_id=acc.id,
|
||||||
|
from_=datetime.now(timezone.utc) - timedelta(days=14),
|
||||||
|
to=datetime.now(timezone.utc)
|
||||||
|
).operations
|
||||||
|
|
||||||
|
for o in ops:
|
||||||
|
ticker = ticker_map.get(o.instrument_uid) or figi_map.get(o.figi) or ""
|
||||||
|
|
||||||
|
# Нам интересны только Сбер, Татнефть и движение денег
|
||||||
|
is_target = any(t in ticker for t in ["SBER", "TATN"])
|
||||||
|
is_money = "PAYMENT" in o.operation_type.name or "DEPOSIT" in o.operation_type.name
|
||||||
|
|
||||||
|
if is_target or is_money:
|
||||||
|
date = o.date.astimezone(timezone(timedelta(hours=3))).strftime("%d.%m %H:%M")
|
||||||
|
op_name = o.type
|
||||||
|
payment = q_to_f(o.payment)
|
||||||
|
|
||||||
|
# Если это покупка/продажа, добавим цену для наглядности
|
||||||
|
price_str = f" @ {q_to_f(o.price):.2f}" if q_to_f(o.price) > 0 else ""
|
||||||
|
|
||||||
|
print(f"{date:<15} | {acc.name[:15]:<15} | {ticker:<6} | {op_name[:12]:<12} | {payment:>10.2f} RUB {price_str}")
|
||||||
318
final_bot.py
Normal file
318
final_bot.py
Normal file
@@ -0,0 +1,318 @@
|
|||||||
|
import os, json, time, uuid, logging, requests, threading, csv
|
||||||
|
from datetime import datetime, timedelta, timezone, time as dtime
|
||||||
|
from flask import Flask, render_template_string
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
load_dotenv(os.path.join(BASE_DIR, "tok.env"))
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s",
|
||||||
|
handlers=[logging.FileHandler(os.path.join(BASE_DIR, "bot.log")), logging.StreamHandler()]
|
||||||
|
)
|
||||||
|
os.environ['SSL_CERT_FILE'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
os.environ['GRPC_DEFAULT_SSL_ROOTS_FILE_PATH'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
|
||||||
|
from t_tech.invest import Client, OrderDirection, OrderType, CandleInterval, InstrumentIdType
|
||||||
|
|
||||||
|
MSK_TZ, STATE_FILE, CONFIG_FILE, TRADE_LOG, TELEMETRY_LOG = timezone(timedelta(hours=3)), os.path.join(BASE_DIR, "state_prod.json"), os.path.join(BASE_DIR, "config.json"), os.path.join(BASE_DIR, "trades.csv"), os.path.join(BASE_DIR, "market_telemetry.csv")
|
||||||
|
state_lock, TG_PROXY = threading.Lock(), "https://muddy-firefly-3862.y-afanasiev.workers.dev"
|
||||||
|
|
||||||
|
def q_to_float(q): return q.units + q.nano / 1e9 if q else 0.0
|
||||||
|
|
||||||
|
def load_config():
|
||||||
|
try:
|
||||||
|
with open(CONFIG_FILE, 'r') as f: return json.load(f)
|
||||||
|
# FIX: Добавлен ACCOUNT_ID в fallback для защиты от KeyError
|
||||||
|
except: return {"TICKER": "UNKNOWN", "WEB_PORT": 5000, "ACCOUNT_ID": ""}
|
||||||
|
|
||||||
|
def save_state_atomic(state):
|
||||||
|
tmp = STATE_FILE + ".tmp"
|
||||||
|
with state_lock:
|
||||||
|
try:
|
||||||
|
with open(tmp, 'w') as f: json.dump(state, f, indent=2)
|
||||||
|
os.replace(tmp, STATE_FILE)
|
||||||
|
except Exception as e: logging.error(f"Save Error: {e}")
|
||||||
|
|
||||||
|
def send_tg(msg, level="INFO"):
|
||||||
|
token, chat_id = os.getenv("TG_TOKEN"), os.getenv("TG_CHAT_ID")
|
||||||
|
if not token or not chat_id: return
|
||||||
|
icons = {"TRADE":"🛒","PROFIT":"💰","LOSS":"🩸","CRIT":"🚨","INFO":"🛰️","AI":"🧠"}
|
||||||
|
try: requests.post(f"{TG_PROXY}/bot{token}/sendMessage", json={"chat_id": chat_id, "text": f"{icons.get(level,'🤖')} *{level}*\n{msg}", "parse_mode": "Markdown"}, timeout=15)
|
||||||
|
except: pass
|
||||||
|
|
||||||
|
def send_tg_report(file_path, caption=""):
|
||||||
|
token, chat_id = os.getenv("TG_TOKEN"), os.getenv("TG_CHAT_ID")
|
||||||
|
if not token or not chat_id or not os.path.exists(file_path): return
|
||||||
|
try:
|
||||||
|
with open(file_path, 'rb') as f:
|
||||||
|
requests.post(f"{TG_PROXY}/bot{token}/sendDocument", data={"chat_id": chat_id, "caption": caption}, files={"document": f}, timeout=30)
|
||||||
|
except: pass
|
||||||
|
|
||||||
|
def calc_rsi(closes, period=14):
|
||||||
|
if len(closes) < period + 1: return 50.0
|
||||||
|
gains, losses = [max(closes[i] - closes[i-1], 0) for i in range(1, len(closes))], [max(closes[i-1] - closes[i], 0) for i in range(1, len(closes))]
|
||||||
|
ag, al = sum(gains[-period:]) / period, sum(losses[-period:]) / period
|
||||||
|
return round(100 - 100 / (1 + ag / al), 1) if al > 0 else 100.0
|
||||||
|
|
||||||
|
def log_trade(action, price, lots, shares, reason="", pnl=0):
|
||||||
|
exists = os.path.isfile(TRADE_LOG)
|
||||||
|
with open(TRADE_LOG, 'a', newline='') as f:
|
||||||
|
w = csv.writer(f)
|
||||||
|
if not exists: w.writerow(["Date","Action","Price","Lots","Shares","Reason","PnL"])
|
||||||
|
w.writerow([datetime.now(MSK_TZ).strftime("%Y-%m-%d %H:%M:%S"), action, price, lots, shares, reason, pnl])
|
||||||
|
|
||||||
|
def log_telemetry(ticker, price, rsi, trend, spread, vola):
|
||||||
|
exists = os.path.isfile(TELEMETRY_LOG)
|
||||||
|
with open(TELEMETRY_LOG, 'a', newline='') as f:
|
||||||
|
w = csv.writer(f)
|
||||||
|
if not exists: w.writerow(["Time","Ticker","Price","RSI","Trend","Spread","Vola%"])
|
||||||
|
w.writerow([datetime.now(MSK_TZ).strftime("%H:%M:%S"), ticker, price, rsi, trend, spread, vola])
|
||||||
|
|
||||||
|
def generate_ai_prompt(conf):
|
||||||
|
prompt_file = os.path.join(BASE_DIR, "AI_PROMPT_WEEKLY.txt")
|
||||||
|
try:
|
||||||
|
with open(prompt_file, 'w') as f:
|
||||||
|
f.write("SYSTEM ROLE: Квантовый финансовый аналитик.\n")
|
||||||
|
f.write(f"TASK: Проанализировать работу торгового бота RAPTOR для тикера {conf.get('TICKER', 'UNKNOWN')}.\n\n")
|
||||||
|
f.write("--- CURRENT CONFIG ---\n")
|
||||||
|
# FIX: Вырезаем приватные данные перед отправкой ИИ
|
||||||
|
safe_conf = {k: v for k, v in conf.items() if k not in ('ACCOUNT_ID', 'TINKOFF_TOKEN')}
|
||||||
|
f.write(json.dumps(safe_conf, indent=2) + "\n\n")
|
||||||
|
f.write("--- LAST TRADES ---\n")
|
||||||
|
if os.path.exists(TRADE_LOG):
|
||||||
|
with open(TRADE_LOG, 'r') as tl: f.writelines(tl.readlines()[-10:])
|
||||||
|
f.write("\n--- MARKET CONTEXT (Last Telemetry) ---\n")
|
||||||
|
if os.path.exists(TELEMETRY_LOG):
|
||||||
|
with open(TELEMETRY_LOG, 'r') as ml: f.writelines(ml.readlines()[-10:])
|
||||||
|
f.write("\nQUESTION: На основе данных выше, предложи оптимизацию ATR_COEFF или STEP_DISTANCE_ATR.\n")
|
||||||
|
return prompt_file
|
||||||
|
except: return None
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
@app.route('/')
|
||||||
|
def index():
|
||||||
|
now_tz = datetime.now(MSK_TZ)
|
||||||
|
# FIX: Оставили работу в выходные (без now_tz.weekday() > 4)
|
||||||
|
is_open = any([dtime(7, 0) <= now_tz.time() <= dtime(18, 45), dtime(19, 0) <= now_tz.time() <= dtime(23, 50)])
|
||||||
|
time_str = now_tz.strftime("%H:%M:%S")
|
||||||
|
|
||||||
|
def get_st(p):
|
||||||
|
# FIX: Добавлена last_vola в дефолтный словарь
|
||||||
|
d = {"phase":"OFFLINE","live_price":0,"total_shares":0,"current_step":0,"avg_price":0,"target_act":0,"profit_goal":0,"pnl":0,"daily_pnl":0,"deals_today":0,"trend":"N/A","last_rsi":50,"filter_status":"N/A","stop_loss":0,"last_atr":0,"last_vola":0.0}
|
||||||
|
try:
|
||||||
|
if os.path.exists(p):
|
||||||
|
with open(p, 'r') as f: data = json.load(f); d.update(data)
|
||||||
|
sh, lp, ap = d.get('total_shares', 0), d.get('live_price', 0), d.get('avg_price', 0)
|
||||||
|
d['pnl'] = round((lp - ap) * sh, 2) if sh > 0 else 0
|
||||||
|
if d['phase'] == "SELL" and d.get('profit_goal', 0) > 0:
|
||||||
|
d['progress'] = round(min(100, max(0, (lp - ap) / (d['profit_goal'] - ap) * 100)), 1)
|
||||||
|
elif d['phase'] == "BUY" and d.get('target_act', 0) > 0:
|
||||||
|
base = d.get('base_price', lp)
|
||||||
|
if base - d['target_act'] != 0: d['progress'] = round(min(100, max(0, (base - lp) / (base - d['target_act']) * 100)), 1)
|
||||||
|
else: d['progress'] = 0
|
||||||
|
else: d['progress'] = 0
|
||||||
|
except: pass
|
||||||
|
return d
|
||||||
|
|
||||||
|
sber = get_st("/root/sber_bot/state_prod.json")
|
||||||
|
gmkn = get_st("/root/gmkn_bot/state_prod.json")
|
||||||
|
|
||||||
|
return render_template_string("""<!DOCTYPE html><html lang="ru"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><title>RAPTOR v18.4 UI</title><meta http-equiv="refresh" content="5">
|
||||||
|
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🚀</text></svg>">
|
||||||
|
<style>
|
||||||
|
body{background:#0a0a0b;color:#eee;font-family:sans-serif;padding:12px;display:flex;justify-content:center}
|
||||||
|
.card{background:#161618;padding:20px;border-radius:18px;border:1px solid #2a2a2a;width:100%;max-width:360px;margin:8px}
|
||||||
|
.price{text-align:center;font-size:3rem;font-weight:bold;margin:8px 0}
|
||||||
|
.pnl{text-align:center;font-weight:bold;font-size:1.2rem;margin-bottom:10px}
|
||||||
|
.row{display:flex;justify-content:space-between;font-size:.82rem;color:#666;padding:3px 0;border-bottom:1px solid #1c1c1c}.row b{color:#ccc}
|
||||||
|
.progress-bg{background:#222;height:6px;border-radius:3px;margin:10px 0;overflow:hidden}
|
||||||
|
.progress-bar{background:cyan;height:100%;transition:width 0.5s}
|
||||||
|
@keyframes blink { 50% { opacity: 0.3; } }
|
||||||
|
.live-dot { animation: blink 1.5s linear infinite; font-size: 1.2rem; vertical-align: middle; }
|
||||||
|
</style></head><body><div style="max-width:820px;width:100%">
|
||||||
|
<h2 style="text-align:center;color:#444;letter-spacing:3px;margin-bottom:5px;">RAPTOR v18.4</h2>
|
||||||
|
<div style="text-align:center; margin-bottom:20px; font-size:0.9rem; background:#111; padding:8px; border-radius:10px; border:1px solid #222;">
|
||||||
|
{% if is_open %}
|
||||||
|
<span class="live-dot" style="color:#00e676;">🟢</span> <b style="color:#00e676; margin-right:15px;">РЫНОК ОТКРЫТ (Торги выходного дня)</b>
|
||||||
|
{% else %}
|
||||||
|
<span style="color:#ff5252;">🔴</span> <b style="color:#ff5252; margin-right:15px;">РЫНОК ЗАКРЫТ</b>
|
||||||
|
{% endif %}
|
||||||
|
<span style="color:#888;">Сервер (МСК): <b style="color:#fff;">{{ time_str }}</b></span>
|
||||||
|
</div>
|
||||||
|
<div style="display:flex;flex-wrap:wrap;justify-content:center">
|
||||||
|
{% for n, d in [('SBER', sber), ('GMKN', gmkn)] %}
|
||||||
|
<div class="card"><div style="display:flex;justify-content:space-between"><b style="color:cyan">{{ n }}</b><span style="color:{{ 'cyan' if d.phase=='BUY' else 'orange' }}">{{ d.phase }} [ст.{{ d.current_step }}]</span></div>
|
||||||
|
<div class="price">{{ d.live_price }}</div>
|
||||||
|
<div class="pnl" style="color:{{ '#00e676' if d.pnl >= 0 else '#ff5252' }}">{{ d.pnl }} ₽</div>
|
||||||
|
<div class="progress-bg"><div class="progress-bar" style="width:{{ d.progress }}%; background:{{ 'cyan' if d.phase=='BUY' else '#4fc3f7' }}"></div></div>
|
||||||
|
<div style="border-top:1px solid #222;padding-top:10px">
|
||||||
|
<div class="row"><span>Avg / Stop</span><b>{{ d.avg_price }} / <span style="color:#ff5252">{{ d.stop_loss }}</span></b></div>
|
||||||
|
<div class="row"><span>Target (TP)</span><b style="color:#4fc3f7">{{ d.profit_goal }}</b></div>
|
||||||
|
<div class="row"><span>Следующий вход</span><b>{{ d.target_act }}</b></div>
|
||||||
|
<div class="row"><span>ATR / RSI / Vola</span><b>{{ d.last_atr }} / {{ d.last_rsi }} / {{ d.last_vola }}%</b></div>
|
||||||
|
<div class="row"><span>Тренд / Фильтр</span><b style="color:{{ '#00e676' if d.trend=='UP' else '#ff9800' }}">{{ d.trend }}</b> / <b style="color:{{ '#00e676' if d.filter_status=='OK' else '#ff9800' }}">{{ d.filter_status }}</b></div>
|
||||||
|
<div class="row"><span>Сделок / P&L дня</span><b>{{ d.deals_today }} / <span style="color:{{ '#00e676' if d.daily_pnl >= 0 else '#ff5252' }}">{{ d.daily_pnl }} ₽</span></b></div>
|
||||||
|
</div></div>{% endfor %}</div></div></body></html>""", sber=sber, gmkn=gmkn, is_open=is_open, time_str=time_str)
|
||||||
|
|
||||||
|
def is_market_open():
|
||||||
|
now = datetime.now(MSK_TZ)
|
||||||
|
t = now.time()
|
||||||
|
# FIX: Торги выходного дня (работает 7 дней в неделю)
|
||||||
|
return any([dtime(7, 0) <= t <= dtime(18, 45), dtime(19, 0) <= t <= dtime(23, 50)])
|
||||||
|
|
||||||
|
def run_bot():
|
||||||
|
conf = load_config()
|
||||||
|
acc_id = conf.get("ACCOUNT_ID", "")
|
||||||
|
if not acc_id: logging.warning("ACCOUNT_ID не задан в config.json!")
|
||||||
|
|
||||||
|
state = {"phase": "BUY", "current_step": 0, "base_price": None, "live_price": 0, "total_shares": 0, "total_lots": 0, "avg_price": 0, "tp_activated": False, "target_act": 0, "profit_goal": 0, "stop_loss": 0, "max_p": 0, "buy_time_ts": 0, "last_sell_ts": 0, "deals_today": 0, "daily_pnl": 0.0, "last_date": str(datetime.now(MSK_TZ).date()), "trend": "WAIT", "last_rsi": 50, "filter_status": "INIT", "lot_size": 1, "last_atr": 0.0, "last_vola": 0.0, "reported": -1, "partial_sold": False, "ai_reported": -1}
|
||||||
|
if os.path.exists(STATE_FILE):
|
||||||
|
try:
|
||||||
|
with open(STATE_FILE, 'r') as f: state.update(json.load(f))
|
||||||
|
except: pass
|
||||||
|
|
||||||
|
with Client(os.getenv("TINKOFF_TOKEN"), target="invest-public-api.tbank.ru:443") as client:
|
||||||
|
try:
|
||||||
|
instr = client.instruments.share_by(id_type=InstrumentIdType.INSTRUMENT_ID_TYPE_TICKER, class_code=conf.get("CLASS_CODE", "TQBR"), id=conf.get("TICKER", "UNKNOWN")).instrument
|
||||||
|
target_uid, lot_size, min_inc = instr.uid, instr.lot, q_to_float(instr.min_price_increment)
|
||||||
|
state['lot_size'] = lot_size
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Init Error: {e}"); return
|
||||||
|
|
||||||
|
last_indicators_ts = last_telemetry_ts = 0; atr = 2.0
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
now = datetime.now(MSK_TZ)
|
||||||
|
if str(now.date()) != state.get('last_date'):
|
||||||
|
state.update({"deals_today": 0, "daily_pnl": 0.0, "last_date": str(now.date()), "reported": -1})
|
||||||
|
|
||||||
|
if now.hour == 23 and now.minute == 55 and state.get('reported') != now.day:
|
||||||
|
send_tg(f"📊 {conf['TICKER']} итог {now.strftime('%d.%m')}:\nСделок: {state['deals_today']}\nP&L дня: {state['daily_pnl']:+.0f} ₽", "INFO")
|
||||||
|
send_tg_report(TRADE_LOG, f"{conf['TICKER']} Trades")
|
||||||
|
state['reported'] = now.day; save_state_atomic(state)
|
||||||
|
|
||||||
|
if now.weekday() == 6 and now.hour == 21 and state.get('ai_reported') != now.isocalendar()[1]:
|
||||||
|
prompt_path = generate_ai_prompt(conf)
|
||||||
|
if prompt_path:
|
||||||
|
send_tg(f"🧠 Сформирован бриф ИИ по {conf['TICKER']}.", "AI")
|
||||||
|
send_tg_report(prompt_path, f"AI Prompt {conf['TICKER']}")
|
||||||
|
state['ai_reported'] = now.isocalendar()[1]; save_state_atomic(state)
|
||||||
|
|
||||||
|
if acc_id:
|
||||||
|
portfolio = client.operations.get_portfolio(account_id=acc_id)
|
||||||
|
pos = next((p for p in portfolio.positions if p.instrument_uid == target_uid), None)
|
||||||
|
state['total_shares'], state['total_lots'] = (int(q_to_float(pos.quantity)), int(q_to_float(pos.quantity)) // lot_size) if pos else (0, 0)
|
||||||
|
if pos and state['avg_price'] == 0: state['avg_price'] = q_to_float(pos.average_position_price)
|
||||||
|
|
||||||
|
if state['total_shares'] == 0 and state['phase'] == "SELL":
|
||||||
|
state.update({"phase": "BUY", "current_step": 0, "avg_price": 0, "tp_activated": False, "max_p": 0, "buy_time_ts": 0, "profit_goal": 0, "stop_loss": 0, "partial_sold": False})
|
||||||
|
|
||||||
|
cur_p = q_to_float(client.market_data.get_last_prices(instrument_id=[target_uid]).last_prices[0].price)
|
||||||
|
|
||||||
|
# FIX: Безопасная инициализация base_price ТОЛЬКО если цена > 0.1
|
||||||
|
if cur_p > 0.1:
|
||||||
|
state['live_price'] = cur_p
|
||||||
|
if state.get('base_price') is None:
|
||||||
|
state['base_price'] = cur_p
|
||||||
|
|
||||||
|
if not is_market_open(): save_state_atomic(state); time.sleep(60); continue
|
||||||
|
|
||||||
|
if time.time() - last_indicators_ts > 900:
|
||||||
|
c = client.market_data.get_candles(instrument_id=target_uid, from_=datetime.now(timezone.utc) - timedelta(days=5), to=datetime.now(timezone.utc), interval=CandleInterval.CANDLE_INTERVAL_HOUR).candles
|
||||||
|
if len(c) >= 20:
|
||||||
|
closes = [q_to_float(x.close) for x in c]
|
||||||
|
state['trend'] = "UP" if cur_p > (sum(closes[-conf.get("TREND_CANDLES", 20):]) / conf.get("TREND_CANDLES", 20)) else "DOWN"
|
||||||
|
state['last_rsi'] = calc_rsi(closes)
|
||||||
|
trs = [max(q_to_float(c[i].high) - q_to_float(c[i].low), abs(q_to_float(c[i].high) - q_to_float(c[i-1].close))) for i in range(1, len(c))]
|
||||||
|
atr = sum(trs[-14:]) / 14; state['last_atr'] = round(atr, 2)
|
||||||
|
state['last_vola'] = round((atr / cur_p) * 100, 2)
|
||||||
|
last_indicators_ts = time.time()
|
||||||
|
|
||||||
|
if time.time() - last_telemetry_ts > 900:
|
||||||
|
try:
|
||||||
|
ob = client.market_data.get_order_book(instrument_id=target_uid, depth=1)
|
||||||
|
spread = round((q_to_float(ob.asks[0].price) - q_to_float(ob.bids[0].price)) / q_to_float(ob.bids[0].price) * 100, 4) if ob.asks and ob.bids else 0.0
|
||||||
|
log_telemetry(conf["TICKER"], cur_p, state.get('last_rsi', 50), state.get('trend', 'WAIT'), spread, state.get('last_vola', 0))
|
||||||
|
except: pass
|
||||||
|
last_telemetry_ts = time.time()
|
||||||
|
|
||||||
|
buy_step = max(round(atr * conf.get("ATR_COEFF", 0.5), 2), conf.get("MIN_BUY_STEP", 1.0))
|
||||||
|
|
||||||
|
if state['total_lots'] > 0:
|
||||||
|
state['phase'] = "SELL"
|
||||||
|
if state.get('max_p', 0) == 0: state['max_p'] = state['avg_price']
|
||||||
|
if cur_p > state.get('max_p', 0): state['max_p'] = cur_p
|
||||||
|
sl_price = round(state['avg_price'] - buy_step * conf["SL_COEFF"], 2)
|
||||||
|
if state.get('tp_activated') or state.get('partial_sold'):
|
||||||
|
sl_price = max(sl_price, round(state['avg_price'] * 1.0008, 2))
|
||||||
|
state['stop_loss'] = sl_price
|
||||||
|
if not state.get('profit_goal'):
|
||||||
|
tp_mult = conf["PROFIT_COEFF"] if state['trend'] == "UP" else conf["PROFIT_COEFF"] * 0.7
|
||||||
|
state['profit_goal'] = round(state['avg_price'] + buy_step * tp_mult, 2)
|
||||||
|
if cur_p >= state['profit_goal']: state['tp_activated'] = True
|
||||||
|
rebound = max(buy_step * conf["TRAILING_REBOUND"], min_inc * 3)
|
||||||
|
is_tp, is_sl = state.get('tp_activated') and cur_p <= state['max_p'] - rebound, cur_p <= sl_price
|
||||||
|
is_time = state.get('buy_time_ts', 0) > 0 and now.timestamp() > state['buy_time_ts'] + conf["MAX_HOLD_HOURS"] * 3600
|
||||||
|
|
||||||
|
if not state.get('partial_sold') and state['total_lots'] >= 2 and cur_p >= state['avg_price'] * (1 + conf.get("EARLY_EXIT_PCT", 0.01)):
|
||||||
|
qty_to_sell = state['total_lots'] // 2
|
||||||
|
res = client.orders.post_order(instrument_id=target_uid, quantity=qty_to_sell, direction=OrderDirection.ORDER_DIRECTION_SELL, account_id=acc_id, order_type=OrderType.ORDER_TYPE_MARKET, order_id=str(uuid.uuid4()))
|
||||||
|
p_sold = q_to_float(res.executed_order_price) or cur_p
|
||||||
|
pnl = round((p_sold - state['avg_price']) * (qty_to_sell * lot_size), 2)
|
||||||
|
state['daily_pnl'] = round(state.get('daily_pnl', 0) + pnl, 2)
|
||||||
|
# FIX: Убран deals_today += 1 при частичной продаже (по замечанию аудитора)
|
||||||
|
state['partial_sold'] = True
|
||||||
|
log_trade("PARTIAL_SELL", p_sold, qty_to_sell, qty_to_sell * lot_size, "EarlyExit", pnl)
|
||||||
|
send_tg(f"💰 {conf['TICKER']} Частичная фиксация 50%\nP&L: {pnl:+.2f} ₽", "PROFIT")
|
||||||
|
|
||||||
|
if is_tp or is_sl or is_time:
|
||||||
|
reason = ("TP" if is_tp else ("SL" if is_sl else "TIME"))
|
||||||
|
res = client.orders.post_order(instrument_id=target_uid, quantity=state['total_lots'], direction=OrderDirection.ORDER_DIRECTION_SELL, account_id=acc_id, order_type=OrderType.ORDER_TYPE_MARKET, order_id=str(uuid.uuid4()))
|
||||||
|
p_sold = q_to_float(res.executed_order_price) or cur_p
|
||||||
|
pnl = round((p_sold - state['avg_price']) * state['total_shares'], 2)
|
||||||
|
state['daily_pnl'] = round(state.get('daily_pnl', 0) + pnl, 2); state['deals_today'] += 1
|
||||||
|
log_trade("SELL", p_sold, state['total_lots'], state['total_shares'], reason, pnl)
|
||||||
|
send_tg(f"{conf['TICKER']} [{reason}]\nP&L: {pnl:+.2f} ₽", "PROFIT" if pnl > 0 else "LOSS")
|
||||||
|
state.update({"phase": "BUY", "current_step": 0, "total_shares": 0, "total_lots": 0, "avg_price": 0, "tp_activated": False, "max_p": 0, "stop_loss": 0, "profit_goal": 0, "buy_time_ts": 0, "base_price": cur_p, "last_sell_ts": now.timestamp(), "partial_sold": False})
|
||||||
|
|
||||||
|
if state['phase'] == "BUY":
|
||||||
|
if state.get('daily_pnl', 0) <= conf["DAILY_LOSS_LIMIT"]:
|
||||||
|
state['filter_status'] = f"LIMIT {state['daily_pnl']:.0f}₽"; save_state_atomic(state); time.sleep(300); continue
|
||||||
|
step = state['current_step']
|
||||||
|
cooldown_ok, trend_ok, rsi_ok = now.timestamp() > state.get('last_sell_ts', 0) + conf["COOLDOWN_MINUTES"] * 60, state.get('trend') == "UP", state.get('last_rsi', 50) < conf["RSI_BUY_THRESHOLD"]
|
||||||
|
filters_ok = (cooldown_ok and trend_ok and rsi_ok) if step == 0 else True
|
||||||
|
|
||||||
|
# FIX: Корректный статус фильтра для дашборда на шагах DCA > 0
|
||||||
|
if step > 0:
|
||||||
|
state['filter_status'] = f"Ожидание DCA ст.{step+1}"
|
||||||
|
else:
|
||||||
|
if not cooldown_ok: state['filter_status'] = "COOLDOWN"
|
||||||
|
elif not trend_ok: state['filter_status'] = "TREND DOWN"
|
||||||
|
elif not rsi_ok: state['filter_status'] = f"RSI {state.get('last_rsi', 50):.0f}"
|
||||||
|
else: state['filter_status'] = "OK"
|
||||||
|
|
||||||
|
if filters_ok and step < len(conf.get("DCA_STEPS", [])):
|
||||||
|
if step == 0 and cur_p > state.get('base_price', cur_p): state['base_price'] = cur_p
|
||||||
|
state['target_act'] = round(state['base_price'] - (buy_step * conf.get("STEP_DISTANCE_ATR", 1.0)) * (step + 1), 2)
|
||||||
|
if cur_p <= state['target_act'] and acc_id:
|
||||||
|
step_budget = conf["MAX_TICKER_BUDGET"] * conf["DCA_STEPS"][step] * conf["RISK_FRACTION"]
|
||||||
|
qty = int(step_budget // (cur_p * lot_size))
|
||||||
|
if qty >= 1:
|
||||||
|
res = client.orders.post_order(instrument_id=target_uid, quantity=qty, direction=OrderDirection.ORDER_DIRECTION_BUY, account_id=acc_id, order_type=OrderType.ORDER_TYPE_MARKET, order_id=str(uuid.uuid4()))
|
||||||
|
p_bought = q_to_float(res.executed_order_price) or cur_p
|
||||||
|
if state['buy_time_ts'] == 0: state['buy_time_ts'] = now.timestamp()
|
||||||
|
state['current_step'] += 1
|
||||||
|
log_trade("BUY", p_bought, qty, qty * lot_size, f"Step{state['current_step']}")
|
||||||
|
send_tg(f"🛒 {conf['TICKER']} шаг {state['current_step']} @ {p_bought:.2f}", "TRADE")
|
||||||
|
elif step == 0: state['target_act'] = round(state['base_price'] - buy_step, 2)
|
||||||
|
save_state_atomic(state); time.sleep(2)
|
||||||
|
except Exception as e: logging.error(f"Loop Error: {e}"); time.sleep(10)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
conf_main = load_config()
|
||||||
|
threading.Thread(target=lambda: app.run(host='0.0.0.0', port=conf_main.get("WEB_PORT", 5000), use_reloader=False), daemon=True).start()
|
||||||
|
while True:
|
||||||
|
try: run_bot()
|
||||||
|
except KeyboardInterrupt: break
|
||||||
|
except Exception as e: logging.error(f"Fatal: {e}"); time.sleep(10)
|
||||||
42
find_new_acc.py
Normal file
42
find_new_acc.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
# Настройка SSL для работы с российскими сертификатами (уже настроена на вашем сервере)
|
||||||
|
os.environ['SSL_CERT_FILE'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
os.environ['GRPC_DEFAULT_SSL_ROOTS_FILE_PATH'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
|
||||||
|
load_dotenv("tok.env")
|
||||||
|
TOKEN = os.getenv("TINKOFF_TOKEN")
|
||||||
|
SBER_UID = "a78b8349-a1dc-447d-9277-1d75826d089a"
|
||||||
|
|
||||||
|
print("\n--- СКАНИРОВАНИЕ ОБНОВЛЕННОГО ДОСТУПА ---")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Подключаемся к НОВОМУ боевому адресу из документации
|
||||||
|
with Client(TOKEN, target="invest-public-api.tbank.ru:443") as client:
|
||||||
|
|
||||||
|
# 1. Запрашиваем цену и ВРЕМЯ этой цены
|
||||||
|
price_resp = client.market_data.get_last_prices(instrument_id=[SBER_UID])
|
||||||
|
lp = price_resp.last_prices[0]
|
||||||
|
actual_price = lp.price.units + lp.price.nano / 1e9
|
||||||
|
price_date = lp.time
|
||||||
|
|
||||||
|
print(f"🌍 ТЕКУЩАЯ ЦЕНА В API: {actual_price} руб.")
|
||||||
|
print(f"📅 ДАТА ЦЕНЫ В API: {price_date.strftime('%Y-%m-%d %H:%M:%S')} UTC")
|
||||||
|
|
||||||
|
if actual_price < 310:
|
||||||
|
print("\n🚨 ВНИМАНИЕ: Цена всё еще ИСТОРИЧЕСКАЯ (305 руб). Проблема в аккаунте!")
|
||||||
|
else:
|
||||||
|
print("\n✅ УРА! API показывает РЕАЛЬНУЮ рыночную цену!")
|
||||||
|
|
||||||
|
# 2. Получаем список всех счетов (ищем новый ACCOUNT_ID)
|
||||||
|
accounts = client.users.get_accounts().accounts
|
||||||
|
print("\n--- СПИСОК ВАШИХ СЧЕТОВ ---")
|
||||||
|
for acc in accounts:
|
||||||
|
print(f"🔹 Имя: {acc.name:15} | ID: {acc.id}")
|
||||||
|
print(f" Тип: {acc.type.name:20} | Статус: {acc.status.name}")
|
||||||
|
print("-" * 50)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"\n❌ ОШИБКА: {e}")
|
||||||
33
find_real_id.py
Normal file
33
find_real_id.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
# Настройка SSL
|
||||||
|
os.environ['SSL_CERT_FILE'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
os.environ['GRPC_DEFAULT_SSL_ROOTS_FILE_PATH'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
|
||||||
|
load_dotenv("tok.env")
|
||||||
|
TOKEN = os.getenv("TINKOFF_TOKEN")
|
||||||
|
|
||||||
|
with Client(TOKEN, target="invest-public-api.tbank.ru:443") as client:
|
||||||
|
# Получаем цену из котировок (MarketData)
|
||||||
|
price_resp = client.market_data.get_last_prices(instrument_id=["a78b8349-a1dc-447d-9277-1d75826d089a"])
|
||||||
|
market_price = price_resp.last_prices[0].price
|
||||||
|
actual_price = market_price.units + market_price.nano / 1e9
|
||||||
|
|
||||||
|
print(f"\n--- ПРОВЕРКА РЫНКА ---")
|
||||||
|
print(f"Текущая цена SBER в API: {actual_price} руб.")
|
||||||
|
|
||||||
|
# Получаем список всех счетов
|
||||||
|
accounts = client.users.get_accounts().accounts
|
||||||
|
print("\n--- ВАШИ СЧЕТА ---")
|
||||||
|
for acc in accounts:
|
||||||
|
# Запрашиваем баланс по каждому счету
|
||||||
|
portfolio = client.operations.get_portfolio(account_id=acc.id)
|
||||||
|
balance = portfolio.total_amount_currencies.units
|
||||||
|
print(f"Счет: {acc.name:15} | ID: {acc.id} | Баланс: {balance} руб. | Тип: {acc.type.name}")
|
||||||
|
|
||||||
|
print("\n--- ИНСТРУКЦИЯ ---")
|
||||||
|
print("1. Если цена выше 310 — API отдает реальные данные.")
|
||||||
|
print("2. Найдите счет, где ваш РЕАЛЬНЫЙ баланс (не 0 и не 1 000 000 виртуальных рублей).")
|
||||||
|
print("3. Скопируйте его ID в tok.env.")
|
||||||
37
full_audit.py
Normal file
37
full_audit.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import os
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
os.environ['SSL_CERT_FILE'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
os.environ['GRPC_DEFAULT_SSL_ROOTS_FILE_PATH'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
|
||||||
|
load_dotenv("/root/sber_bot/tok.env")
|
||||||
|
TOKEN = os.getenv("TINKOFF_TOKEN")
|
||||||
|
|
||||||
|
def q_to_f(q): return q.units + q.nano/1e9 if q else 0
|
||||||
|
|
||||||
|
with Client(TOKEN, target="invest-public-api.tbank.ru:443") as client:
|
||||||
|
# 1. Загружаем справочник тикеров, чтобы не мучить API в цикле
|
||||||
|
instr_dict = {i.figi: i.ticker for i in client.instruments.shares().instruments}
|
||||||
|
accounts = client.users.get_accounts().accounts
|
||||||
|
|
||||||
|
print(f"{'Дата (MSK)':<15} | {'Тикер':<6} | {'Тип':<8} | {'Цена':<8} | {'Кол':<4} | {'Сумма':<10}")
|
||||||
|
print("-" * 65)
|
||||||
|
|
||||||
|
for acc in accounts:
|
||||||
|
ops = client.operations.get_operations(
|
||||||
|
account_id=acc.id,
|
||||||
|
from_=datetime.now(timezone.utc) - timedelta(days=7),
|
||||||
|
to=datetime.now(timezone.utc)
|
||||||
|
).operations
|
||||||
|
|
||||||
|
for o in ops:
|
||||||
|
if o.operation_type.name in ['OPERATION_TYPE_BUY', 'OPERATION_TYPE_SELL']:
|
||||||
|
ticker = instr_dict.get(o.figi, "N/A")
|
||||||
|
date = o.date.astimezone(timezone(timedelta(hours=3))).strftime("%d.%m %H:%M")
|
||||||
|
op_type = "BUY" if "BUY" in o.operation_type.name else "SELL"
|
||||||
|
price = q_to_f(o.price)
|
||||||
|
payment = q_to_f(o.payment)
|
||||||
|
|
||||||
|
print(f"{date:<15} | {ticker:<6} | {op_type:<8} | {price:<8.2f} | {int(o.quantity):<4} | {payment:<10.2f}")
|
||||||
41
full_audit_v2.py
Normal file
41
full_audit_v2.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import os
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
os.environ['SSL_CERT_FILE'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
os.environ['GRPC_DEFAULT_SSL_ROOTS_FILE_PATH'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
|
||||||
|
load_dotenv("/root/sber_bot/tok.env")
|
||||||
|
TOKEN = os.getenv("TINKOFF_TOKEN")
|
||||||
|
|
||||||
|
def q_to_f(q): return q.units + q.nano/1e9 if q else 0
|
||||||
|
|
||||||
|
with Client(TOKEN, target="invest-public-api.tbank.ru:443") as client:
|
||||||
|
# Загружаем тикеры
|
||||||
|
shares = client.instruments.shares().instruments
|
||||||
|
ticker_map = {s.uid: s.ticker for s in shares}
|
||||||
|
figi_map = {s.figi: s.ticker for s in shares}
|
||||||
|
|
||||||
|
accounts = client.users.get_accounts().accounts
|
||||||
|
|
||||||
|
print(f"{'Дата (MSK)':<15} | {'Счет':<12} | {'Тикер':<6} | {'Тип':<5} | {'Цена':<8} | {'Сумма':<10}")
|
||||||
|
print("-" * 80)
|
||||||
|
|
||||||
|
for acc in accounts:
|
||||||
|
ops = client.operations.get_operations(
|
||||||
|
account_id=acc.id,
|
||||||
|
from_=datetime.now(timezone.utc) - timedelta(days=10),
|
||||||
|
to=datetime.now(timezone.utc)
|
||||||
|
).operations
|
||||||
|
|
||||||
|
for o in ops:
|
||||||
|
if "TYPE_BUY" in o.operation_type.name or "TYPE_SELL" in o.operation_type.name:
|
||||||
|
# Определяем тикер
|
||||||
|
t = ticker_map.get(o.instrument_uid) or figi_map.get(o.figi) or "N/A"
|
||||||
|
date = o.date.astimezone(timezone(timedelta(hours=3))).strftime("%d.%m %H:%M")
|
||||||
|
op_type = "BUY" if "BUY" in o.operation_type.name else "SELL"
|
||||||
|
price = q_to_f(o.price)
|
||||||
|
payment = q_to_f(o.payment)
|
||||||
|
|
||||||
|
print(f"{date:<15} | {acc.name[:12]:<12} | {t:<6} | {op_type:<5} | {price:<8.2f} | {payment:<10.2f}")
|
||||||
24
get_id.py
Normal file
24
get_id.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
# Настройка SSL для работы с российскими сертификатами
|
||||||
|
os.environ['SSL_CERT_FILE'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
os.environ['GRPC_DEFAULT_SSL_ROOTS_FILE_PATH'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
|
||||||
|
load_dotenv("tok.env")
|
||||||
|
TOKEN = os.getenv("TINKOFF_TOKEN")
|
||||||
|
|
||||||
|
print("\n--- ЗАПРОС СПИСКА ВАШИХ РЕАЛЬНЫХ СЧЕТОВ ---")
|
||||||
|
|
||||||
|
try:
|
||||||
|
with Client(TOKEN, target="invest-public-api.tbank.ru:443") as client:
|
||||||
|
accounts = client.users.get_accounts().accounts
|
||||||
|
if not accounts:
|
||||||
|
print("❌ Счета не найдены. Проверьте права вашего токена!")
|
||||||
|
else:
|
||||||
|
for acc in accounts:
|
||||||
|
print(f"🔹 Имя: {acc.name:15} | ID: {acc.id} | Тип: {acc.type.name}")
|
||||||
|
print("\n✅ СКОПИРУЙТЕ НУЖНЫЙ ID И ВСТАВЬТЕ ЕГО В tok.env")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Ошибка подключения: {e}")
|
||||||
24
get_today_trades.py
Normal file
24
get_today_trades.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import os, requests
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
os.environ['SSL_CERT_FILE'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
os.environ['GRPC_DEFAULT_SSL_ROOTS_FILE_PATH'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
|
||||||
|
load_dotenv("/root/sber_bot/tok.env")
|
||||||
|
TOKEN = os.getenv("TINKOFF_TOKEN")
|
||||||
|
ACC_ID = os.getenv("ACCOUNT_ID")
|
||||||
|
|
||||||
|
def q_to_f(q): return q.units + q.nano/1e9 if q else 0
|
||||||
|
|
||||||
|
with Client(TOKEN, target="invest-public-api.tbank.ru:443") as client:
|
||||||
|
from_date = datetime.now(timezone.utc) - timedelta(days=1)
|
||||||
|
to_date = datetime.now(timezone.utc)
|
||||||
|
|
||||||
|
print(f"\n--- РЕАЛЬНЫЕ СДЕЛКИ ЗА 24 ЧАСА (Счет {ACC_ID}) ---")
|
||||||
|
ops = client.operations.get_operations(account_id=ACC_ID, from_=from_date, to=to_date).operations
|
||||||
|
|
||||||
|
for o in ops:
|
||||||
|
if o.operation_type.name in ['OPERATION_TYPE_BUY', 'OPERATION_TYPE_SELL']:
|
||||||
|
print(f"{o.date.strftime('%H:%M:%S')} | {o.type} | {q_to_f(o.price)} руб. | {o.quantity} шт. | Итог: {q_to_f(o.payment)} руб.")
|
||||||
33
hardcopy.0
Normal file
33
hardcopy.0
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
[22:17:39] K=>:: 318.80 | &5;L BUY: 317.01
|
||||||
|
[22:17:40] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:41] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:42] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:43] K=>:: 318.80 | &5;L BUY: 317.01
|
||||||
|
[22:17:44] K=>:: 318.80 | &5;L BUY: 317.01
|
||||||
|
[22:17:45] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:46] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:47] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:48] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:49] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:50] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:51] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:52] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:53] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:54] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:56] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:57] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:58] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:17:59] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:18:00] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:18:01] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:18:02] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:18:03] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:18:04] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:18:05] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:18:06] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:18:07] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:18:08] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:18:09] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:18:10] K=>:: 318.79 | &5;L BUY: 317.01
|
||||||
|
[22:18:11] K=>:: 318.80 | &5;L BUY: 317.01
|
||||||
|
|
||||||
BIN
invest-python-master.zip
Normal file
BIN
invest-python-master.zip
Normal file
Binary file not shown.
166
invest-python-master/.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
Normal file
166
invest-python-master/.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
name: Bug Report
|
||||||
|
description: Сообщить об ошибке
|
||||||
|
title: '[Bug] Title'
|
||||||
|
labels:
|
||||||
|
- bug
|
||||||
|
assignees:
|
||||||
|
- daxartio
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: 'Спасибо, что нашли время заполнить этот отчет об ошибке!
|
||||||
|
|
||||||
|
'
|
||||||
|
- type: textarea
|
||||||
|
id: what-happened
|
||||||
|
attributes:
|
||||||
|
label: Что случилось?
|
||||||
|
description: Краткое описание.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: to-reproduce
|
||||||
|
attributes:
|
||||||
|
label: Воспроизведение
|
||||||
|
description: Код повторяющий кейс
|
||||||
|
render: Python
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: dropdown
|
||||||
|
id: package-version
|
||||||
|
attributes:
|
||||||
|
label: T-Tech Invest Version
|
||||||
|
description: Какая версия библиотеки используется?
|
||||||
|
options:
|
||||||
|
- 0.3.5
|
||||||
|
- 0.3.4
|
||||||
|
- 0.3.3
|
||||||
|
- 0.3.2
|
||||||
|
- 0.3.1
|
||||||
|
- 0.2.0-beta118
|
||||||
|
- 0.2.0-beta117
|
||||||
|
- 0.2.0-beta116
|
||||||
|
- 0.2.0-beta115
|
||||||
|
- 0.2.0-beta114
|
||||||
|
- 0.2.0-beta113
|
||||||
|
- 0.2.0-beta112
|
||||||
|
- 0.2.0-beta111
|
||||||
|
- 0.2.0-beta110
|
||||||
|
- 0.2.0-beta109
|
||||||
|
- 0.2.0-beta108
|
||||||
|
- 0.2.0-beta107
|
||||||
|
- 0.2.0-beta106
|
||||||
|
- 0.2.0-beta105
|
||||||
|
- 0.2.0-beta104
|
||||||
|
- 0.2.0-beta103
|
||||||
|
- 0.2.0-beta101
|
||||||
|
- 0.2.0-beta100
|
||||||
|
- 0.2.0-beta99
|
||||||
|
- 0.2.0-beta98
|
||||||
|
- 0.2.0-beta97
|
||||||
|
- 0.2.0-beta96
|
||||||
|
- 0.2.0-beta95
|
||||||
|
- 0.2.0-beta94
|
||||||
|
- 0.2.0-beta93
|
||||||
|
- 0.2.0-beta92
|
||||||
|
- 0.2.0-beta91
|
||||||
|
- 0.2.0-beta90
|
||||||
|
- 0.2.0-beta89
|
||||||
|
- 0.2.0-beta88
|
||||||
|
- 0.2.0-beta87
|
||||||
|
- 0.2.0-beta86
|
||||||
|
- 0.2.0-beta85
|
||||||
|
- 0.2.0-beta84
|
||||||
|
- 0.2.0-beta83
|
||||||
|
- 0.2.0-beta82
|
||||||
|
- 0.2.0-beta81
|
||||||
|
- 0.2.0-beta80
|
||||||
|
- 0.2.0-beta79
|
||||||
|
- 0.2.0-beta78
|
||||||
|
- 0.2.0-beta77
|
||||||
|
- 0.2.0-beta76
|
||||||
|
- 0.2.0-beta75
|
||||||
|
- 0.2.0-beta74
|
||||||
|
- 0.2.0-beta73
|
||||||
|
- 0.2.0-beta72
|
||||||
|
- 0.2.0-beta71
|
||||||
|
- 0.2.0-beta70
|
||||||
|
- 0.2.0-beta69
|
||||||
|
- 0.2.0-beta68
|
||||||
|
- 0.2.0-beta67
|
||||||
|
- 0.2.0-beta66
|
||||||
|
- 0.2.0-beta65
|
||||||
|
- 0.2.0-beta64
|
||||||
|
- 0.2.0-beta63
|
||||||
|
- 0.2.0-beta62
|
||||||
|
- 0.2.0-beta61
|
||||||
|
- 0.2.0-beta60
|
||||||
|
- 0.2.0-beta59
|
||||||
|
- 0.2.0-beta58
|
||||||
|
- 0.2.0-beta57
|
||||||
|
- 0.2.0-beta56
|
||||||
|
- 0.2.0-beta55
|
||||||
|
- 0.2.0-beta54
|
||||||
|
- 0.2.0-beta53
|
||||||
|
- 0.2.0-beta52
|
||||||
|
- 0.2.0-beta51
|
||||||
|
- 0.2.0-beta50
|
||||||
|
- 0.2.0-beta49
|
||||||
|
- 0.2.0-beta48
|
||||||
|
- 0.2.0-beta47
|
||||||
|
- 0.2.0-beta46
|
||||||
|
- 0.2.0-beta45
|
||||||
|
- 0.2.0-beta44
|
||||||
|
- 0.2.0-beta43
|
||||||
|
- 0.2.0-beta42
|
||||||
|
- 0.2.0-beta41
|
||||||
|
- 0.2.0-beta40
|
||||||
|
- 0.2.0-beta39
|
||||||
|
- 0.2.0-beta38
|
||||||
|
- 0.2.0-beta37
|
||||||
|
- 0.2.0-beta36
|
||||||
|
- 0.2.0-beta35
|
||||||
|
- 0.2.0-beta34
|
||||||
|
- 0.2.0-beta33
|
||||||
|
- 0.2.0-beta32
|
||||||
|
- 0.2.0-beta31
|
||||||
|
- 0.2.0-beta30
|
||||||
|
- 0.2.0-beta29
|
||||||
|
- 0.2.0-beta28
|
||||||
|
- 0.2.0-beta27
|
||||||
|
- Другая
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: dropdown
|
||||||
|
id: python-version
|
||||||
|
attributes:
|
||||||
|
label: Python Version
|
||||||
|
description: Какая версия Python-а используется?
|
||||||
|
options:
|
||||||
|
- '3.11'
|
||||||
|
- '3.10'
|
||||||
|
- '3.9'
|
||||||
|
- '3.8'
|
||||||
|
- Другая
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: dropdown
|
||||||
|
id: os
|
||||||
|
attributes:
|
||||||
|
label: OS
|
||||||
|
description: Ваша операционная система.
|
||||||
|
options:
|
||||||
|
- Windows
|
||||||
|
- Linux
|
||||||
|
- Mac OS
|
||||||
|
- Mac OS (m1)
|
||||||
|
- Другая
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: logs
|
||||||
|
attributes:
|
||||||
|
label: Логи
|
||||||
|
description: Скопируйте и вставьте сюда логи. Не забудьте скрыть чувствительные
|
||||||
|
данные.
|
||||||
|
render: Shell
|
||||||
25
invest-python-master/.github/ISSUE_TEMPLATE/feature_request.yaml
vendored
Normal file
25
invest-python-master/.github/ISSUE_TEMPLATE/feature_request.yaml
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
name: Feature request
|
||||||
|
description: Предложите идею для этого проекта
|
||||||
|
title: "[Feature] Title"
|
||||||
|
labels: ["enhancement"]
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Описание
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: to-resolve
|
||||||
|
attributes:
|
||||||
|
label: Желаемое решение
|
||||||
|
description: Что нужно сделать?
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: textarea
|
||||||
|
id: additional
|
||||||
|
attributes:
|
||||||
|
label: Дополнительно
|
||||||
|
description: Фрагменты кода, описание апи, ...
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
156
invest-python-master/.github/ISSUE_TEMPLATE/issue.yaml
vendored
Normal file
156
invest-python-master/.github/ISSUE_TEMPLATE/issue.yaml
vendored
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
name: Custom Issue
|
||||||
|
description: Проблемы, вопросы, ...
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: what-happened
|
||||||
|
attributes:
|
||||||
|
label: Что случилось?
|
||||||
|
description: Краткое описание.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: to-reproduce
|
||||||
|
attributes:
|
||||||
|
label: Воспроизведение
|
||||||
|
description: Код повторяющий кейс
|
||||||
|
render: Python
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
- type: dropdown
|
||||||
|
id: package-version
|
||||||
|
attributes:
|
||||||
|
label: T-Tech Invest Version
|
||||||
|
description: Какая версия библиотеки используется?
|
||||||
|
options:
|
||||||
|
- 0.3.5
|
||||||
|
- 0.3.4
|
||||||
|
- 0.3.3
|
||||||
|
- 0.3.2
|
||||||
|
- 0.3.1
|
||||||
|
- 0.2.0-beta118
|
||||||
|
- 0.2.0-beta117
|
||||||
|
- 0.2.0-beta116
|
||||||
|
- 0.2.0-beta115
|
||||||
|
- 0.2.0-beta114
|
||||||
|
- 0.2.0-beta113
|
||||||
|
- 0.2.0-beta112
|
||||||
|
- 0.2.0-beta111
|
||||||
|
- 0.2.0-beta110
|
||||||
|
- 0.2.0-beta109
|
||||||
|
- 0.2.0-beta108
|
||||||
|
- 0.2.0-beta107
|
||||||
|
- 0.2.0-beta106
|
||||||
|
- 0.2.0-beta105
|
||||||
|
- 0.2.0-beta104
|
||||||
|
- 0.2.0-beta103
|
||||||
|
- 0.2.0-beta101
|
||||||
|
- 0.2.0-beta100
|
||||||
|
- 0.2.0-beta99
|
||||||
|
- 0.2.0-beta98
|
||||||
|
- 0.2.0-beta97
|
||||||
|
- 0.2.0-beta96
|
||||||
|
- 0.2.0-beta95
|
||||||
|
- 0.2.0-beta94
|
||||||
|
- 0.2.0-beta93
|
||||||
|
- 0.2.0-beta92
|
||||||
|
- 0.2.0-beta91
|
||||||
|
- 0.2.0-beta90
|
||||||
|
- 0.2.0-beta89
|
||||||
|
- 0.2.0-beta88
|
||||||
|
- 0.2.0-beta87
|
||||||
|
- 0.2.0-beta86
|
||||||
|
- 0.2.0-beta85
|
||||||
|
- 0.2.0-beta84
|
||||||
|
- 0.2.0-beta83
|
||||||
|
- 0.2.0-beta82
|
||||||
|
- 0.2.0-beta81
|
||||||
|
- 0.2.0-beta80
|
||||||
|
- 0.2.0-beta79
|
||||||
|
- 0.2.0-beta78
|
||||||
|
- 0.2.0-beta77
|
||||||
|
- 0.2.0-beta76
|
||||||
|
- 0.2.0-beta75
|
||||||
|
- 0.2.0-beta74
|
||||||
|
- 0.2.0-beta73
|
||||||
|
- 0.2.0-beta72
|
||||||
|
- 0.2.0-beta71
|
||||||
|
- 0.2.0-beta70
|
||||||
|
- 0.2.0-beta69
|
||||||
|
- 0.2.0-beta68
|
||||||
|
- 0.2.0-beta67
|
||||||
|
- 0.2.0-beta66
|
||||||
|
- 0.2.0-beta65
|
||||||
|
- 0.2.0-beta64
|
||||||
|
- 0.2.0-beta63
|
||||||
|
- 0.2.0-beta62
|
||||||
|
- 0.2.0-beta61
|
||||||
|
- 0.2.0-beta60
|
||||||
|
- 0.2.0-beta59
|
||||||
|
- 0.2.0-beta58
|
||||||
|
- 0.2.0-beta57
|
||||||
|
- 0.2.0-beta56
|
||||||
|
- 0.2.0-beta55
|
||||||
|
- 0.2.0-beta54
|
||||||
|
- 0.2.0-beta53
|
||||||
|
- 0.2.0-beta52
|
||||||
|
- 0.2.0-beta51
|
||||||
|
- 0.2.0-beta50
|
||||||
|
- 0.2.0-beta49
|
||||||
|
- 0.2.0-beta48
|
||||||
|
- 0.2.0-beta47
|
||||||
|
- 0.2.0-beta46
|
||||||
|
- 0.2.0-beta45
|
||||||
|
- 0.2.0-beta44
|
||||||
|
- 0.2.0-beta43
|
||||||
|
- 0.2.0-beta42
|
||||||
|
- 0.2.0-beta41
|
||||||
|
- 0.2.0-beta40
|
||||||
|
- 0.2.0-beta39
|
||||||
|
- 0.2.0-beta38
|
||||||
|
- 0.2.0-beta37
|
||||||
|
- 0.2.0-beta36
|
||||||
|
- 0.2.0-beta35
|
||||||
|
- 0.2.0-beta34
|
||||||
|
- 0.2.0-beta33
|
||||||
|
- 0.2.0-beta32
|
||||||
|
- 0.2.0-beta31
|
||||||
|
- 0.2.0-beta30
|
||||||
|
- 0.2.0-beta29
|
||||||
|
- 0.2.0-beta28
|
||||||
|
- 0.2.0-beta27
|
||||||
|
- Другая
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: dropdown
|
||||||
|
id: python-version
|
||||||
|
attributes:
|
||||||
|
label: Python Version
|
||||||
|
description: Какая версия Python-а используется?
|
||||||
|
options:
|
||||||
|
- '3.11'
|
||||||
|
- '3.10'
|
||||||
|
- '3.9'
|
||||||
|
- '3.8'
|
||||||
|
- Другая
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: dropdown
|
||||||
|
id: os
|
||||||
|
attributes:
|
||||||
|
label: OS
|
||||||
|
description: Ваша операционная система.
|
||||||
|
options:
|
||||||
|
- Windows
|
||||||
|
- Linux
|
||||||
|
- Mac OS
|
||||||
|
- Mac OS (m1)
|
||||||
|
- Другая
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: logs
|
||||||
|
attributes:
|
||||||
|
label: Логи
|
||||||
|
description: Скопируйте и вставьте сюда логи. Не забудьте скрыть чувствительные
|
||||||
|
данные.
|
||||||
|
render: Shell
|
||||||
3
invest-python-master/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
3
invest-python-master/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<!-- Опишите ваши изменения. Это ускорит процесс review. -->
|
||||||
|
|
||||||
|
<!-- Убедитесь, что прочитали файл https://github.com/RussianInvestments/invest-python/blob/main/CONTRIBUTING.md -->
|
||||||
35
invest-python-master/.github/workflows/bumpversion.yml
vendored
Normal file
35
invest-python-master/.github/workflows/bumpversion.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
name: Bump version
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
paths:
|
||||||
|
- "tinkoff/**"
|
||||||
|
- "!tinkoff/invest/__init__.py"
|
||||||
|
- "!tinkoff/invest/constants.py"
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
token: ${{ secrets.BOT_ACCESS_TOKEN }}
|
||||||
|
|
||||||
|
- name: Git user
|
||||||
|
run: |
|
||||||
|
git config --local user.name 'github-actions[bot]'
|
||||||
|
git config --local user.email 'github-actions[bot]@users.noreply.github.com'
|
||||||
|
|
||||||
|
- name: Install python dependencies
|
||||||
|
run: make install-poetry install-bump
|
||||||
|
|
||||||
|
- name: Bump version
|
||||||
|
run: make bump-version v=$(make next-version)
|
||||||
|
|
||||||
|
- name: Push
|
||||||
|
run: |
|
||||||
|
git push
|
||||||
|
git push --tags
|
||||||
49
invest-python-master/.github/workflows/check.yml
vendored
Normal file
49
invest-python-master/.github/workflows/check.yml
vendored
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
name: CI Tests/Lints
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-ubuntu:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.8'
|
||||||
|
|
||||||
|
- name: Install python dependencies
|
||||||
|
run: make install-poetry install
|
||||||
|
|
||||||
|
- name: Run linters
|
||||||
|
run: make lint
|
||||||
|
|
||||||
|
- name: Test docs
|
||||||
|
run: make docs
|
||||||
|
|
||||||
|
- name: Run test
|
||||||
|
run: make test
|
||||||
|
env:
|
||||||
|
INVEST_SANDBOX_TOKEN: ${{ secrets.INVEST_SANDBOX_TOKEN }}
|
||||||
|
INVEST_TOKEN: ${{ secrets.INVEST_TOKEN }}
|
||||||
|
|
||||||
|
build-windows:
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Install make
|
||||||
|
run: choco install make
|
||||||
|
|
||||||
|
- name: Install python dependencies
|
||||||
|
run: make install-poetry install
|
||||||
|
|
||||||
|
- name: Run test
|
||||||
|
run: make test
|
||||||
|
env:
|
||||||
|
INVEST_SANDBOX_TOKEN: ${{ secrets.INVEST_SANDBOX_TOKEN }}
|
||||||
16
invest-python-master/.github/workflows/check_pr_title.yml
vendored
Normal file
16
invest-python-master/.github/workflows/check_pr_title.yml
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
name: Check PR title
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types:
|
||||||
|
- opened
|
||||||
|
- reopened
|
||||||
|
- edited
|
||||||
|
- synchronize
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: aslafy-z/conventional-pr-title-action@v3
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
24
invest-python-master/.github/workflows/github_pages.yml
vendored
Normal file
24
invest-python-master/.github/workflows/github_pages.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
name: Github pages
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Install python dependencies
|
||||||
|
run: make install-poetry install-docs
|
||||||
|
|
||||||
|
- name: Generate docs
|
||||||
|
run: make docs
|
||||||
|
|
||||||
|
- name: Deploy pages
|
||||||
|
uses: peaceiris/actions-gh-pages@v3
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
publish_dir: ./site
|
||||||
25
invest-python-master/.github/workflows/pypi.yml
vendored
Normal file
25
invest-python-master/.github/workflows/pypi.yml
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
name: Publish to PYPI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
release:
|
||||||
|
types:
|
||||||
|
- created
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Install poetry
|
||||||
|
run: make install-poetry
|
||||||
|
|
||||||
|
- name: Publish package to pypi
|
||||||
|
run: make publish
|
||||||
|
env:
|
||||||
|
pypi_username: ${{ secrets.PYPI_USERNAME }}
|
||||||
|
pypi_password: ${{ secrets.PYPI_PASSWORD }}
|
||||||
149
invest-python-master/.gitignore
vendored
Normal file
149
invest-python-master/.gitignore
vendored
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv*
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
tests/pytest.ini
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
||||||
|
|
||||||
|
.env
|
||||||
|
|
||||||
|
docs/README.md
|
||||||
|
docs/CHANGELOG.md
|
||||||
|
docs/CONTRIBUTING.md
|
||||||
|
|
||||||
|
.idea
|
||||||
|
.market_data_cache
|
||||||
|
.DS_Store
|
||||||
7
invest-python-master/BREAKING_CHANGES.md
Normal file
7
invest-python-master/BREAKING_CHANGES.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Breaking changes
|
||||||
|
## 0.3.0
|
||||||
|
- Package naming changed to `t_tech` with all corresponding subpackages
|
||||||
|
## 0.2.0-beta60
|
||||||
|
- `MarketDataCache` was moved to [t_tech/invest/caching/market_data_cache/cache.py](t_tech/invest/caching/market_data_cache/cache.py).
|
||||||
|
- The correct import is now `from t_tech.invest.caching.market_data_cache.cache import MarketDataCache` instead of `from t_tech.invest.services import MarketDataCache`.
|
||||||
|
- Import in [download_all_candles.py](examples/download_all_candles.py) was also corrected.
|
||||||
3
invest-python-master/CHANGELOG.md
Normal file
3
invest-python-master/CHANGELOG.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
You can see [the commits](https://github.com/RussianInvestments/invest-python/commits/main)
|
||||||
143
invest-python-master/CONTRIBUTING.md
Normal file
143
invest-python-master/CONTRIBUTING.md
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
Спасибо за участие в проекте T-Invest!
|
||||||
|
|
||||||
|
## Быстрый старт
|
||||||
|
|
||||||
|
1. Сделайте [fork](https://opensource.tbank.ru/invest/invest-python/-/forks/new) проекта
|
||||||
|
2. Склонируйте репозиторий на свой локальный компьютер
|
||||||
|
```bash
|
||||||
|
git clone https://opensource.tbank.ru/<username>/invest-python.git
|
||||||
|
```
|
||||||
|
> Вы должны использовать свой username вместо `username`
|
||||||
|
3. Создайте новую ветку для ваших изменений
|
||||||
|
```bash
|
||||||
|
git checkout -b branch_name
|
||||||
|
```
|
||||||
|
4. Добавьте изменения и выполните команды на локальной машине (см. ниже)
|
||||||
|
1. Установите зависимости
|
||||||
|
2. Проверьте свой код с помощью тестов и линтеров
|
||||||
|
5. Создайте коммит своих изменений. Формат описан ниже
|
||||||
|
```bash
|
||||||
|
git add .
|
||||||
|
git commit -m "feat: add new feature"
|
||||||
|
```
|
||||||
|
6. Отправьте свои изменения на github
|
||||||
|
```bash
|
||||||
|
git push
|
||||||
|
```
|
||||||
|
7. Создайте Pull Request в этот репозиторий
|
||||||
|
|
||||||
|
## Commit Message Format
|
||||||
|
|
||||||
|
Мы придерживаемся соглашений [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) для наименование коммитов.
|
||||||
|
|
||||||
|
> A specification for adding human and machine readable meaning to commit messages.
|
||||||
|
|
||||||
|
Body и Footer можно указать по желанию.
|
||||||
|
|
||||||
|
### Commit Message Header
|
||||||
|
|
||||||
|
```
|
||||||
|
<type>(<scope>): <short summary>
|
||||||
|
│ │ │
|
||||||
|
│ │ └─⫸ Summary in present tense. Not capitalized. No period at the end.
|
||||||
|
│ │
|
||||||
|
│ └─⫸ Commit Scope: grpc, async, mypy, schemas, sandbox
|
||||||
|
│
|
||||||
|
└─⫸ Commit Type: feat|fix|build|ci|docs|perf|refactor|test|chore
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Type
|
||||||
|
|
||||||
|
| feat | Features | A new feature |
|
||||||
|
|----------|--------------------------|--------------------------------------------------------------------------------------------------------|
|
||||||
|
| fix | Bug Fixes | A bug fix |
|
||||||
|
| docs | Documentation | Documentation only changes |
|
||||||
|
| style | Styles | Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) |
|
||||||
|
| refactor | Code Refactoring | A code change that neither fixes a bug nor adds a feature |
|
||||||
|
| perf | Performance Improvements | A code change that improves performance |
|
||||||
|
| test | Tests | Adding missing tests or correcting existing tests |
|
||||||
|
| build | Builds | Changes that affect the build system or external dependencies (example scopes: mypy, pip, pytest) |
|
||||||
|
| ci | Continuous Integrations | Changes to our CI configuration files and scripts (example scopes: Github Actions) |
|
||||||
|
| chore | Chores | Other changes that don't modify src or test files |
|
||||||
|
| revert | Reverts | Reverts a previous commit |
|
||||||
|
|
||||||
|
## Выполнение команд на локальной машине
|
||||||
|
|
||||||
|
Для работы с проектом рекомендуем использовать [poetry](https://pypi.org/project/poetry/).
|
||||||
|
|
||||||
|
Также рекомендуем использовать таск раннер make. Все команды описаны в Makefile. Вы можете их скопировать и запускать напрямую.
|
||||||
|
|
||||||
|
## Установка зависимостей
|
||||||
|
|
||||||
|
```
|
||||||
|
make install-poetry
|
||||||
|
make install
|
||||||
|
```
|
||||||
|
|
||||||
|
### Виртуальное окружение
|
||||||
|
|
||||||
|
По умолчанию, poetry создает виртуальное окружение в директории `~/.cache/pypoetry/virtualenvs/`. Чтобы создавать виртуальное окружение в директории проекта, выполните команду:
|
||||||
|
|
||||||
|
```
|
||||||
|
poetry config virtualenvs.in-project true
|
||||||
|
```
|
||||||
|
|
||||||
|
Вы можете сами создать виртуальное окружение в директории проекта:
|
||||||
|
|
||||||
|
```
|
||||||
|
python -m venv .venv
|
||||||
|
```
|
||||||
|
|
||||||
|
poetry будет использовать его.
|
||||||
|
|
||||||
|
### Запуск тестов
|
||||||
|
|
||||||
|
```
|
||||||
|
make test
|
||||||
|
```
|
||||||
|
|
||||||
|
### Запуск линтеров
|
||||||
|
|
||||||
|
```
|
||||||
|
make lint
|
||||||
|
```
|
||||||
|
|
||||||
|
### Запуск автоформатирования
|
||||||
|
|
||||||
|
```
|
||||||
|
make format
|
||||||
|
```
|
||||||
|
|
||||||
|
### Загрузка proto файлов
|
||||||
|
|
||||||
|
```
|
||||||
|
make download-protos
|
||||||
|
```
|
||||||
|
|
||||||
|
По дефолту загружает из ветки `main`.
|
||||||
|
|
||||||
|
### Генерация клиента
|
||||||
|
|
||||||
|
```
|
||||||
|
make gen-grpc
|
||||||
|
```
|
||||||
|
|
||||||
|
Затем, добавить изменения в модули:
|
||||||
|
- t_tech/invest/\_\_init__.py
|
||||||
|
- t_tech/invest/async_services.py
|
||||||
|
- t_tech/invest/schemas.py
|
||||||
|
- t_tech/invest/services.py
|
||||||
|
|
||||||
|
### Загрузка proto файлов и генерация клиента
|
||||||
|
|
||||||
|
Можно упростить все до одной команды.
|
||||||
|
|
||||||
|
```
|
||||||
|
make gen-client
|
||||||
|
```
|
||||||
|
|
||||||
|
### Release новой версии
|
||||||
|
|
||||||
|
Релиз новой версии происходит автоматически после слияния изменений в main ветку.
|
||||||
202
invest-python-master/LICENSE
Normal file
202
invest-python-master/LICENSE
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright 2023 Tinkoff
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
106
invest-python-master/Makefile
Normal file
106
invest-python-master/Makefile
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
PYTHONPATH = PYTHONPATH=./
|
||||||
|
POETRY_RUN = poetry run
|
||||||
|
|
||||||
|
PROTO_DIR = protos/t_tech/invest/grpc
|
||||||
|
PACKAGE_PROTO_DIR = t_tech/invest/grpc
|
||||||
|
OUT = .
|
||||||
|
PROTOS = protos
|
||||||
|
|
||||||
|
TEST = $(POETRY_RUN) pytest $(args)
|
||||||
|
MAIN_CODE = t_tech examples scripts
|
||||||
|
CODE = tests $(MAIN_CODE)
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test:
|
||||||
|
$(TEST) --cov
|
||||||
|
|
||||||
|
.PHONY: test-fast
|
||||||
|
test-fast:
|
||||||
|
$(TEST)
|
||||||
|
|
||||||
|
.PHONY: test-sandbox
|
||||||
|
test-sandbox:
|
||||||
|
$(TEST) --test-sandbox --cov
|
||||||
|
|
||||||
|
.PHONY: lint
|
||||||
|
lint:
|
||||||
|
$(POETRY_RUN) ruff $(CODE)
|
||||||
|
$(POETRY_RUN) black --check $(CODE)
|
||||||
|
$(POETRY_RUN) pytest --dead-fixtures --dup-fixtures
|
||||||
|
$(POETRY_RUN) mypy $(MAIN_CODE)
|
||||||
|
$(POETRY_RUN) poetry check
|
||||||
|
|
||||||
|
.PHONY: format
|
||||||
|
format:
|
||||||
|
$(POETRY_RUN) isort $(CODE)
|
||||||
|
$(POETRY_RUN) black $(CODE)
|
||||||
|
$(POETRY_RUN) ruff --fix $(CODE)
|
||||||
|
|
||||||
|
.PHONY: check
|
||||||
|
check: lint test
|
||||||
|
|
||||||
|
.PHONY: docs
|
||||||
|
docs:
|
||||||
|
mkdir -p ./docs
|
||||||
|
cp README.md ./docs/
|
||||||
|
cp CHANGELOG.md ./docs/
|
||||||
|
cp CONTRIBUTING.md ./docs/
|
||||||
|
$(POETRY_RUN) mkdocs build -s -v
|
||||||
|
|
||||||
|
.PHONY: docs-serve
|
||||||
|
docs-serve:
|
||||||
|
$(POETRY_RUN) mkdocs serve
|
||||||
|
|
||||||
|
.PHONY: next-version
|
||||||
|
next-version:
|
||||||
|
@$(POETRY_RUN) python -m scripts.version
|
||||||
|
|
||||||
|
.PHONY: bump-version
|
||||||
|
bump-version:
|
||||||
|
poetry version $(v)
|
||||||
|
$(POETRY_RUN) python -m scripts.update_package_version $(v)
|
||||||
|
$(POETRY_RUN) python -m scripts.update_issue_templates $(v)
|
||||||
|
git add . && git commit -m "chore(release): bump version to $(v)"
|
||||||
|
git tag -a $(v) -m ""
|
||||||
|
|
||||||
|
.PHONY: install-poetry
|
||||||
|
install-poetry:
|
||||||
|
pip install poetry==2.3.2
|
||||||
|
|
||||||
|
.PHONY: install-docs
|
||||||
|
install-docs:
|
||||||
|
poetry install --only docs
|
||||||
|
|
||||||
|
.PHONY: install-bump
|
||||||
|
install-bump:
|
||||||
|
poetry install --only bump
|
||||||
|
|
||||||
|
.PHONY: install
|
||||||
|
install:
|
||||||
|
poetry install -E all
|
||||||
|
|
||||||
|
.PHONY: publish
|
||||||
|
publish:
|
||||||
|
@poetry publish --build --no-interaction --username=$(pypi_username) --password=$(pypi_password)
|
||||||
|
|
||||||
|
.PHONY: publish-opensource
|
||||||
|
publish-opensource:
|
||||||
|
@poetry publish --build --no-interaction -r opensource --username=$(pypi_username) --password=$(pypi_password)
|
||||||
|
|
||||||
|
.PHONY: config-opensource
|
||||||
|
config-opensource:
|
||||||
|
@poetry config repositories.opensource https://opensource.tbank.ru/api/v4/projects/238/packages/pypi
|
||||||
|
|
||||||
|
.PHONY: download-protos
|
||||||
|
download-protos:
|
||||||
|
$(POETRY_RUN) python -m scripts.download_protos
|
||||||
|
|
||||||
|
.PHONY: gen-grpc
|
||||||
|
gen-grpc:
|
||||||
|
rm -r ${PACKAGE_PROTO_DIR}
|
||||||
|
$(POETRY_RUN) python -m grpc_tools.protoc -I${PROTOS} --python_out=${OUT} --mypy_out=${OUT} --grpc_python_out=${OUT} ${PROTO_DIR}/google/api/*.proto
|
||||||
|
$(POETRY_RUN) python -m grpc_tools.protoc -I${PROTOS} --python_out=${OUT} --mypy_out=${OUT} --grpc_python_out=${OUT} ${PROTO_DIR}/*.proto
|
||||||
|
touch ${PACKAGE_PROTO_DIR}/__init__.py
|
||||||
|
|
||||||
|
.PHONY: gen-client
|
||||||
|
gen-client: download-protos gen-grpc
|
||||||
84
invest-python-master/README.md
Normal file
84
invest-python-master/README.md
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
# T-Invest
|
||||||
|
|
||||||
|
[](https://opensource.tbank.ru/invest/invest-python/-/packages)
|
||||||
|
[](https://www.python.org/downloads/)
|
||||||
|
[](https://opensource.tbank.ru/invest/invest-python/-/blob/master/LICENSE)
|
||||||
|
|
||||||
|
[//]: # ()
|
||||||
|
|
||||||
|
Данный репозиторий предоставляет клиент для взаимодействия с торговой платформой
|
||||||
|
[Т-Инвестиции](https://www.tbank.ru/invest/) на языке Python.
|
||||||
|
|
||||||
|
Проект является продуктом независимой разработки и не связан с какими-либо компаниями. Библиотека распространяется
|
||||||
|
свободно и не является коммерческим продуктом или официальным выпуском какого-либо стороннего разработчика. Все
|
||||||
|
исходные материалы, архитектура и реализация созданы самостоятельно.
|
||||||
|
|
||||||
|
The project is the result of independent development and is not affiliated with any companies. The library is
|
||||||
|
distributed freely and is not a commercial product or official release of any third-party vendor. All source materials,
|
||||||
|
architecture, and implementation were created independently.
|
||||||
|
|
||||||
|
|
||||||
|
- [Документация](https://opensource.tbank.ru/invest/invest-python/-/blob/master/README.md?ref_type=heads)
|
||||||
|
- [Документация по Invest API](https://developer.tbank.ru/invest/intro/intro)
|
||||||
|
|
||||||
|
## Начало работы
|
||||||
|
|
||||||
|
<!-- terminal -->
|
||||||
|
|
||||||
|
```
|
||||||
|
$ pip install t-tech-investments --index-url https://opensource.tbank.ru/api/v4/projects/238/packages/pypi/simple
|
||||||
|
```
|
||||||
|
|
||||||
|
## Возможности
|
||||||
|
|
||||||
|
- ☑ Синхронный и асинхронный GRPC клиент
|
||||||
|
- ☑ Возможность отменить все заявки
|
||||||
|
- ☑ Выгрузка истории котировок "от" и "до"
|
||||||
|
- ☑ Кеширование данных
|
||||||
|
- ☑ Торговая стратегия
|
||||||
|
|
||||||
|
## Как пользоваться
|
||||||
|
|
||||||
|
### Получить список аккаунтов
|
||||||
|
|
||||||
|
```python
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
TOKEN = 'token'
|
||||||
|
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
print(client.users.get_accounts())
|
||||||
|
```
|
||||||
|
|
||||||
|
### Переопределить target
|
||||||
|
|
||||||
|
В T-Invest API есть два контура - "боевой", предназначенный для исполнения ордеров на бирже и "песочница",
|
||||||
|
предназначенный для тестирования API и торговых гипотез, заявки с которого не выводятся на биржу,
|
||||||
|
а исполняются в эмуляторе.
|
||||||
|
|
||||||
|
Переключение между контурами реализовано через target, INVEST_GRPC_API - "боевой", INVEST_GRPC_API_SANDBOX - "песочница"
|
||||||
|
|
||||||
|
```python
|
||||||
|
from t_tech.invest import Client
|
||||||
|
from t_tech.invest.constants import INVEST_GRPC_API
|
||||||
|
|
||||||
|
TOKEN = 'token'
|
||||||
|
|
||||||
|
with Client(TOKEN, target=INVEST_GRPC_API) as client:
|
||||||
|
print(client.users.get_accounts())
|
||||||
|
```
|
||||||
|
|
||||||
|
> :warning: **Не публикуйте токены в общедоступные репозитории**
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
Остальные примеры доступны в [examples](https://opensource.tbank.ru/invest/invest-python/-/tree/master/examples).
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
Для тех, кто хочет внести свои изменения в проект.
|
||||||
|
|
||||||
|
- [CONTRIBUTING](https://opensource.tbank.ru/invest/invest-python/-/blob/master/CONTRIBUTING.md)
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Лицензия [The Apache License](https://opensource.tbank.ru/invest/invest-python/-/blob/master/LICENSE).
|
||||||
18
invest-python-master/conftest.py
Normal file
18
invest-python-master/conftest.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_addoption(parser):
|
||||||
|
parser.addoption(
|
||||||
|
"--test-sandbox",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
help="Run sandbox tests",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_collection_modifyitems(config, items):
|
||||||
|
if not config.getoption("--test-sandbox"):
|
||||||
|
skipper = pytest.mark.skip(reason="Only run when --test-sandbox is given")
|
||||||
|
for item in items:
|
||||||
|
if "test_sandbox" in item.keywords:
|
||||||
|
item.add_marker(skipper)
|
||||||
4
invest-python-master/docs/api/clients.md
Normal file
4
invest-python-master/docs/api/clients.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
# Clients
|
||||||
|
|
||||||
|
::: t_tech.invest.clients
|
||||||
122
invest-python-master/docs/examples.md
Normal file
122
invest-python-master/docs/examples.md
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
Больше примеров доступно [здесь](https://github.com/RussianInvestments/invest-python/tree/main/examples).
|
||||||
|
|
||||||
|
## Получение и вывод в консоль свечей с часовым интервалом за год
|
||||||
|
[examples/all_candles.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/all_candles.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/all_candles.py" %}
|
||||||
|
~~~
|
||||||
|
## Асинхронная функция получения и вывода в консоль свечей с часовым интервалом за год
|
||||||
|
[examples/async_all_candles.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/async_all_candles.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/async_all_candles.py" %}
|
||||||
|
~~~
|
||||||
|
## Асинхронная функция получения и вывода счетов пользователя
|
||||||
|
[examples/async_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/async_client.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/async_client.py" %}
|
||||||
|
~~~
|
||||||
|
## Асинхронная функция получения и вывода минутных свечей
|
||||||
|
[examples/async_retrying_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/async_retrying_client.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/async_retrying_client.py" %}
|
||||||
|
~~~
|
||||||
|
## Подписка на стрим котировок по минутным свечам и вывод получаемых свечей в консоль
|
||||||
|
[examples/async_stream_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/async_stream_client.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/async_stream_client.py" %}
|
||||||
|
~~~
|
||||||
|
## Отмена всех выставленных поручений
|
||||||
|
[examples/cancel_orders.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/cancel_orders.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/cancel_orders.py" %}
|
||||||
|
~~~
|
||||||
|
## Функция получения и вывода счетов клиента
|
||||||
|
[examples/client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/client.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/client.py" %}
|
||||||
|
~~~
|
||||||
|
## Загрузка и вывод всех минутных свечей по интрументу
|
||||||
|
[examples/download_all_candles.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/download_all_candles.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/download_all_candles.py" %}
|
||||||
|
~~~
|
||||||
|
## Асинхронная подписка на стрим минутных свечей
|
||||||
|
[examples/easy_async_stream_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/easy_async_stream_client.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/easy_async_stream_client.py" %}
|
||||||
|
~~~
|
||||||
|
## Простая подписка на стрим минутных свечей
|
||||||
|
[examples/easy_stream_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/easy_stream_client.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/easy_stream_client.py" %}
|
||||||
|
~~~
|
||||||
|
## Получение списка операций и их постраничный вывод
|
||||||
|
[examples/get_operations_by_cursor.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/get_operations_by_cursor.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/get_operations_by_cursor.py" %}
|
||||||
|
~~~
|
||||||
|
## Функция кэширования инструментов
|
||||||
|
[examples/instrument_cache.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/instrument_cache.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/instrument_cache.py" %}
|
||||||
|
~~~
|
||||||
|
## Функция получения списка инструментов подходящих под строку query
|
||||||
|
[examples/instruments/instruments.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/instruments/instruments.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/instruments/instruments.py" %}
|
||||||
|
~~~
|
||||||
|
## Функция логгирования ошибок
|
||||||
|
[examples/logger.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/logger.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/logger.py" %}
|
||||||
|
~~~
|
||||||
|
## Подписка на стрим портфолио и вывод информации
|
||||||
|
[examples/porfolio_stream_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/porfolio_stream_client.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/porfolio_stream_client.py" %}
|
||||||
|
~~~
|
||||||
|
## Подписка на стрим позиций и вывод информации
|
||||||
|
[examples/positions_stream.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/positions_stream.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/positions_stream.py" %}
|
||||||
|
~~~
|
||||||
|
## Функция получения и вывода минутных свечей
|
||||||
|
[examples/retrying_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/retrying_client.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/retrying_client.py" %}
|
||||||
|
~~~
|
||||||
|
## Получение и вывод информации об аккаунте пользователя в песочнице
|
||||||
|
[examples/sandbox_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/sandbox_client.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/sandbox_client.py" %}
|
||||||
|
~~~
|
||||||
|
## Подписка на стрим минутных свечей и их вывод
|
||||||
|
[examples/stream_client.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/stream_client.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/stream_client.py" %}
|
||||||
|
~~~
|
||||||
|
## Создание тэйк-профит стоп ордера
|
||||||
|
[examples/wiseplat_create_take_profit_stop_order.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/wiseplat_create_take_profit_stop_order.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/wiseplat_create_take_profit_stop_order.py" %}
|
||||||
|
~~~
|
||||||
|
## Отмена всех выставленных стоп ордеров
|
||||||
|
[examples/wiseplat_cancel_all_stop_orders.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/wiseplat_cancel_all_stop_orders.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/wiseplat_cancel_all_stop_orders.py" %}
|
||||||
|
~~~
|
||||||
|
## Получение figi для тикера
|
||||||
|
[examples/wiseplat_get_figi_for_ticker.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/wiseplat_get_figi_for_ticker.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/wiseplat_get_figi_for_ticker.py" %}
|
||||||
|
~~~
|
||||||
|
## Получение / установка баланса для песочницы. Получение / закрытие всех песочниц. Создание новой песочницы.
|
||||||
|
[examples/wiseplat_set_get_sandbox_balance.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/wiseplat_set_get_sandbox_balance.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/wiseplat_set_get_sandbox_balance.py" %}
|
||||||
|
~~~
|
||||||
|
## Пример live стратегии для нескольких тикеров. Вывод OHLCV для каждой сформировавшейся свечи.
|
||||||
|
[examples/wiseplat_live_strategy_print_ohlcv.py](https://github.com/RussianInvestments/invest-python/blob/main/examples/wiseplat_live_strategy_print_ohlcv.py)
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/wiseplat_live_strategy_print_ohlcv.py" %}
|
||||||
|
~~~
|
||||||
16
invest-python-master/docs/robots.md
Normal file
16
invest-python-master/docs/robots.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
## Примеры готовых роботов
|
||||||
|
|
||||||
|
| Ссылка на репозиторий | Описание |
|
||||||
|
|------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| [tromario/tinkoff-invest-volume-analysis-robot](https://github.com/tromario/tinkoff-invest-volume-analysis-robot) | Проектом был реализован один из методов работы с профилем рынка - реакция на максимальный горизонтальный объем внутри дня за выбранный период.Основной объем работы был заложен в математический аппарат. Работа имеет визуализацию алгоритма. |
|
||||||
|
| [qwertyo1/tinkoff-trading-bot](https://github.com/qwertyo1/tinkoff-trading-bot) | Проектом реализована простая интервальная стратегия. Несложный код поможет начинающим разработчикам быстро разобраться, запустить, проверить и доработать торговую стратегию под свои цели. Простое ведение статистики через sqllite. |
|
||||||
|
| [karpp/investRobot](https://github.com/karpp/investRobot) | investRobot - это робот для алгоритмической торговли на бирже Тинькофф Инвестиций посредством Tinkoff Invest API. В качестве демонстрации представлена одна торговая стратегия, основанная на индикаторе двух скользящих средних. |
|
||||||
|
| [EIDiamond/invest-bot](https://github.com/EIDiamond/invest-bot) | Робот интрадей торговли на Московской бирже с возможность информирования о сделках и результатах торговли в Telegram чат.Удобное решение опционального включения\выключения информирования в Телеграм. Без подключения Телеграм чата все события и результаты пишутся в лог файл. |
|
||||||
|
|
||||||
|
## Готовые стратегии
|
||||||
|
|
||||||
|
Функция создает дополнительный столбец с действиями ("ma200_support_action"), куда записываются сигналы на шорт или лонг по условиям.
|
||||||
|
Затем данные агрегируются и выводятся в виде списка акций, по которым пришли сигналы, в порядке убывания даты сигнала.
|
||||||
|
~~~python
|
||||||
|
{% include "../examples/strategies/moving_average.py" %}
|
||||||
|
~~~
|
||||||
13
invest-python-master/examples/README.md
Normal file
13
invest-python-master/examples/README.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
Cначала нужно добавить токен в переменную окружения.
|
||||||
|
|
||||||
|
<!-- termynal -->
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ export INVEST_TOKEN=YOUR_TOKEN
|
||||||
|
```
|
||||||
|
|
||||||
|
А потом можно запускать примеры
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ python examples/client.py
|
||||||
|
```
|
||||||
0
invest-python-master/examples/__init__.py
Normal file
0
invest-python-master/examples/__init__.py
Normal file
25
invest-python-master/examples/all_candles.py
Normal file
25
invest-python-master/examples/all_candles.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import os
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from t_tech.invest import CandleInterval, Client
|
||||||
|
from t_tech.invest.schemas import CandleSource
|
||||||
|
from t_tech.invest.utils import now
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
for candle in client.get_all_candles(
|
||||||
|
instrument_id="BBG004730N88",
|
||||||
|
from_=now() - timedelta(days=365),
|
||||||
|
interval=CandleInterval.CANDLE_INTERVAL_HOUR,
|
||||||
|
candle_source_type=CandleSource.CANDLE_SOURCE_UNSPECIFIED,
|
||||||
|
):
|
||||||
|
print(candle)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
24
invest-python-master/examples/async_all_candles.py
Normal file
24
invest-python-master/examples/async_all_candles.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient, CandleInterval
|
||||||
|
from t_tech.invest.schemas import CandleSource
|
||||||
|
from t_tech.invest.utils import now
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
async for candle in client.get_all_candles(
|
||||||
|
instrument_id="BBG004730N88",
|
||||||
|
from_=now() - timedelta(days=365),
|
||||||
|
interval=CandleInterval.CANDLE_INTERVAL_HOUR,
|
||||||
|
candle_source_type=CandleSource.CANDLE_SOURCE_EXCHANGE,
|
||||||
|
):
|
||||||
|
print(candle)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
15
invest-python-master/examples/async_client.py
Normal file
15
invest-python-master/examples/async_client.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
print(await client.users.get_accounts())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient, CandleInterval
|
||||||
|
from t_tech.invest.utils import now
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
candles = await client.market_data.get_candles(
|
||||||
|
instrument_id="BBG004730N88",
|
||||||
|
to=now(),
|
||||||
|
limit=3,
|
||||||
|
interval=CandleInterval.CANDLE_INTERVAL_HOUR,
|
||||||
|
)
|
||||||
|
for candle in candles.candles:
|
||||||
|
print(candle)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
38
invest-python-master/examples/async_get_insider_deals.py
Normal file
38
invest-python-master/examples/async_get_insider_deals.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
"""Example - How to get list of insider deals.
|
||||||
|
Request data in loop with batches of 10 records.
|
||||||
|
"""
|
||||||
|
import asyncio
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import GetInsiderDealsRequest
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
deals = []
|
||||||
|
|
||||||
|
next_cursor = None
|
||||||
|
while True:
|
||||||
|
response = await client.instruments.get_insider_deals(
|
||||||
|
request=GetInsiderDealsRequest(
|
||||||
|
instrument_id="BBG004730N88", limit=10, next_cursor=next_cursor
|
||||||
|
)
|
||||||
|
)
|
||||||
|
deals.extend(response.insider_deals)
|
||||||
|
if not next_cursor:
|
||||||
|
break
|
||||||
|
next_cursor = response.next_cursor
|
||||||
|
print("Insider deals:")
|
||||||
|
for deal in deals:
|
||||||
|
print(deal)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
20
invest-python-master/examples/async_get_last_prices.py
Normal file
20
invest-python-master/examples/async_get_last_prices.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient, InstrumentStatus
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
print(
|
||||||
|
await client.market_data.get_last_prices(
|
||||||
|
figi=["BBG004730ZJ9"],
|
||||||
|
instrument_status=InstrumentStatus.INSTRUMENT_STATUS_ALL,
|
||||||
|
)
|
||||||
|
) # pylint:disable=line-too-long
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
28
invest-python-master/examples/async_get_market_values.py
Normal file
28
invest-python-master/examples/async_get_market_values.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import GetMarketValuesRequest, MarketValueType
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
market_values = await client.market_data.get_market_values(
|
||||||
|
request=GetMarketValuesRequest(
|
||||||
|
instrument_id=["BBG004730N88", "64c0da45-4c90-41d4-b053-0c66c7a8ddcd"],
|
||||||
|
values=[
|
||||||
|
MarketValueType.INSTRUMENT_VALUE_LAST_PRICE,
|
||||||
|
MarketValueType.INSTRUMENT_VALUE_CLOSE_PRICE,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
for instrument in market_values.instruments:
|
||||||
|
print(instrument.instrument_uid)
|
||||||
|
for value in instrument.values:
|
||||||
|
print(value)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
39
invest-python-master/examples/async_get_orders.py
Normal file
39
invest-python-master/examples/async_get_orders.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
"""Example - How to get list of orders for 1 last hour (maximum requesting period)."""
|
||||||
|
import asyncio
|
||||||
|
import datetime
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import OrderExecutionReportStatus
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
response = await client.users.get_accounts()
|
||||||
|
account, *_ = response.accounts
|
||||||
|
account_id = account.id
|
||||||
|
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
orders = await client.orders.get_orders(
|
||||||
|
account_id=account_id,
|
||||||
|
from_=now - datetime.timedelta(hours=1),
|
||||||
|
to=now,
|
||||||
|
# filter only executed or partially executed orders
|
||||||
|
execution_status=[
|
||||||
|
OrderExecutionReportStatus.EXECUTION_REPORT_STATUS_FILL,
|
||||||
|
OrderExecutionReportStatus.EXECUTION_REPORT_STATUS_PARTIALLYFILL,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
print("Orders list:")
|
||||||
|
for order in orders.orders:
|
||||||
|
print(order)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
22
invest-python-master/examples/async_get_risk_rates.py
Normal file
22
invest-python-master/examples/async_get_risk_rates.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import RiskRatesRequest
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
request = RiskRatesRequest()
|
||||||
|
request.instrument_id = ["BBG001M2SC01", "BBG004730N88"]
|
||||||
|
r = await client.instruments.get_risk_rates(request=request)
|
||||||
|
for i in r.instrument_risk_rates:
|
||||||
|
print(i.instrument_uid)
|
||||||
|
print(i.short_risk_rate)
|
||||||
|
print(i.long_risk_rate)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
22
invest-python-master/examples/async_get_sandbox_max_lots.py
Normal file
22
invest-python-master/examples/async_get_sandbox_max_lots.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import GetMaxLotsRequest
|
||||||
|
from t_tech.invest.sandbox.async_client import AsyncSandboxClient
|
||||||
|
from t_tech.invest.sandbox.client import SandboxClient
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_SANDBOX_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncSandboxClient(TOKEN) as client:
|
||||||
|
account_id = (await client.users.get_accounts()).accounts[0].id
|
||||||
|
request = GetMaxLotsRequest(
|
||||||
|
account_id=account_id,
|
||||||
|
instrument_id="BBG004730N88",
|
||||||
|
)
|
||||||
|
print(await client.sandbox.get_sandbox_max_lots(request=request))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
26
invest-python-master/examples/async_get_signals.py
Normal file
26
invest-python-master/examples/async_get_signals.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
"""Example - How to get Signals"""
|
||||||
|
import asyncio
|
||||||
|
import datetime
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import GetSignalsRequest, SignalState
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
request = GetSignalsRequest()
|
||||||
|
request.instrument_uid = "e6123145-9665-43e0-8413-cd61b8aa9b13" # Сбербанк
|
||||||
|
request.active = SignalState.SIGNAL_STATE_ALL # все сигналы
|
||||||
|
request.from_ = datetime.datetime.now() - datetime.timedelta(
|
||||||
|
weeks=4
|
||||||
|
) # сигналы, созданные не больше чем 4 недели назад
|
||||||
|
r = await client.signals.get_signals(request=request)
|
||||||
|
for signal in r.signals:
|
||||||
|
print(signal)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
19
invest-python-master/examples/async_get_strategies.py
Normal file
19
invest-python-master/examples/async_get_strategies.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
"""Example - How to get all strategies"""
|
||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import GetStrategiesRequest
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
r = await client.signals.get_strategies(request=GetStrategiesRequest())
|
||||||
|
for strategy in r.strategies:
|
||||||
|
print(strategy)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
41
invest-python-master/examples/async_get_tech_analysis.py
Normal file
41
invest-python-master/examples/async_get_tech_analysis.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
from datetime import timedelta
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import (
|
||||||
|
Deviation,
|
||||||
|
GetTechAnalysisRequest,
|
||||||
|
IndicatorInterval,
|
||||||
|
IndicatorType,
|
||||||
|
Smoothing,
|
||||||
|
TypeOfPrice,
|
||||||
|
)
|
||||||
|
from t_tech.invest.utils import decimal_to_quotation, now
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
request = GetTechAnalysisRequest(
|
||||||
|
indicator_type=IndicatorType.INDICATOR_TYPE_RSI,
|
||||||
|
instrument_uid="6542a064-6633-44ba-902f-710c97507522",
|
||||||
|
from_=now() - timedelta(days=7),
|
||||||
|
to=now(),
|
||||||
|
interval=IndicatorInterval.INDICATOR_INTERVAL_4_HOUR,
|
||||||
|
type_of_price=TypeOfPrice.TYPE_OF_PRICE_AVG,
|
||||||
|
length=42,
|
||||||
|
deviation=Deviation(
|
||||||
|
deviation_multiplier=decimal_to_quotation(Decimal(1.0)),
|
||||||
|
),
|
||||||
|
smoothing=Smoothing(fast_length=13, slow_length=7, signal_smoothing=3),
|
||||||
|
)
|
||||||
|
response = await client.market_data.get_tech_analysis(request=request)
|
||||||
|
for indicator in response.technical_indicators:
|
||||||
|
print(indicator.signal)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
18
invest-python-master/examples/async_get_trading_statuses.py
Normal file
18
invest-python-master/examples/async_get_trading_statuses.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
|
||||||
|
token = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(token) as client:
|
||||||
|
statuses = await client.market_data.get_trading_statuses(
|
||||||
|
instrument_ids=["BBG004730N88"]
|
||||||
|
)
|
||||||
|
print(statuses)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
19
invest-python-master/examples/async_indicatives.py
Normal file
19
invest-python-master/examples/async_indicatives.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import IndicativesRequest
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
request = IndicativesRequest()
|
||||||
|
indicatives = await client.instruments.indicatives(request=request)
|
||||||
|
for instrument in indicatives.instruments:
|
||||||
|
print(instrument.name)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
55
invest-python-master/examples/async_instrument_favorites.py
Normal file
55
invest-python-master/examples/async_instrument_favorites.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import (
|
||||||
|
CreateFavoriteGroupRequest,
|
||||||
|
DeleteFavoriteGroupRequest,
|
||||||
|
EditFavoritesActionType as At,
|
||||||
|
EditFavoritesRequestInstrument,
|
||||||
|
GetFavoriteGroupsRequest,
|
||||||
|
)
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
r = await client.instruments.get_favorites()
|
||||||
|
|
||||||
|
print("Список избранных инструментов:")
|
||||||
|
for i in r.favorite_instruments:
|
||||||
|
print(f"{i.ticker} - {i.name}")
|
||||||
|
|
||||||
|
request = CreateFavoriteGroupRequest()
|
||||||
|
request.group_name = "My test favorite group"
|
||||||
|
request.group_color = "aa0000" # red color
|
||||||
|
r = await client.instruments.create_favorite_group(request=request)
|
||||||
|
group_id = r.group_id
|
||||||
|
print(f"Создана новая группа избранного с ИД: {group_id}")
|
||||||
|
|
||||||
|
await client.instruments.edit_favorites(
|
||||||
|
instruments=[EditFavoritesRequestInstrument(instrument_id="BBG001M2SC01")],
|
||||||
|
action_type=At.EDIT_FAVORITES_ACTION_TYPE_ADD,
|
||||||
|
group_id=group_id,
|
||||||
|
)
|
||||||
|
|
||||||
|
request = GetFavoriteGroupsRequest()
|
||||||
|
request.instrument_id = ["BBG001M2SC01"]
|
||||||
|
r = await client.instruments.get_favorite_groups(request=request)
|
||||||
|
print(f"Список групп избранного:")
|
||||||
|
for i in r.groups:
|
||||||
|
print(
|
||||||
|
f"{i.group_id} - {i.group_name}. Количество элементов: {i.size}. "
|
||||||
|
f"Содержит выбранный инструмент {request.instrument_id[0]}: "
|
||||||
|
f"{i.contains_instrument} "
|
||||||
|
)
|
||||||
|
|
||||||
|
request = DeleteFavoriteGroupRequest()
|
||||||
|
request.group_id = group_id
|
||||||
|
await client.instruments.delete_favorite_group(request=request)
|
||||||
|
print(f"Удалена группа избранного с ИД: {group_id}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
27
invest-python-master/examples/async_operations_stream.py
Normal file
27
invest-python-master/examples/async_operations_stream.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import OperationsStreamRequest, PingDelaySettings
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
accounts = await client.users.get_accounts()
|
||||||
|
accounts = [i.id for i in accounts.accounts]
|
||||||
|
print(f"Subscribe for operations on accounts: {accounts}")
|
||||||
|
async for operation in client.operations_stream.operations_stream(
|
||||||
|
OperationsStreamRequest(
|
||||||
|
accounts=accounts,
|
||||||
|
ping_settings=PingDelaySettings(
|
||||||
|
ping_delay_ms=10_000,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
):
|
||||||
|
print(operation)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
19
invest-python-master/examples/async_order_state_stream.py
Normal file
19
invest-python-master/examples/async_order_state_stream.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import OrderStateStreamRequest
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
request = OrderStateStreamRequest()
|
||||||
|
stream = client.orders_stream.order_state_stream(request=request)
|
||||||
|
async for order_state in stream:
|
||||||
|
print(order_state)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
28
invest-python-master/examples/async_post_order_async.py
Normal file
28
invest-python-master/examples/async_post_order_async.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import OrderDirection, OrderType, PostOrderAsyncRequest
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
accounts = await client.users.get_accounts()
|
||||||
|
account_id = accounts.accounts[0].id
|
||||||
|
request = PostOrderAsyncRequest(
|
||||||
|
order_type=OrderType.ORDER_TYPE_MARKET,
|
||||||
|
direction=OrderDirection.ORDER_DIRECTION_BUY,
|
||||||
|
instrument_id="BBG004730ZJ9",
|
||||||
|
quantity=1,
|
||||||
|
account_id=account_id,
|
||||||
|
order_id=str(uuid4()),
|
||||||
|
)
|
||||||
|
response = await client.orders.post_order_async(request=request)
|
||||||
|
print(response)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
29
invest-python-master/examples/async_retrying_client.py
Normal file
29
invest-python-master/examples/async_retrying_client.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import asyncio
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from t_tech.invest import CandleInterval
|
||||||
|
from t_tech.invest.retrying.aio.client import AsyncRetryingClient
|
||||||
|
from t_tech.invest.retrying.settings import RetryClientSettings
|
||||||
|
from t_tech.invest.utils import now
|
||||||
|
|
||||||
|
logging.basicConfig(format="%(asctime)s %(levelname)s:%(message)s", level=logging.DEBUG)
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
retry_settings = RetryClientSettings(use_retry=True, max_retry_attempt=2)
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncRetryingClient(TOKEN, settings=retry_settings) as client:
|
||||||
|
async for candle in client.get_all_candles(
|
||||||
|
figi="BBG000B9XRY4",
|
||||||
|
from_=now() - timedelta(days=301),
|
||||||
|
interval=CandleInterval.CANDLE_INTERVAL_1_MIN,
|
||||||
|
):
|
||||||
|
print(candle)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
41
invest-python-master/examples/async_stream_client.py
Normal file
41
invest-python-master/examples/async_stream_client.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
from typing import AsyncIterable
|
||||||
|
|
||||||
|
from t_tech.invest import (
|
||||||
|
AsyncClient,
|
||||||
|
CandleInstrument,
|
||||||
|
MarketDataRequest,
|
||||||
|
SubscribeCandlesRequest,
|
||||||
|
SubscriptionAction,
|
||||||
|
SubscriptionInterval,
|
||||||
|
)
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async def request_iterator():
|
||||||
|
yield MarketDataRequest(
|
||||||
|
subscribe_candles_request=SubscribeCandlesRequest(
|
||||||
|
subscription_action=SubscriptionAction.SUBSCRIPTION_ACTION_SUBSCRIBE,
|
||||||
|
instruments=[
|
||||||
|
CandleInstrument(
|
||||||
|
figi="BBG004730N88",
|
||||||
|
interval=SubscriptionInterval.SUBSCRIPTION_INTERVAL_ONE_MINUTE,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
while True:
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
async for marketdata in client.market_data_stream.market_data_stream(
|
||||||
|
request_iterator()
|
||||||
|
):
|
||||||
|
print(marketdata)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
23
invest-python-master/examples/cancel_orders.py
Normal file
23
invest-python-master/examples/cancel_orders.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
response = client.users.get_accounts()
|
||||||
|
account, *_ = response.accounts
|
||||||
|
account_id = account.id
|
||||||
|
logger.info("Orders: %s", client.orders.get_orders(account_id=account_id))
|
||||||
|
client.cancel_all_orders(account_id=account.id)
|
||||||
|
logger.info("Orders: %s", client.orders.get_orders(account_id=account_id))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
14
invest-python-master/examples/client.py
Normal file
14
invest-python-master/examples/client.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
print(client.users.get_accounts())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
32
invest-python-master/examples/download_all_candles.py
Normal file
32
invest-python-master/examples/download_all_candles.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
|
from datetime import timedelta
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from t_tech.invest import CandleInterval, Client
|
||||||
|
from t_tech.invest.caching.market_data_cache.cache import MarketDataCache
|
||||||
|
from t_tech.invest.caching.market_data_cache.cache_settings import (
|
||||||
|
MarketDataCacheSettings,
|
||||||
|
)
|
||||||
|
from t_tech.invest.utils import now
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
settings = MarketDataCacheSettings(base_cache_dir=Path("market_data_cache"))
|
||||||
|
market_data_cache = MarketDataCache(settings=settings, services=client)
|
||||||
|
for candle in market_data_cache.get_all_candles(
|
||||||
|
figi="BBG004730N88",
|
||||||
|
from_=now() - timedelta(days=1),
|
||||||
|
interval=CandleInterval.CANDLE_INTERVAL_HOUR,
|
||||||
|
):
|
||||||
|
print(candle.time, candle.is_complete)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
46
invest-python-master/examples/easy_async_stream_client.py
Normal file
46
invest-python-master/examples/easy_async_stream_client.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import (
|
||||||
|
AsyncClient,
|
||||||
|
CandleInstrument,
|
||||||
|
InfoInstrument,
|
||||||
|
MarketDataResponse,
|
||||||
|
SubscriptionInterval,
|
||||||
|
TradeInstrument,
|
||||||
|
)
|
||||||
|
from t_tech.invest.async_services import AsyncMarketDataStreamManager
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
market_data_stream: AsyncMarketDataStreamManager = (
|
||||||
|
client.create_market_data_stream()
|
||||||
|
)
|
||||||
|
market_data_stream.candles.waiting_close().subscribe(
|
||||||
|
[
|
||||||
|
CandleInstrument(
|
||||||
|
figi="BBG004730N88",
|
||||||
|
interval=SubscriptionInterval.SUBSCRIPTION_INTERVAL_ONE_MINUTE,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
market_data_stream.trades.subscribe(
|
||||||
|
[
|
||||||
|
TradeInstrument(
|
||||||
|
figi="BBG004730N88",
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
async for marketdata in market_data_stream:
|
||||||
|
marketdata: MarketDataResponse = marketdata
|
||||||
|
print(marketdata)
|
||||||
|
market_data_stream.info.subscribe([InfoInstrument(figi="BBG004730N88")])
|
||||||
|
if marketdata.subscribe_info_response:
|
||||||
|
market_data_stream.stop()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
28
invest-python-master/examples/easy_stream_client.py
Normal file
28
invest-python-master/examples/easy_stream_client.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import CandleInstrument, Client, InfoInstrument, SubscriptionInterval
|
||||||
|
from t_tech.invest.services import MarketDataStreamManager
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
market_data_stream: MarketDataStreamManager = client.create_market_data_stream()
|
||||||
|
market_data_stream.candles.waiting_close().subscribe(
|
||||||
|
[
|
||||||
|
CandleInstrument(
|
||||||
|
figi="BBG004730N88",
|
||||||
|
interval=SubscriptionInterval.SUBSCRIPTION_INTERVAL_ONE_MINUTE,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
for marketdata in market_data_stream:
|
||||||
|
print(marketdata)
|
||||||
|
market_data_stream.info.subscribe([InfoInstrument(figi="BBG004730N88")])
|
||||||
|
if marketdata.subscribe_info_response:
|
||||||
|
market_data_stream.stop()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
29
invest-python-master/examples/get_active_orders.py
Normal file
29
invest-python-master/examples/get_active_orders.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
"""Example - How to get list of active orders."""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
response = client.users.get_accounts()
|
||||||
|
account, *_ = response.accounts
|
||||||
|
account_id = account.id
|
||||||
|
|
||||||
|
orders = client.orders.get_orders(
|
||||||
|
account_id=account_id,
|
||||||
|
)
|
||||||
|
print("Active orders:")
|
||||||
|
for order in orders.orders:
|
||||||
|
print(order)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
23
invest-python-master/examples/get_candles_with_limit.py
Normal file
23
invest-python-master/examples/get_candles_with_limit.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import CandleInterval, Client
|
||||||
|
from t_tech.invest.utils import now
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
for candle in client.market_data.get_candles(
|
||||||
|
instrument_id="BBG004730N88",
|
||||||
|
to=now(),
|
||||||
|
limit=24,
|
||||||
|
interval=CandleInterval.CANDLE_INTERVAL_HOUR,
|
||||||
|
).candles:
|
||||||
|
print(candle)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
19
invest-python-master/examples/get_last_prices.py
Normal file
19
invest-python-master/examples/get_last_prices.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client, InstrumentStatus
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
print(
|
||||||
|
client.market_data.get_last_prices(
|
||||||
|
figi=["BBG004730ZJ9"],
|
||||||
|
instrument_status=InstrumentStatus.INSTRUMENT_STATUS_BASE,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
20
invest-python-master/examples/get_last_trades.py
Normal file
20
invest-python-master/examples/get_last_trades.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
from t_tech.invest.schemas import TradeSourceType
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
print(
|
||||||
|
client.market_data.get_last_trades(
|
||||||
|
instrument_id="BBG004730ZJ9",
|
||||||
|
trade_source=TradeSourceType.TRADE_SOURCE_EXCHANGE,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
27
invest-python-master/examples/get_market_values.py
Normal file
27
invest-python-master/examples/get_market_values.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
from t_tech.invest.schemas import GetMarketValuesRequest, MarketValueType
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
for values in client.market_data.get_market_values(
|
||||||
|
request=GetMarketValuesRequest(
|
||||||
|
instrument_id=["BBG004730N88"],
|
||||||
|
values=[
|
||||||
|
MarketValueType.INSTRUMENT_VALUE_LAST_PRICE,
|
||||||
|
MarketValueType.INSTRUMENT_VALUE_CLOSE_PRICE,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
).instruments:
|
||||||
|
for value in values.values:
|
||||||
|
print(value)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
28
invest-python-master/examples/get_operations_by_cursor.py
Normal file
28
invest-python-master/examples/get_operations_by_cursor.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import os
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
from t_tech.invest import Client, GetOperationsByCursorRequest
|
||||||
|
|
||||||
|
token = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
with Client(token) as client:
|
||||||
|
accounts = client.users.get_accounts()
|
||||||
|
account_id = accounts.accounts[0].id
|
||||||
|
|
||||||
|
def get_request(cursor=""):
|
||||||
|
return GetOperationsByCursorRequest(
|
||||||
|
account_id=account_id,
|
||||||
|
instrument_id="BBG004730N88",
|
||||||
|
cursor=cursor,
|
||||||
|
limit=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
operations = client.operations.get_operations_by_cursor(get_request())
|
||||||
|
print(operations)
|
||||||
|
depth = 10
|
||||||
|
while operations.has_next and depth > 0:
|
||||||
|
request = get_request(cursor=operations.next_cursor)
|
||||||
|
operations = client.operations.get_operations_by_cursor(request)
|
||||||
|
pprint(operations)
|
||||||
|
depth -= 1
|
||||||
38
invest-python-master/examples/get_orders.py
Normal file
38
invest-python-master/examples/get_orders.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
"""Example - How to get list of orders for 1 last hour (maximum requesting period)."""
|
||||||
|
import datetime
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
from t_tech.invest.schemas import OrderExecutionReportStatus
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
response = client.users.get_accounts()
|
||||||
|
account, *_ = response.accounts
|
||||||
|
account_id = account.id
|
||||||
|
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
orders = client.orders.get_orders(
|
||||||
|
account_id=account_id,
|
||||||
|
from_=now - datetime.timedelta(hours=1),
|
||||||
|
to=now,
|
||||||
|
# filter only executed or partially executed orders
|
||||||
|
execution_status=[
|
||||||
|
OrderExecutionReportStatus.EXECUTION_REPORT_STATUS_FILL,
|
||||||
|
OrderExecutionReportStatus.EXECUTION_REPORT_STATUS_PARTIALLYFILL,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
print("Orders list:")
|
||||||
|
for order in orders.orders:
|
||||||
|
print(order)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
21
invest-python-master/examples/get_risk_rates.py
Normal file
21
invest-python-master/examples/get_risk_rates.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
from t_tech.invest.schemas import RiskRatesRequest
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
request = RiskRatesRequest()
|
||||||
|
request.instrument_id = ["BBG001M2SC01", "BBG004730N88"]
|
||||||
|
r = client.instruments.get_risk_rates(request=request)
|
||||||
|
for i in r.instrument_risk_rates:
|
||||||
|
print(i.instrument_uid)
|
||||||
|
print(i.short_risk_rate)
|
||||||
|
print(i.long_risk_rate)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
20
invest-python-master/examples/get_sandbox_max_lots.py
Normal file
20
invest-python-master/examples/get_sandbox_max_lots.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import GetMaxLotsRequest
|
||||||
|
from t_tech.invest.sandbox.client import SandboxClient
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_SANDBOX_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with SandboxClient(TOKEN) as client:
|
||||||
|
account_id = client.users.get_accounts().accounts[0].id
|
||||||
|
request = GetMaxLotsRequest(
|
||||||
|
account_id=account_id,
|
||||||
|
instrument_id="BBG004730N88",
|
||||||
|
)
|
||||||
|
print(client.sandbox.get_sandbox_max_lots(request=request))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
22
invest-python-master/examples/get_signals.py
Normal file
22
invest-python-master/examples/get_signals.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
"""Example - How to get Signals with filtering"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
from t_tech.invest.schemas import GetSignalsRequest, SignalState
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
request = GetSignalsRequest()
|
||||||
|
request.instrument_uid = "e6123145-9665-43e0-8413-cd61b8aa9b13" # Сбербанк
|
||||||
|
request.active = SignalState.SIGNAL_STATE_ACTIVE # только активные сигналы
|
||||||
|
r = client.signals.get_signals(request=request)
|
||||||
|
for signal in r.signals:
|
||||||
|
print(signal)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
19
invest-python-master/examples/get_strategies.py
Normal file
19
invest-python-master/examples/get_strategies.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
"""Example - How to get Strategies"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
from t_tech.invest.schemas import GetStrategiesRequest
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
r = client.signals.get_strategies(request=GetStrategiesRequest())
|
||||||
|
for strategy in r.strategies:
|
||||||
|
print(strategy)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
40
invest-python-master/examples/get_tech_analysis.py
Normal file
40
invest-python-master/examples/get_tech_analysis.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import os
|
||||||
|
from datetime import timedelta
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
from t_tech.invest.schemas import (
|
||||||
|
Deviation,
|
||||||
|
GetTechAnalysisRequest,
|
||||||
|
IndicatorInterval,
|
||||||
|
IndicatorType,
|
||||||
|
Smoothing,
|
||||||
|
TypeOfPrice,
|
||||||
|
)
|
||||||
|
from t_tech.invest.utils import decimal_to_quotation, now
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
request = GetTechAnalysisRequest(
|
||||||
|
indicator_type=IndicatorType.INDICATOR_TYPE_RSI,
|
||||||
|
instrument_uid="6542a064-6633-44ba-902f-710c97507522",
|
||||||
|
from_=now() - timedelta(days=7),
|
||||||
|
to=now(),
|
||||||
|
interval=IndicatorInterval.INDICATOR_INTERVAL_4_HOUR,
|
||||||
|
type_of_price=TypeOfPrice.TYPE_OF_PRICE_AVG,
|
||||||
|
length=42,
|
||||||
|
deviation=Deviation(
|
||||||
|
deviation_multiplier=decimal_to_quotation(Decimal(1.0)),
|
||||||
|
),
|
||||||
|
smoothing=Smoothing(fast_length=13, slow_length=7, signal_smoothing=3),
|
||||||
|
)
|
||||||
|
response = client.market_data.get_tech_analysis(request=request)
|
||||||
|
for indicator in response.technical_indicators:
|
||||||
|
print(indicator.signal)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
10
invest-python-master/examples/get_trading_statuses.py
Normal file
10
invest-python-master/examples/get_trading_statuses.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
token = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
with Client(token) as client:
|
||||||
|
statuses = client.market_data.get_trading_statuses(instrument_ids=["BBG004730N88"])
|
||||||
|
print(statuses)
|
||||||
44
invest-python-master/examples/instrument_cache.py
Normal file
44
invest-python-master/examples/instrument_cache.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
from t_tech.invest import Client, InstrumentIdType
|
||||||
|
from t_tech.invest.caching.instruments_cache.instruments_cache import InstrumentsCache
|
||||||
|
from t_tech.invest.caching.instruments_cache.settings import InstrumentsCacheSettings
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
inst = client.instruments.etfs().instruments[-1]
|
||||||
|
pprint(inst)
|
||||||
|
|
||||||
|
from_server = client.instruments.etf_by(
|
||||||
|
id_type=InstrumentIdType.INSTRUMENT_ID_TYPE_UID,
|
||||||
|
class_code=inst.class_code,
|
||||||
|
id=inst.uid,
|
||||||
|
)
|
||||||
|
pprint(from_server)
|
||||||
|
|
||||||
|
settings = InstrumentsCacheSettings()
|
||||||
|
instruments_cache = InstrumentsCache(
|
||||||
|
settings=settings, instruments_service=client.instruments
|
||||||
|
)
|
||||||
|
|
||||||
|
from_cache = instruments_cache.etf_by(
|
||||||
|
id_type=InstrumentIdType.INSTRUMENT_ID_TYPE_UID,
|
||||||
|
class_code=inst.class_code,
|
||||||
|
id=inst.uid,
|
||||||
|
)
|
||||||
|
pprint(from_cache)
|
||||||
|
|
||||||
|
if str(from_server) != str(from_cache):
|
||||||
|
raise Exception("cache miss")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import GetAssetReportsRequest
|
||||||
|
from t_tech.invest.utils import now
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
instruments = await client.instruments.find_instrument(
|
||||||
|
query="Тинькофф Квадратные метры"
|
||||||
|
)
|
||||||
|
instrument = instruments.instruments[0]
|
||||||
|
print(instrument.name)
|
||||||
|
request = GetAssetReportsRequest(
|
||||||
|
instrument_id=instrument.uid,
|
||||||
|
from_=now() - timedelta(days=7),
|
||||||
|
to=now(),
|
||||||
|
)
|
||||||
|
print(await client.instruments.get_asset_reports(request=request))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import AssetsRequest, InstrumentStatus, InstrumentType
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
r = await client.instruments.get_assets(
|
||||||
|
request=AssetsRequest(
|
||||||
|
instrument_type=InstrumentType.INSTRUMENT_TYPE_SHARE,
|
||||||
|
instrument_status=InstrumentStatus.INSTRUMENT_STATUS_BASE,
|
||||||
|
) # pylint:disable=line-too-long
|
||||||
|
)
|
||||||
|
print("BASE SHARE ASSETS")
|
||||||
|
for bond in r.assets:
|
||||||
|
print(bond)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient, InstrumentType
|
||||||
|
from t_tech.invest.schemas import EventType, GetBondEventsRequest
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
bond = (
|
||||||
|
await client.instruments.find_instrument(
|
||||||
|
query="Тинькофф Банк выпуск 1",
|
||||||
|
instrument_kind=InstrumentType.INSTRUMENT_TYPE_BOND,
|
||||||
|
)
|
||||||
|
).instruments[0]
|
||||||
|
|
||||||
|
request = GetBondEventsRequest(
|
||||||
|
instrument_id=bond.uid,
|
||||||
|
type=EventType.EVENT_TYPE_CALL,
|
||||||
|
)
|
||||||
|
print(await client.instruments.get_bond_events(request=request))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
20
invest-python-master/examples/instruments/async_get_bonds.py
Normal file
20
invest-python-master/examples/instruments/async_get_bonds.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import InstrumentExchangeType
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
bonds = await client.instruments.bonds(
|
||||||
|
instrument_exchange=InstrumentExchangeType.INSTRUMENT_EXCHANGE_UNSPECIFIED,
|
||||||
|
)
|
||||||
|
for bond in bonds.instruments:
|
||||||
|
print(bond)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import GetConsensusForecastsRequest, Page
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
request = GetConsensusForecastsRequest(
|
||||||
|
paging=Page(page_number=0, limit=2),
|
||||||
|
)
|
||||||
|
response = await client.instruments.get_consensus_forecasts(request=request)
|
||||||
|
print(response.page)
|
||||||
|
for forecast in response.items:
|
||||||
|
print(forecast.uid, forecast.consensus.name)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import GetForecastRequest
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
async with AsyncClient(TOKEN) as client:
|
||||||
|
instrument = (
|
||||||
|
await client.instruments.find_instrument(
|
||||||
|
query="Сбер Банк - привилегированные акции"
|
||||||
|
)
|
||||||
|
).instruments[0]
|
||||||
|
request = GetForecastRequest(instrument_id=instrument.uid)
|
||||||
|
response = await client.instruments.get_forecast_by(request=request)
|
||||||
|
print(instrument.name, response.consensus.recommendation.name)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import InstrumentsRequest, InstrumentStatus
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
token = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
with AsyncClient(token) as client:
|
||||||
|
r = await client.instruments.structured_notes(
|
||||||
|
request=InstrumentsRequest(
|
||||||
|
instrument_status=InstrumentStatus.INSTRUMENT_STATUS_ALL
|
||||||
|
)
|
||||||
|
)
|
||||||
|
for note in r.instruments:
|
||||||
|
print(note)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import AsyncClient
|
||||||
|
from t_tech.invest.schemas import InstrumentIdType, InstrumentRequest
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
token = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
with AsyncClient(token) as client:
|
||||||
|
r = await client.instruments.structured_note_by(
|
||||||
|
request=InstrumentRequest(
|
||||||
|
id_type=InstrumentIdType.INSTRUMENT_ID_TYPE_FIGI, id="BBG012S2DCJ8"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
print(r.instrument)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
from t_tech.invest.schemas import GetAssetFundamentalsRequest
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
request = GetAssetFundamentalsRequest(
|
||||||
|
assets=["40d89385-a03a-4659-bf4e-d3ecba011782"],
|
||||||
|
)
|
||||||
|
print(client.instruments.get_asset_fundamentals(request=request))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import os
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
from t_tech.invest.schemas import GetAssetReportsRequest
|
||||||
|
from t_tech.invest.utils import now
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
instruments = client.instruments.find_instrument(
|
||||||
|
query="Тинькофф Квадратные метры"
|
||||||
|
)
|
||||||
|
instrument = instruments.instruments[0]
|
||||||
|
print(instrument.name)
|
||||||
|
request = GetAssetReportsRequest(
|
||||||
|
instrument_id=instrument.uid,
|
||||||
|
from_=now() - timedelta(days=7),
|
||||||
|
to=now(),
|
||||||
|
)
|
||||||
|
print(client.instruments.get_asset_reports(request=request))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
28
invest-python-master/examples/instruments/get_assets.py
Normal file
28
invest-python-master/examples/instruments/get_assets.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
from t_tech.invest.schemas import AssetsRequest, InstrumentStatus, InstrumentType
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
r = client.instruments.get_assets(
|
||||||
|
request=AssetsRequest(instrument_type=InstrumentType.INSTRUMENT_TYPE_BOND)
|
||||||
|
)
|
||||||
|
print("BONDS")
|
||||||
|
for bond in r.assets:
|
||||||
|
print(bond)
|
||||||
|
r = client.instruments.get_assets(
|
||||||
|
request=AssetsRequest(
|
||||||
|
instrument_status=InstrumentStatus.INSTRUMENT_STATUS_BASE
|
||||||
|
)
|
||||||
|
)
|
||||||
|
print("BASE ASSETS")
|
||||||
|
for bond in r.assets:
|
||||||
|
print(bond)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
24
invest-python-master/examples/instruments/get_bond_events.py
Normal file
24
invest-python-master/examples/instruments/get_bond_events.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
from t_tech.invest.schemas import EventType, GetBondEventsRequest, InstrumentType
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
bond = client.instruments.find_instrument(
|
||||||
|
query="Тинькофф Банк выпуск 1",
|
||||||
|
instrument_kind=InstrumentType.INSTRUMENT_TYPE_BOND,
|
||||||
|
).instruments[0]
|
||||||
|
|
||||||
|
request = GetBondEventsRequest(
|
||||||
|
instrument_id=bond.uid,
|
||||||
|
type=EventType.EVENT_TYPE_CALL,
|
||||||
|
)
|
||||||
|
print(client.instruments.get_bond_events(request=request))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
19
invest-python-master/examples/instruments/get_bonds.py
Normal file
19
invest-python-master/examples/instruments/get_bonds.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
from t_tech.invest.schemas import InstrumentExchangeType
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
r = client.instruments.bonds(
|
||||||
|
instrument_exchange=InstrumentExchangeType.INSTRUMENT_EXCHANGE_UNSPECIFIED
|
||||||
|
)
|
||||||
|
for bond in r.instruments:
|
||||||
|
print(bond)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
18
invest-python-master/examples/instruments/get_brands.py
Normal file
18
invest-python-master/examples/instruments/get_brands.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
"""Example - How to get Brands"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
r = client.instruments.get_brands()
|
||||||
|
for brand in r.brands:
|
||||||
|
print(brand)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import os
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
from t_tech.invest.schemas import (
|
||||||
|
GetAssetReportsRequest,
|
||||||
|
GetConsensusForecastsRequest,
|
||||||
|
InstrumentIdType,
|
||||||
|
Page,
|
||||||
|
)
|
||||||
|
from t_tech.invest.utils import now
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
request = GetConsensusForecastsRequest(
|
||||||
|
paging=Page(page_number=0, limit=2),
|
||||||
|
)
|
||||||
|
response = client.instruments.get_consensus_forecasts(request=request)
|
||||||
|
print(response.page)
|
||||||
|
for forecast in response.items:
|
||||||
|
print(forecast.uid, forecast.consensus.name)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
20
invest-python-master/examples/instruments/get_dfa_by.py
Normal file
20
invest-python-master/examples/instruments/get_dfa_by.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client, InstrumentIdType, InstrumentRequest
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
dfa = client.instruments.dfa_by(
|
||||||
|
request=InstrumentRequest(
|
||||||
|
id_type=InstrumentIdType.INSTRUMENT_ID_TYPE_POSITION_UID,
|
||||||
|
id="ce604b33-70c7-4609-9f42-075dbd9fe278",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
print(dfa)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
16
invest-python-master/examples/instruments/get_dfas.py
Normal file
16
invest-python-master/examples/instruments/get_dfas.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
r = client.instruments.dfas()
|
||||||
|
for dfa in r.instruments:
|
||||||
|
print(dfa)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
28
invest-python-master/examples/instruments/get_forecast_by.py
Normal file
28
invest-python-master/examples/instruments/get_forecast_by.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import os
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from t_tech.invest import Client
|
||||||
|
from t_tech.invest.schemas import (
|
||||||
|
GetAssetReportsRequest,
|
||||||
|
GetConsensusForecastsRequest,
|
||||||
|
GetForecastRequest,
|
||||||
|
InstrumentIdType,
|
||||||
|
Page,
|
||||||
|
)
|
||||||
|
from t_tech.invest.utils import now
|
||||||
|
|
||||||
|
TOKEN = os.environ["INVEST_TOKEN"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
with Client(TOKEN) as client:
|
||||||
|
instrument = client.instruments.find_instrument(
|
||||||
|
query="Сбер Банк - привилегированные акции"
|
||||||
|
).instruments[0]
|
||||||
|
request = GetForecastRequest(instrument_id=instrument.uid)
|
||||||
|
response = client.instruments.get_forecast_by(request=request)
|
||||||
|
print(instrument.name, response.consensus.recommendation.name)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user