달나라 노트

Python Upbit : buy_market_order, sell_market_order (시장가 주문, 시장가 매수, 시장가 매도) 본문

Python/Python ETC

Python Upbit : buy_market_order, sell_market_order (시장가 주문, 시장가 매수, 시장가 매도)

CosmosProject 2022. 2. 27. 02:02
728x90
반응형

 

 

 

buy_market_order -> 시장가에 코인 매수

sell_market_order -> 시장가에 코인 매도

 

Syntax

buy_market_order(ticker='KRW-ETH',
                 price=100000)

ticker = 시장가에 매수할 ticker

price = 매수할 양(얼마치를 매수할지)

(KRW-ETH를 시장가에 100000원어치 매수한다는 예시입니다.)

 

 

 

 

sell_market_order(ticker='KRW-ETH',
                  volume=1.5)

ticker = 시장가에 매도할 ticker

volume = 시장가에 매도할 개수

(KRW-ETH를 1.5개 시장가에 매도한다는 예시입니다.)

 

 

 

 

 

 

 

 

import pyupbit as ub

access_key = 'access_key'
secret_key = 'secret_key'

upbit = ub.Upbit(access=access_key, secret=secret_key)

buy_result = upbit.buy_market_order(ticker='KRW-ETH', price=100000)
sell_result = upbit.sell_market_order(ticker='KRW-ETH', volume=1.5)



-- Result
{'uuid': 'adrg189adrg48-w6wf-w6d3-ws9e18fg6rs', 'side': 'bid', 'ord_type': 'limit', 'price': '3000000.0', 'state': 'wait', 'market': 'KRW-ETH', 'created_at': '2022-02-27T01:28:54+09:00', 'volume': '0.03333333', 'remaining_volume': '0.03333333', 'reserved_fee': '4.5', 'remaining_fee': '4.5', 'paid_fee': '0.0', 'locked': '9004.5', 'executed_volume': '0.0', 'trades_count': 0}
{'uuid': 's6e1f3sd-38w6-d7s4-yu8j-a5e1fg3s86d', 'side': 'ask', 'ord_type': 'limit', 'price': '3000000.0', 'state': 'wait', 'market': 'KRW-ETH', 'created_at': '2022-02-27T01:43:36+09:00', 'volume': '1.5', 'remaining_volume': '1.5', 'reserved_fee': '0.0', 'remaining_fee': '0.0', 'paid_fee': '0.0', 'locked': '0.01', 'executed_volume': '0.0', 'trades_count': 0}

 

- buy_market_order(ticker='KRW-ETH', price=100000)

KRW-ETH를 시장가에 100000원어치 매수

 

 

- sell_market_order(ticker='KRW-ETH', volume=1.5)

KRW-ETH를 시장가에 1.5개 매수

 

 

 

 

결과로 return 되는 dictionary의 주요한 항목들의 의미는 다음과 같습니다.

 

uuid = 거래 ID같은 개념이라고 보면 됩니다. 이 ID를 이용해서 걸려있는 매수/매도 주문을 취소할 수도 있습니다.

side = bid인 경우 매수 주문, ask인 경우 매도 주문을 의미합니다.

price = 매수/매도할 가격입니다.

market = 매수/매도할 코인의 ticker입니다.

createdat = 매수/매도 주문이 생성된 시간입니다.

volume = 매수/매도할 개수입니다.

remaining_volume = 남아있는 매수/매도 개수입니다.

 

 

 

 

 

 

728x90
반응형
Comments