示例#1
0
    def buy_shares(self, buy_this_value):
        """
        Responsible for buy share, doing in the fill-or-kill mode means delete order if not buy.
        Not need to cancel the order because the mode
        """
        the_price = Common.price_loop(self.SLEEP_TIME, self.SELL_NUM_ITERATIONS)
        Common.plog_info("The buy price from price_loop:" + str(the_price))
        response, result = quoteRest.set_order(config.venue, config.stock, config.account, the_price, buy_this_value,
                                               "buy", "fill-or-kill")
        Common.plog_info("Buying...")
        self.response_process(response, result)
        self.qty_filled_buy = result['totalFilled']
        if self.qty_filled_buy > 0:
            self.buy_price = result['price']
            self.all_buy += self.qty_filled_buy
            self.all_profit -= self.buy_price
            Common.plog_info(result)
            Common.plog_info("===============================================================")
            Common.plog_info("We buy number: "+str(self.qty_filled_buy)+" For price: " +str(self.buy_price)+" The all buy until now: "+
                             str(self.all_buy)+" The all profit: "+str(self.all_profit))
            Common.plog_info("===============================================================")
        else:
            Common.plog_info("Not success to buy this package. Built the new one")
            return False

        return True
示例#2
0
__author__ = 'eugenel'

import sys
import quoteRest
import config
import Common

sleep_time = 3
num_iterations = 10
price=Common.price_loop(sleep_time, num_iterations)

if price == 0:
    print "No Price need try again"
    sys.exit()

# Place a market order to buy stock:
response, result = quoteRest.set_order(config.venue, config.stock, config.account, price, 100)
print result

num_iterations=10
sleep_time = 3
if Common.is_deal_done(num_iterations, response, result, sleep_time):
    print "DEAL DONE!"
else:
    response, result = quoteRest.cancel_order(config.venue, config.stock, result['id'])
    print result
    print "NO DEAL!"