-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
122 lines (89 loc) · 2.41 KB
/
Copy pathcli.py
File metadata and controls
122 lines (89 loc) · 2.41 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import argparse
from binance.exceptions import BinanceAPIException
from bot.orders import (
place_market_order,
place_limit_order
)
from bot.validators import (
validate_side,
validate_order_type,
validate_quantity,
validate_symbol
)
from bot.logging_config import logger
try:
parser = argparse.ArgumentParser(
description="Binance Futures Trading Bot"
)
parser.add_argument(
"--symbol",
required=True,
help="Trading Symbol (e.g. BTCUSDT)"
)
parser.add_argument(
"--side",
required=True,
help="BUY or SELL"
)
parser.add_argument(
"--type",
required=True,
help="MARKET or LIMIT"
)
parser.add_argument(
"--quantity",
required=True,
type=float,
help="Order Quantity"
)
parser.add_argument(
"--price",
type=float,
help="Limit Price"
)
args = parser.parse_args()
symbol = validate_symbol(args.symbol)
side = validate_side(args.side)
order_type = validate_order_type(args.type)
quantity = validate_quantity(args.quantity)
print("\n===== ORDER SUMMARY =====")
print("Symbol :", symbol)
print("Side :", side)
print("Type :", order_type)
print("Qty :", quantity)
if order_type == "MARKET":
response = place_market_order(
symbol,
side,
quantity
)
else:
if args.price is None:
raise ValueError(
"Price is required for LIMIT orders"
)
response = place_limit_order(
symbol,
side,
quantity,
args.price
)
print("\n===== ORDER RESPONSE =====")
print("Order ID:", response.get("orderId"))
print("Status:", response.get("status"))
print("Executed Qty:", response.get("executedQty"))
if "avgPrice" in response:
print("Average Price:", response.get("avgPrice"))
print("\nORDER SUCCESSFUL")
except BinanceAPIException as e:
logger.exception(e)
print("\nBinance API Error")
print(e)
except ValueError as e:
logger.exception(e)
print("\nValidation Error")
print(e)
except Exception as e:
logger.exception(e)
print("\nUnexpected Error")
print(e)