-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
38 lines (34 loc) · 918 Bytes
/
main.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
import time
import requests
import json
def get_price(symbol):
url = f"https://api.binance.com/api/v3/ticker/price?symbol={symbol}"
response = requests.get(url)
price = float(json.loads(response.text)['price'])
return price
def trade(symbol, qty, side, price):
url = "https://api.binance.com/api/v3/order"
headers = {
"X-MBX-APIKEY": "<APIKEY>"
}
data = {
"symbol": symbol,
"side": side,
"type": "LIMIT",
"timeInForce": "GTC",
"quantity": qty,
"price": price,
}
response = requests.post(url, headers=headers, data=data)
print(response.text)
def main():
symbol = "BTCUSDT"
while True:
price = get_price(symbol)
if price > 60000:
trade(symbol, 1, "SELL", price)
else:
trade(symbol, 1, "BUY", price)
time.sleep(30)
if __name__ == "__main__":
main()