-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathv6script.py
57 lines (43 loc) · 1.73 KB
/
v6script.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
51
52
53
54
55
56
57
# Import the ccxt library and the sleep function from the time module
import ccxt
from time import sleep
# Replace EXCHANGE_NAME with the name of the exchange you want to use
exchange_name = 'kucoin'
# Instantiate the Exchange class
exchange = getattr(ccxt, exchange_name)()
# Set sandbox mode to True or False
exchange.set_sandbox_mode(enabled=True)
# Set your API keys
exchange.apiKey = 'public-key'
exchange.secret = 'private-key'
exchange.password = 'passphrase'
# Set the symbol you want to trade on Kucoin
symbol = 'BTC/USDT'
# Set the amount of BTC you want to trade
amount = .1
# Create an infinite loop to trade continuously
while True:
# Fetch the current ticker information for the symbol
ticker = exchange.fetch_ticker(symbol)
# Check the current bid and ask prices
bid = ticker['bid']
ask = ticker['ask']
# Calculate the midpoint of the bid and ask prices
midpoint = (bid + ask) / 2
# Set the premium for the sell order
premium = 0.003
# Check if there are any open orders
open_orders = exchange.fetch_open_orders(symbol)
if not open_orders:
# Place a limit buy order at the midpoint price
order_id = exchange.create_order(symbol, 'limit', 'buy', amount, midpoint)
# Pause for a few seconds and check the status of the open orders
sleep(5)
open_orders = exchange.fetch_open_orders(symbol)
# Check if there are any open orders
if not open_orders:
# Place a limit sell order at the midpoint price plus the premium
order_id = exchange.create_order(symbol, 'limit', 'sell', amount, midpoint * (1 + premium))
# Pause for a few seconds and check the status of the open orders
sleep(5)
open_orders = exchange.fetch_open_orders(symbol)