forked from appcorner/bitkub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.py
65 lines (50 loc) · 1.66 KB
/
sample.py
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
61
62
63
64
65
from bitkub import Bitkub
import time
API_KEY = ""
API_SECRET = ""
bitkub = Bitkub()
bitkub.set_api_key(API_KEY)
bitkub.set_api_secret(API_SECRET)
coin_name = 'BTC'
symbol = f'THB_{coin_name}'
amountTHB = 15.00
# Get last price
ticker = bitkub.ticker(symbol)
last_price = ticker[symbol]['last']
print(f'Last price: {last_price}')
# Get lowestAsk price
ask_price = ticker[symbol]['lowestAsk']
print(f'Ask price: {ask_price}')
# Get highestBid price
bid_price = ticker[symbol]['highestBid']
print(f'Bid price: {bid_price}')
# buy order
buy_order = bitkub.place_bid(sym=symbol, amt=amountTHB, rat=ask_price)
print(f'Buy order: {buy_order}')
# wait 5 seconds for order to be filled
time.sleep(5)
# get balance
balance = bitkub.balances()
# print(balance)
symbol_balance = balance['result'][coin_name]['available']
print(f'Balance: {symbol_balance}')
# sell order
# sell_order = bitkub.place_ask(sym=symbol, amt=symbol_balance, rat=bid_price)
# print(f'Sell order: {sell_order}')
# sell order by fiat
coinTHB = symbol_balance*bid_price
sell_order = bitkub.place_ask_by_fiat(sym=symbol, amt=coinTHB, rat=bid_price)
print(f'Sell order by fiat: {sell_order}')
# wait 5 seconds for order to be filled
time.sleep(5)
# get balance
balance = bitkub.balances()
symbol_balance = balance['result'][coin_name]['available']
print(f'Balance: {symbol_balance}')
# print(bitkub.crypto_generate_address(sym=symbol))
# print(bitkub.crypto_address())
# print(bitkub.crypto_deposit_history())
# print(bitkub.crypto_withdraw_history())
# print(bitkub.fiat_accounts())
# print(bitkub.fiat_deposit_history())
# print(bitkub.fiat_withdraw_history())