forked from sammchardy/python-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation.py
More file actions
54 lines (43 loc) · 1.47 KB
/
Copy pathvalidation.py
File metadata and controls
54 lines (43 loc) · 1.47 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
#!/usr/bin/env python
# coding=utf-8
from .exceptions import BinanceOrderUnknownSymbolException, \
BinanceOrderInactiveSymbolException, \
BinanceOrderMinPriceException, \
BinanceOrderMinAmountException, \
BinanceOrderMinTotalException
"""
Use details from
https://www.binance.com/exchange/public/product
minTrade means min Amount
ticksize means min price
Notional limits from https://binance.zendesk.com/hc/en-us/articles/115000594711
BTC - 0.001
ETH - 0.01
USDT - 1
"""
NOTIONAL_LIMITS = {
'BTC': 0.001,
'ETH': 0.01,
'USDT': 1
}
def validate_order(params, products):
print(params)
if params['symbol'] not in products:
raise BinanceOrderUnknownSymbolException(params['symbol'])
limits = products[params['symbol']]
if not limits['active']:
raise BinanceOrderInactiveSymbolException(params['symbol'])
price = float(params['price'])
quantity = float(params['quantity'])
# check price
if price < float(limits['tickSize']):
raise BinanceOrderMinPriceException(limits['tickSize'])
# check order amount
min_trade = float(limits['minTrade'])
if quantity / min_trade - int(quantity / min_trade) > 0.0:
raise BinanceOrderMinAmountException(limits['minTrade'])
# check order total
total = float(params['price']) * float(params['quantity'])
notional_total = NOTIONAL_LIMITS[limits['quoteAsset']]
if total < notional_total:
raise BinanceOrderMinTotalException(notional_total)