Repository navigation
Expand file tree
/
Copy pathcli.py
More file actions
67 lines (51 loc) · 2.07 KB
/
Copy pathcli.py
File metadata and controls
67 lines (51 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
61
62
63
64
65
66
67
import argparse
from bot.orders import place_order, build_preview, format_order_result
from bot.validators import validate_side, validate_type, validate_quantity, validate_price
from bot.logging_config import setup_logger
from rich import print
def main():
setup_logger()
parser = argparse.ArgumentParser(description="Binance Futures Testnet Bot")
parser.add_argument("--symbol", required=True, help="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, help="Order quantity")
parser.add_argument("--price", required=False, help="Required for LIMIT")
args = parser.parse_args()
try:
args.side = validate_side(args.side)
args.type = validate_type(args.type)
args.quantity = validate_quantity(args.quantity)
args.price = validate_price(args.price, required=(args.type == "LIMIT"))
print("\n[bold cyan]--- ORDER REQUEST ---[/bold cyan]")
print(f"[white]Symbol:[/white] {args.symbol}")
print(f"[white]Side:[/white] {args.side}")
print(f"[white]Type:[/white] {args.type}")
print(f"[white]Quantity:[/white] {args.quantity}")
if args.type == "LIMIT":
print(f"[white]Price:[/white] {args.price}")
preview = build_preview(
args.symbol,
args.side,
args.type,
args.quantity,
args.price
)
print("\n[yellow] Preview:[/yellow]")
print(preview)
confirm = input("Proceed? (y/n): ").lower()
if confirm != "y":
print("[red]Cancelled[/red]")
return
result = place_order(
symbol=args.symbol,
side=args.side,
order_type=args.type,
quantity=args.quantity,
price=args.price
)
print(format_order_result(result))
except Exception as e:
print(f"\n[bold red] ERROR:[/bold red] {str(e)}")
if __name__ == "__main__":
main()