Exemple #1
0
 def __init__(self, uid):
     Id.__init__(self)
     Position.__init__(self)
     PixelModifierList.__init__(self)
     ChannelList.__init__(self)
     self.uid = uid
     self.type = 'Pixel'
Exemple #2
0
	def __init__( self, uid ):
		Id.__init__( self )
		Position.__init__( self )
		PixelModifierList.__init__( self )
		ChannelList.__init__( self )
		self.uid = uid
		self.type = 'Pixel'
Exemple #3
0
    def __init__(self, uid):
        Id.__init__(self)
        Schedule.__init__(self)
        Position.__init__(self)
        self.type = 'ScanCode'
        self.uid = uid

        # This uid is used for any post-processing of the uid
        # The original uid is maintained in case it is needed
        self.updated_uid = None
Exemple #4
0
    def __init__(self, uid):
        Id.__init__(self)
        Schedule.__init__(self)
        Position.__init__(self)
        self.type = 'ScanCode'
        self.uid = uid

        # By default, interconnect_id of 0
        # Will be set during the merge process if it needs to change
        self.interconnect_id = 0
Exemple #5
0
	def __init__( self, uid ):
		Id.__init__( self )
		Schedule.__init__( self )
		Position.__init__( self )
		self.type = 'ScanCode'
		self.uid = uid

		# By default, interconnect_id of 0
		# Will be set during the merge process if it needs to change
		self.interconnect_id = 0
Exemple #6
0
 def json(self):
     '''
     JSON representation of ScanCodeId
     '''
     output = Id.json(self)
     output.update(Schedule.json(self))
     output.update(Position.json(self))
     return output
Exemple #7
0
def check_position(candle: OHLCV, trade):
    # Check position status
    global max_margin_used
    global pos
    global pl
    global plot_sell_index
    global plot_sell_value
    global plot_buy_index
    global plot_buy_value
    global plot_pl_index
    global plot_pl_value
    if pos.status == 'ACTIVE':
        pos.calc(trade)
        if not pos.trailing and pos.pl_pct <= -add_percent and abs(pos.amount * pos.base) < margin:
            pos.add(trade['price'], pos.amount)
            pos.calc(trade)
            logging.info('Add ' + str(pos.amount) + '@' + str(trade['price']) + '- base: ' + str(pos.base))
        if not pos.trailing and pos.pl_pct <= -stop_pct:
            pos.close()
        if not pos.trailing and pos.pl_pct >= trailing_profit_pct:
            pos.trailing_stop(trailing_stop_pct)
        if pos.status != "CLOSED" and pos.trailing:
            pos.trailing_stop(trailing_stop_pct)
    if pos.status == "CLOSED":
        if pos.trailing:
            logging.info('Close position by trailing @ ' + str(trade['price']) + ' @ ' + str(pos.pl_pct))
        else:
            logging.info('Close position by stop-loss @ ' + str(trade['price']) + ' @ ' + str(pos.pl_pct))
        if pos.amount > 0:
            plot_sell_index.append(datetime.fromtimestamp(float(candle.start / 1000)))
            plot_sell_value.append(candle.close)
        else:
            plot_buy_index.append(datetime.fromtimestamp(float(candle.start / 1000)))
            plot_buy_value.append(candle.close)
        pl += pos.pl - (pos.fee * 2)
        plot_pl_index.append(datetime.fromtimestamp(float(candle.start / 1000)))
        plot_pl_value.append(pl)
        logging.info('PL: ' + str(pl))
        positions.append(pos)
        if pos.amount * pos.base > max_margin_used:
            max_margin_used = pos.amount * pos.base
        pos = Position()
Exemple #8
0
trailing_profit_pct = 2
trailing_stop_pct = 0.2
# Stop loss percent
stop_pct = 10

# print(start, end)


# Get trades data from db
trade_cursor = trades.find({"selector": selector, "time": {"$lte": end, "$gte": start}}).sort([("time", 1)])
# Back testing
candle = OHLCV()
macd = MACD(macd_short, macd_long)
strategy = Extend(min_len=min_length, max_len=max_length, diff=diff)
order = None
pos = Position()
positions = []
last_signal = None
pl = 0
max_margin_used = 0
plot_price_index = []
plot_price_value = []
plot_buy_index = []
plot_buy_value = []
plot_sell_index = []
plot_sell_value = []
plot_pl_index = []
plot_pl_value = []
plot_macd_short = []
plot_macd_long = []
Exemple #9
0
 def setupPosition(self, pair):
     return Position(pair)
Exemple #10
0
trade_cursor = trades.find({
    "selector": selector,
    "time": {
        "$lte": end,
        "$gte": start
    }
}).sort([("time", 1)])
# Back testing
candle = OHLCV()
macd = MACD(macd_short, macd_long)
strategy = Retrace(min_len=min_length, max_len=max_length, diff=diff)
# vb_strategy = VolumeBased(min_len=min_length, max_len=max_length, diff=diff)
# vsr_strategy = VolumeSupportResistance(min_len=min_length, max_len=max_length, diff=diff)
# strategy = Independence(min_len=min_length, max_len=max_length, diff=diff)
order = None
pos = Position()
positions = []
last_signal = None
pl = 0
plot_price_index = []
plot_price_value = []
plot_buy_index = []
plot_buy_value = []
plot_sell_index = []
plot_sell_value = []
plot_pl_index = []
plot_pl_value = []
plot_macd_short = []
plot_macd_long = []
for trade in trade_cursor:
    # Add trade to OHLCV candle