forked from Kucoin/kucoin-universal-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_get_started.py
More file actions
60 lines (49 loc) · 2.07 KB
/
example_get_started.py
File metadata and controls
60 lines (49 loc) · 2.07 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import logging
import os
from kucoin_universal_sdk.api.client import DefaultClient
from kucoin_universal_sdk.generate.spot.market.model_get_part_order_book_req import GetPartOrderBookReqBuilder
from kucoin_universal_sdk.model.client_option import ClientOptionBuilder
from kucoin_universal_sdk.model.constants import GLOBAL_API_ENDPOINT, GLOBAL_FUTURES_API_ENDPOINT, \
GLOBAL_BROKER_API_ENDPOINT
from kucoin_universal_sdk.model.transport_option import TransportOptionBuilder
def example():
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
# Retrieve API secret information from environment variables
key = os.getenv("API_KEY", "")
secret = os.getenv("API_SECRET", "")
passphrase = os.getenv("API_PASSPHRASE", "")
# Set specific options, others will fall back to default values
http_transport_option = (
TransportOptionBuilder()
.set_keep_alive(True)
.set_max_pool_size(10)
.set_max_connection_per_pool(10)
.build()
)
# Create a client using the specified options
client_option = (
ClientOptionBuilder()
.set_key(key)
.set_secret(secret)
.set_passphrase(passphrase)
.set_spot_endpoint(GLOBAL_API_ENDPOINT)
.set_futures_endpoint(GLOBAL_FUTURES_API_ENDPOINT)
.set_broker_endpoint(GLOBAL_BROKER_API_ENDPOINT)
.set_transport_option(http_transport_option)
.build()
)
client = DefaultClient(client_option)
# Get the Restful Service
kucoin_rest_service = client.rest_service()
spot_market_api = kucoin_rest_service.get_spot_service().get_market_api()
# Query for part orderbook depth data. (aggregated by price)
request = GetPartOrderBookReqBuilder().set_symbol("BTC-USDT").set_size("20").build()
response = spot_market_api.get_part_order_book(request)
logging.info(f"time={response.time}, sequence={response.sequence}, "
f"bids={response.bids}, asks={response.asks}")
if __name__ == "__main__":
example()