https://github.com/gateio/gateapi-python
위 문서를 바탕으로 작성하였음
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
import gate_api
# api keyset
configuration = gate_api.Configuration(
host = "https://api.gateio.ws/api/v4",
key = str(''),
secret = str('')
)
api_client = gate_api.ApiClient(configuration)
api_instance = gate_api.SpotApi(api_client)
# 현물 USDT 소지량 확인 및 출력, apikey 이상 등으로 에러날시 Exception
try:
api_response = api_instance.list_spot_accounts(currency='USDT')
print('[apikey 정상 확인]\nUSDT 소지량 :',api_response)
except:
print('Error.. apikey 값 확인 필요')
# 주문 메서드
def GateioOrder(Symbol,Money):
# 호가 호출 및 asks 부분 잘라내기
orderbook = str(api_instance.list_order_book(Symbol+'_USDT',limit=1))
order_price = orderbook[orderbook.find('[[')+3:orderbook.find(',')-1]
ask_cal = Money/order_price
# 주문 가격 및 수량 출력
print('매수 주문 가격 :',order_price,'\n','매수 수량 :',ask_cal)
# 주문
try:
order = gate_api.Order(currency_pair=Symbol+'_USDT',amount= ask_cal,price = float(order_price), side='buy') # Order |
api_response = api_instance.create_order(order)
# 주문 결과 출력
print('[주문 성공]\n',api_response)
except:
print("Error.. 홈페이지에서 apikey 설정 Spot(현물) 체크 유무 확인 필요")
# 주문 메서드 호출(주문하려는 코인, 주문에 사용될 테더갯수)
GateioOrder('BTC',10)
|
cs |
호가 불러오는 부분이 좀 조잡하긴한데 그냥 저런식으로 쓰고있음