Last active
January 4, 2025 15:11
-
-
Save pgmrDohan/25513a32fdcd9cc2a186caf80107af98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ccxt | |
| import time | |
| # Bitget API 키 설정 | |
| api_key = 'YOUR_API_KEY' | |
| api_secret = 'YOUR_API_SECRET' | |
| password = 'YOUR_PASSWORD' | |
| # Bitget 거래소 객체 생성 | |
| exchange = ccxt.bitget({ | |
| 'apiKey': api_key, | |
| 'secret': api_secret, | |
| 'password': password, | |
| 'options': { | |
| 'defaultType': 'spot', # 현물 거래를 위한 설정 | |
| }, | |
| }) | |
| # 거래할 심볼 목록 | |
| symbols = ['BTC/USDT', 'ETH/USDT', 'BGB/USDT', 'XRP/USDT', 'UNI/USDT', 'DOGE/USDT', 'USDC/USDT'] | |
| # 매수 및 매도 가격 범위 설정 (예시) | |
| buy_price_ranges = { | |
| 'BTC/USDT': (30000, 35000), | |
| 'ETH/USDT': (2000, 2500), | |
| 'BGB/USDT': (0.5, 1.0), | |
| 'XRP/USDT': (0.4, 0.5), | |
| 'UNI/USDT': (5, 7), | |
| 'DOGE/USDT': (0.06, 0.08), | |
| 'USDC/USDT': (0.99, 1.01), | |
| } | |
| sell_price_ranges = { | |
| 'BTC/USDT': (40000, 45000), | |
| 'ETH/USDT': (3000, 3500), | |
| 'BGB/USDT': (1.5, 2.0), | |
| 'XRP/USDT': (0.6, 0.7), | |
| 'UNI/USDT': (10, 12), | |
| 'DOGE/USDT': (0.1, 0.12), | |
| 'USDC/USDT': (1.02, 1.05), | |
| } | |
| # 주문 크기 설정 (예시: 각 거래에 $100 상당의 코인 매수/매도) | |
| order_size_usd = 100 | |
| def place_order(symbol, side, amount): | |
| try: | |
| order = exchange.create_order(symbol=symbol, type='market', side=side, amount=amount) | |
| print(f"주문 성공: {symbol} {side} {amount}") | |
| except Exception as e: | |
| print(f"주문 실패: {symbol} {side} {amount} - {str(e)}") | |
| def main(): | |
| while True: | |
| for symbol in symbols: | |
| try: | |
| # 현재 가격 가져오기 | |
| ticker = exchange.fetch_ticker(symbol) | |
| current_price = ticker['last'] | |
| print(f"{symbol} 현재 가격: {current_price}") | |
| # 매수 조건 확인 및 주문 | |
| if symbol in buy_price_ranges: | |
| buy_min, buy_max = buy_price_ranges[symbol] | |
| if buy_min <= current_price <= buy_max: | |
| amount_to_buy = order_size_usd / current_price | |
| place_order(symbol, 'buy', amount_to_buy) | |
| # 매도 조건 확인 및 주문 | |
| if symbol in sell_price_ranges: | |
| sell_min, sell_max = sell_price_ranges[symbol] | |
| if sell_min <= current_price <= sell_max: | |
| # 보유 잔고 확인 | |
| balance = exchange.fetch_balance() | |
| if symbol.split('/')[0] in balance['free']: | |
| amount_to_sell = balance['free'][symbol.split('/')[0]] | |
| if amount_to_sell > 0: | |
| place_order(symbol, 'sell', amount_to_sell) | |
| else: | |
| print(f"{symbol} 잔고 부족으로 매도 불가") | |
| else: | |
| print(f"{symbol} 잔고 정보 없음") | |
| except Exception as e: | |
| print(f"{symbol} 처리 중 오류 발생: {str(e)}") | |
| # 일정 시간 대기 (예: 60초) | |
| time.sleep(60) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment