示例#1
0
def analyse_messages(messages, active_trade):
    analysis = post_analysis.Dax()
    for m in messages:
        if analysis.find(m['message']):
            print m['message']
            notification.play_audio(AUDIO_FILE)
            
            if active_trade:
                # Trade is still active -> close it
                # TODO: Check if previous trade was stopped out
                print 'Previous trade still active -> aborted'
                return active_trade
            else:
                # Execute trade
                longshort = analysis.get_longshort(m['message'])
                start = analysis.get_start(m['message'])
                stop = analysis.get_stop(m['message'])
                if stop > 100:
                    # The stop is denoted as distance from trade start
                    stop = (start - stop) if (longshort == LONG) else (stop - start)
                
                print '@ {}'.format(start)
                print 'Long' if longshort == LONG else 'Short'
                print 'Stop {}'.format(stop)
                print 'Executing Trade...'
                active_trade = trade.Trade(m['post_id'], 'dax', start, N_TVK, longshort, stop)
                print 'Checking if Trade is active...'
                time.sleep(0.2)
                if active_trade.is_active():
                    print 'Trade active with id ' + active_trade.trade_id
                    return active_trade
                else:
                    print 'ERROR: Trade not open'
                    return None
示例#2
0
def analyse_comments(comments, active_trade):
    analysis = post_analysis.Dax()
    for c in comments:
        if analysis.find_tvk(c['text']):
            print 'Comment: ' + c['text']
            notification.play_audio(AUDIO_FILE)
            # Close one contract
            active_trade.close_position(1)
            if active_trade.num_contracts == 0:
                print 'Trade completed'
                return None # Trade completed
    
    return active_trade