forked from PythonForForex/Binance-api-step-by-step-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuy_bnb.py
More file actions
29 lines (21 loc) · 665 Bytes
/
buy_bnb.py
File metadata and controls
29 lines (21 loc) · 665 Bytes
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
import os
from binance.client import Client
# init
api_key = os.environ.get('binance_api')
api_secret = os.environ.get('binance_secret')
client = Client(api_key, api_secret)
# functions
def topup_bnb(min_balance: float, topup: float):
''' Top up BNB balance if it drops below minimum specified balance '''
bnb_balance = client.get_asset_balance(asset='BNB')
bnb_balance = float(bnb_balance['free'])
if bnb_balance < min_balance:
qty = round(topup - bnb_balance, 5)
print(qty)
order = client.order_market_buy(symbol='BNBUSDT', quantity=qty)
return order
return False
# example
min_balance = 1.0
topup = 2.5
order = topup_bnb(min_balance, topup)