forked from EasyAI/Simple-Binance-Trader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrader_configuration.py
82 lines (60 loc) · 2.35 KB
/
trader_configuration.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#! /usr/bin/env python3
import numpy as np
import technical_indicators as TI
## Minimum price rounding.
pRounding = 8
#time, open, high, low, close, volume
def technical_indicators(candles):
indicators = {}
open_prices = [candle[1] for candle in candles]
high_prices = [candle[2] for candle in candles]
low_prices = [candle[3] for candle in candles]
close_prices = [candle[4] for candle in candles]
indicators.update({'MACD':TI.get_MACD(close_prices)})
return(indicators)
def other_conditions(custom_conditional_data, trade_information, indicators):
custom_conditional_data = custom_conditional_data
can_order = True
trade_information.update({'canOrder':can_order})
return(custom_conditional_data, trade_information)
def sell_conditions(custom_conditional_data, trade_information, indicators, prices, candles):
'''
The current order types that are supported are
limit orders = LIMIT
stop loss orders = STOP_LOSS_LIMIT
market orders = MARKET
'''
price = side = description = ptype = None
orderType = 'WAIT'
## Set the indicators used to test the conditions:
macd = indicators['MACD']
## Logic for SELL conditions.
if macd[0]['macd'] < macd[0]['signal']:
orderType = 'SIGNAL'
side = 'SELL'
description = 'Signal buy order'
ptype = 'MARKET'
elif False:
price = ''
orderType = 'STOP_LOSS'
side = 'SELL'
description = 'Signal buy order'
ptype = 'STOP_LOSS_LIMIT'
return({'price':price, 'orderType':orderType, 'side':side, 'description':description, 'ptype':ptype})
def buy_conditions(custom_conditional_data, trade_information, indicators, prices, candles):
'''
The current order types that are supported are
limit orders = LIMIT
market orders = MARKET
'''
price = side = description = ptype = None
orderType = 'WAIT'
## Set the indicators used to test the conditions:
macd = indicators['MACD']
## Logic for BUY conditions.
if macd[0]['hist'] > 0 and macd[0]['macd'] > macd[1]['macd'] and macd[0]['macd'] > macd[0]['signal']:
orderType = 'SIGNAL'
side = 'BUY'
description = 'Signal buy order'
ptype = 'MARKET'
return({'price':price, 'orderType':orderType, 'side':side, 'description':description, 'ptype':ptype})