파이썬 26

[선물API] 계좌 정보 불러오기

먼저 API키가 필요합니다.바이낸스 API키 발급 방법->  바이낸스 API키 발급  만약 안되면 사용중인 PC의 시간을 동기화 해줘야 합니다.윈도우 11 기준 화면 우측 하단에 표기된 시간을 우클릭 후 날짜 및 시간 조정을 누르신 다음 '지금 동기화'를 누르시면 됩니다.import requestsimport hmacimport hashlibimport timefrom pprint import pprint# 바이낸스 API 키와 시크릿 로드with open("D:/코인/binance key.txt") as f: lines = f.readlines() api_key = lines[0].strip() secret_key = lines[1].strip()headers = { "X-MBX-..

[선물 API] 여러개 주문 동시에 넣기

해당 코드는 과거에 사용하고 최근에 개선하지 않은 코드입니다.제대로 작동하지 않을 수 있습니다. import ccxtimport asyncioimport logging# API, Secret Key가 저장된 txt 파일을 불러오는 코드. 경로는 바꿔도 상관없다.with open("D:/코인/binance key.txt") as f: lines = f.readlines() api_key = lines[0].strip() secret_key = lines[1].strip()logger = logging.getLogger('ccxt')logger.setLevel(logging.ERROR)Futures_binance = ccxt.binance({ 'apiKey': api_key, 's..

[선물 API] 차트 데이터 불러오기

차트를 가져오는 방법은 크게 두가지가 있습니다.CCXT라는 가상화폐 거래소의 API를 단일한 인터페이스로 제공하는 오픈소스 라이브러리를 활용하는 것.바이낸스에서 제공되는 API를 직접 요청하는 것.  우선 CCXT를 활용하는 방법입니다.import ccxtimport pprintFutures_binance = ccxt.binance(config={ 'options': { 'defaultType': 'future' }})BTC_Chart = Futures_binance.fetch_ohlcv( symbol="BTCUSDT", timeframe='1m', limit=20)pprint.pprint(BTC_Chart) CCXT를 통해 받은 차트 데이터는 리스트 형태입니다.[..

[선물 WS] 주문 체결, 지갑 정보 전달받기 (User Data Stream)

API나 웹소켓을 다룰 때 주문, 계좌 정보와 같이개인정보에 해당하는 내용을 다룰땐 API키가 필요합니다.API키 발급 방법은 바이낸스 API키 발급 참조 import requestsimport asyncioimport websocketsimport jsonwith open("D:/코인/binance key.txt") as f: lines = f.readlines() api_key = lines[0].strip() secret_key = lines[1].strip()headers = { "X-MBX-APIKEY": api_key,}FUTURES_STREAM_END_POINT_1 = "wss://fstream.binance.com"BINANCE_FUTURES_END_POINT = "h..

[현물 WS] 호가창 일부분 실시간 (Partial Book Depth Streams)

import asyncioimport websocketsimport jsonfrom pprint import pprintasync def Partial_Book_Depth(): symbol = 'btcusdt' # 이름 levels = '@depth20' # 불러올 주문 수. 5, 10, 20 단위 US = '@1000ms' # 업데이트 속도. 1000ms, 100ms uri = f'wss://stream.binance.com:9443/ws/{symbol}{levels}{US}' async with websockets.connect(uri) as websocket: try: while True: data = json.l..

반응형