-
Notifications
You must be signed in to change notification settings - Fork 0
/
Binance_PendingSpotOrderWithTime.py
48 lines (43 loc) · 1.61 KB
/
Binance_PendingSpotOrderWithTime.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
import time
from binance.client import Client
import configparser
def PandingOrder(client, symbol, side, quantity, price, time_in_force):
# Place a limit order
# symbol = 'BUSDUSDT' # symbol to trade
# side = 'BUY' # side of the order
# quantity = 100 # amount to buy/sell
# price = 0.2 # price to buy/sell at
# time_in_force = 'GTC' # time in force of the order
response = client.create_order(
symbol=symbol,
side=side,
type='LIMIT',
timeInForce=time_in_force,
quantity=quantity,
price=price
)
# Print the response
return response
if __name__ == '__main__':
# Read Env config
config = configparser.ConfigParser()
config.read('config.ini')
# Set up the Binance API client
api_key = config['Binance']['binance_api'] # Fill the key in config file
api_secret = config['Binance']['binance_secret'] # Fill the key in config file
client = Client(api_key, api_secret)
timestamp = 1655834 # timestamp(fill the time with the coin can be exchange)
# main
while (True):
try:
if (timestamp < time.time()):
res = PandingOrder(client=client, symbol='BUSDUSDT', side='BUY', quantity=100, price=0.2,
time_in_force='GTC')
if res['orderId'] > -1:
print("Successful Pending Limit Order")
print(res)
break
else:
print("Waiting for time up...")
except Exception:
print("Something Error")