빗썸 API 프로그래밍 - 1steemCreated with Sketch.

in #kr6 years ago

빗썸 API Reference Code 받기

빗썸 홈페이지에 접속하여 홈페이지 하단에 "API"클릭
"4. Sample Code"에서 원하는 언어의 Reference Code를 다운 받아서 개발을 시작하면 된다.
필자는 파이썬을 이용한다.

파이썬 Reference Code를 받으면 두개의 파일이 존재한다.

xcoin_api_client.py
api_test.py

xcoin_api_client.py : 빗썸 API Server와 통신을 담당하는 부분이다. 개발자는 수정할 부분이 없지만...개발하다 보면 저거 다 수정해야만 할 것 이다. 하지만 지금은 그게 목적이 아니니 pass!!

api_test.py: 이 파일에 자신이 빗섬 API를 만들어 나가면 된다. 만드는 방법은 Reference Code를 다운 받은 페이지에 빗썸에서 제공하는 API 매뉴얼을 보고 만들면 된다....고 필자가 적을것이면 이 글을 적을 필요가 없겠지?? ^^

지금부터 api_test.py 파일에 API들을 하나씩 만들어 보자.
먼저 아래와 같이 빗썸 홈페이지에서 API 활성하여 받은 Connect Key와 Secret Key를 입력하여야 한다.

api_key = "자신이 받은 Connect Key 입력";
api_secret = "자신이 받은 Secret Key 입력";

Orderbook 코딩

빗썸에서 제공하는 매뉴얼을 보면서 코드를 확인하길 바란다.

함수명: bithumbOrderbook
parameter: currency

def bithumbOrderbook(currency):
    result = api.xcoinApiCall("/public/orderbook/"+currency, rgParams)
    return result

함수 호출 방법

result =bithumbOrderbook("BTC")
print(result)

함수 Retrun 결과

{'status': '0000', 'data': {'timestamp': '1534701828977', 'payment_currency': 'KRW', 'order_currency': 'BTC', 'bids': [{'quantity': '0.0025', 'price': '7316000'}, {'quantity': '0.001', 'price': '7309000'}, {'quantity': '0.2778', 'price': '7308000'}, {'quantity': '0.6125', 'price': '7307000'}, {'quantity': '0.3477', 'price': '7305000'}, {'quantity': '0.2296', 'price': '7304000'}, {'quantity': '0.427', 'price': '7303000'}, {'quantity': '4.7527', 'price': '7301000'}, {'quantity': '14.1503', 'price': '7300000'}, {'quantity': '0.4267', 'price': '7299000'}, {'quantity': '0.0512', 'price': '7298000'}, {'quantity': '0.371', 'price': '7297000'}, {'quantity': '0.1738', 'price': '7296000'}, {'quantity': '0.3552', 'price': '7295000'}, {'quantity': '0.854', 'price': '7294000'}, {'quantity': '0.3123', 'price': '7293000'}, {'quantity': '0.058', 'price': '7292000'}, {'quantity': '2.9732', 'price': '7291000'}, {'quantity': '1.7687', 'price': '7290000'}, {'quantity': '3.8242', 'price': '7289000'}], 'asks': [{'quantity': '0.0224', 'price': '7328000'}, {'quantity': '0.005', 'price': '7355000'}, {'quantity': '0.0013', 'price': '7356000'}, {'quantity': '0.0016', 'price': '7359000'}, {'quantity': '0.051', 'price': '7361000'}, {'quantity': '1.1151', 'price': '7362000'}, {'quantity': '0.001', 'price': '7363000'}, {'quantity': '0.99', 'price': '7372000'}, {'quantity': '0.2708', 'price': '7375000'}, {'quantity': '0.0026', 'price': '7377000'}, {'quantity': '0.2204', 'price': '7379000'}, {'quantity': '1.0831', 'price': '7380000'}, {'quantity': '0.4314', 'price': '7381000'}, {'quantity': '1.98', 'price': '7384000'}, {'quantity': '19.906', 'price': '7390000'}, {'quantity': '0.0016', 'price': '7394000'}, {'quantity': '0.0016', 'price': '7396000'}, {'quantity': '0.0667', 'price': '7398000'}, {'quantity': '0.0998', 'price': '7400000'}, {'quantity': '0.0013', 'price': '7401000'}]}}

너무 길어서 확인 하기 힘드니 빗썸 API 매뉴얼에서 제공하는 결과를 활용하도록 하겠다.

{
    "status"    : "0000",
    "data"      : {
        "timestamp"         : 1417142049868,
        "order_currency"    : "BTC",
        "payment_currency"  : "KRW",
        "bids": [
            {
                "quantity"  : "6.1189306",
                "price"     : "504000"
            },
            {
                "quantity"  : "10.35117828",
                "price"     : "503000"
            }
        ],
        "asks": [
            {
                "quantity"  : "2.67575",
                "price"     : "506000"
            },
            {
                "quantity"  : "3.54343",
                "price"     : "507000"
            }
        ]
    }
}

빗썸 Orderbook을 보는 법을 알아 보았다. 보다시피 코드가 무지 심플하다. 할게 없다.
여기서 필자는 왜 파이썬을 사용하였는지 알수 있다. 결국 API를 활용하여 함수를 만들때, 빗썸의 기능을 호출하는 함수는 무지 심플하다. 결국 호출후에 받아오는 Return 값을 잘 처리하여야 하는데, 이를 처리하는데 파이썬 만큼 간략하게 다루는 언어는 없을거라 본다.

오늘은 아주 간단하게 Orderbook 정보를 가져오는 것을 해보았다.
일단 Orderbook을 가져왔다면, 빗썸 API구현의 50%는 한 것이나 다름없다.
이 글을 읽는 독자들 모두 Good luck!

Sort:  

저는 문돌이라 이해 하기가 참 어렵습니다. 하하..ㅠ

공돌이인 저두 어렵습니다...

다음 연재도 기대 됩니다 !

네...종종 연재해드릴게요

Congratulations @hasworld! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes received

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Do not miss the last post from @steemitboard:
SteemitBoard and the Veterans on Steemit - The First Community Badge.

You can upvote this notification to help all Steemit users. Learn why here!

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63550.59
ETH 2644.53
USDT 1.00
SBD 2.81