-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbinanceSell.py
50 lines (43 loc) · 1.53 KB
/
binanceSell.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
import ccxt
import json
import sys
import requests
import time
from datetime import datetime
coin = input("请输入交易币种(如 BNX ): ")
opentime = input("请输入开盘时间(2023-02-14 20:00:00): ")
sell_price = float(input("请输入卖出价格: "))
sell_amount = float(input("请输入卖出数量: "))
print("\nBinance 开盘抢卖...")
print("卖出:", coin)
print("价格:", sell_price)
print("数量:", sell_amount)
print("交易金额(USDT):", sell_price*sell_amount)
config = json.load(open('config.json'))
exchange = {}
def exchangeInit(config):
global exchange
exchange["spot"] = ccxt.binance(config["binance"])
exchange["spot"].load_markets()
def exchangeTrade(coin, exchange, sell_price, sell_amount):
pair = coin + "/USDT"
res = exchange["spot"].createLimitSellOrder(pair, sell_amount, sell_price)
return res
if __name__ == '__main__':
exchangeInit(config)
while True:
timeB = datetime.strptime(opentime, "%Y-%m-%d %H:%M:%S")
timeA = datetime.now()
if timeA > timeB:
try:
res = exchangeTrade(coin, exchange, sell_price, sell_amount)
print("发送成功!", res)
except Exception as e:
print("交易失败!", type(e).__name__, str(e))
pass
timeC = datetime.now()
print("交易耗时", (timeC - timeA).microseconds/1000, "毫秒")
break
else:
print("距离", timeB, "剩余时间:", (timeB - timeA), end = '\r')
time.sleep(0.05)