Sunnatskilletskillet127

import ccxt import talib # Borsa API-ga ulanish exchange = ccxt

BITSTAMP:BTCUSD   Биткоин
import ccxt
import talib

# Borsa API-ga ulanish
exchange = ccxt.binance({
'apiKey': 'sizning_api_key',
'secret': 'sizning_api_secret',
})

# Almashtirish nomi
symbol = 'BTC/USDT'

# Borsa kurslarini olish
def get_market_data(symbol, timeframe='1h', limit=100):
ohlcv = exchange.fetch_ohlcv(symbol, timeframe, limit)
close_prices = [candle for candle in ohlcv] # 4 - close
return close_prices

# Simple Moving Average (SMA) ni hisoblash
def calculate_sma(data, period=20):
return talib.SMA(data, timeperiod=period)

# Strategiya: Agar SMA ning o'rtacha narxi, joriy kursdan yuqori bo'lsa, sotish buyurtmasi bering
def trade_strategy(symbol, timeframe='1h', limit=100, sma_period=20):
close_prices = get_market_data(symbol, timeframe, limit)
sma_values = calculate_sma(close_prices, sma_period)

current_price = close_prices
last_sma_value = sma_values

if current_price > last_sma_value:
# Borsaga buyurtma jo'natish
place_order(symbol, 'buy', current_price, 0.001)
print(f'Sotish buyurtmasi berildi! Narxi: {current_price}')

# Buyurtma yaratish va borsaga jo'natish
def place_order(symbol, order_type, price, quantity):
order = exchange.create_limit_buy_order(symbol, quantity, price) if order_type == 'buy' else exchange.create_limit_sell_order(symbol, quantity, price)
return order

# Strategiyani har bir mumni tekshirish
trade_strategy(symbol)
Отказ от ответственности

Все виды контента, которые вы можете увидеть на TradingView, не являются финансовыми, инвестиционными, торговыми или любыми другими рекомендациями. Мы не предоставляем советы по покупке и продаже активов. Подробнее — в Условиях использования TradingView.