Beispiel #1
0
    def SendTrade(self, _price_, _int_price_, _size_requested_, _buysell_):
        #self.Dump()

        #print('SendTrade Called')
        #print _price_, _int_price_, _size_requested_, _buysell_
        #exit()
        print('Send'),
        if (_size_requested_ <= 0):
            print 'SendTrade: _size_requested_ <= 0'
            return
        order_ = BaseOrder()
        order_.security_name_ = self.shortcode_
        order_.buysell_ = _buysell_
        order_.price_ = _price_
        order_.int_price_ = _int_price_
        order_.size_requested_ = _size_requested_
        order_.size_remaining_ = _size_requested_
        order_.order_status_ = 'Conf' # In original order_manager_, this would have been 'None' -> 'Seqd' -> 'Conf', 
        #we assume that once an order is sent to the exchange, it will always get confirmed, also we assume delay to be zero!!
        order_.client_assigned_order_sequence_ = self.client_assigned_order_sequence_
        self.client_assigned_order_sequence_ += 1
        # since we will have only one client, so caos and saos will be same (so we don't need the sequenced thingy!)
        
        if (_buysell_ == 'B'): # Buy
            t_bid_index_ = self.GetBidIndex(_int_price_)
            #self.sum_bid_unconfirmed_[t_bid_index_] += _size_requested_
            #self.AdjustTopBottomUnconfirmedBidIndexes(t_bid_index_)
            #self.unsequenced_bids_.append(order_)
            #self.num_unconfirmed_orders_ += 1
            self.bid_order_vec_[t_bid_index_].append(order_)
            order_.server_assigned_order_sequence_ = order_.client_assigned_order_sequence_ # hack
            self.AdjustTopBottomOrderVecBidIndexes(t_bid_index_)
            self.sum_bid_confirmed_[t_bid_index_] += order_.size_requested_
            self.AdjustTopBottomConfirmedBidIndexes(t_bid_index_)
            self.sum_bid_sizes_ += _size_requested_
        else:
            t_ask_index_ = self.GetAskIndex(_int_price_)
#             self.sum_ask_unconfirmed_[t_ask_index_] += _size_requested_
#             self.AdjustTopBottomUnconfirmedAskIndexes(t_ask_index_)
#             self.unsequenced_bids_.append(order_)
#             self.num_unconfirmed_orders_ += 1
            self.ask_order_vec_[t_ask_index_].append(order_)
            order_.server_assigned_order_sequence_ = order_.client_assigned_order_sequence_ # hack
            self.AdjustTopBottomOrderVecAskIndexes(t_ask_index_)
            self.sum_ask_confirmed_[t_ask_index_] += order_.size_requested_
            self.AdjustTopBottomConfirmedAskIndexes(t_ask_index_)
            self.sum_ask_sizes_ += _size_requested_
        
        order_.dump()
        #self.Dump()

        self.base_trader_.SendTrade(order_)
        
        self.total_size_placed_ += _size_requested_
        self.send_order_count_ += 1
Beispiel #2
0
 def SendOrderExch(self, _server_assigned_client_id_, _security_name_,
                   _buysell_, _price_, _size_requested_, _int_price_,
                   _client_assigned_order_sequence_):
     #print 'SendOrderExch'
     order_ = BaseOrder()
     order_.security_name_ = _security_name_
     order_.buysell_ = _buysell_
     order_.price_ = _price_
     order_.size_remaining_ = _size_requested_
     order_.int_price_ = _int_price_
     order_.order_status_ = 'Conf'
     order_.size_requested_ = _size_requested_  # Check
     order_.num_events_seen_ = 0
     order_.client_assigned_order_sequence_ = _client_assigned_order_sequence_
     order_.server_assigned_order_sequence_ = self.server_assigned_order_sequence_
     order_.server_assigned_client_id_ = _server_assigned_client_id_
     self.server_assigned_order_sequence_ += 1
     # Not keeping masked_from_market_data_asks_map_ and alone_above_best_market
     if (order_.buysell_ == 'B'):
         order_.queue_size_behind_ = 0
         order_.queue_size_ahead_ = 0
         if (order_.int_price_ >=
                 self.dep_market_view_.bestask_int_price()):
             order_.int_price_ = self.dep_market_view_.bestask_int_price()
             order_.price_ = self.dep_market_view_.bestask_price()
             if (self.dep_market_view_.bestask_size() >=
                     order_.size_remaining()):
                 size_executed_ = order_.ExecuteRemaining()
                 self.client_position_map_[
                     _server_assigned_client_id_] += size_executed_
                 #self.global_position_to_send_map_[_server_assigned_client_id_] += size_executed_
                 self.BroadcastExecNotification(_server_assigned_client_id_,
                                                order_)
                 print('executed')
             else:
                 size_executed_ = order_.MatchPartial(
                     self.dep_market_view_.bestask_size())
                 self.client_position_map_[
                     _server_assigned_client_id_] += size_executed_
                 #self.global_position_to_send_map_[_server_assigned_client_id_] += size_executed_
                 self.BroadcastExecNotification(_server_assigned_client_id_,
                                                order_)
                 if (not order_.int_price_
                         in self.intpx_to_bid_order_vec_.keys()):
                     self.intpx_to_bid_order_vec_[order_.int_price_] = []
                 self.intpx_to_bid_order_vec_[order_.int_price_].append(
                     order_)
                 print('liquidity')
         else:
             #print 'Adding Buy Liquidity order'
             if (not order_.int_price_
                     in self.intpx_to_bid_order_vec_.keys()):
                 self.intpx_to_bid_order_vec_[order_.int_price_] = []
             self.intpx_to_bid_order_vec_[order_.int_price_].append(order_)
             print('liquidity')
     else:
         order_.queue_size_behind_ = 0
         order_.queue_size_ahead_ = 0
         if (order_.int_price_ <=
                 self.dep_market_view_.bestbid_int_price()):
             order_.int_price_ = self.dep_market_view_.bestbid_int_price()
             order_.price_ = self.dep_market_view_.bestbid_price()
             if ((self.dep_market_view_.bestbid_size()) >=
                     order_.size_remaining()):
                 size_executed = order_.ExecuteRemaining()
                 self.client_position_map_[
                     _server_assigned_client_id_] -= size_executed
                 #self.global_position_to_send_map_[_server_assigned_client_id_] += size_executed
                 self.BroadcastExecNotification(_server_assigned_client_id_,
                                                order_)
                 print('executed')
             else:
                 size_executed_ = order_.MatchPartial(
                     self.dep_market_view.bestbid_size())
                 self.client_position_map_[
                     _server_assigned_client_id_] -= size_executed_
                 #self.global_position_to_send_map_[_server_assigned_client_id_] += size_executed_
                 self.BroadcastExecNotification(_server_assigned_client_id_,
                                                order_)
                 if (not order_.int_price_
                         in self.intpx_to_ask_order_vec_.keys()):
                     self.intpx_to_ask_order_vec_[order_.int_price_] = []
                 self.intpx_to_ask_order_vec_[order_.int_price_].append(
                     order_)
                 print('liquidity')
         else:
             if (not order_.int_price_
                     in self.intpx_to_ask_order_vec_.keys()):
                 self.intpx_to_ask_order_vec_[order_.int_price_] = []
             self.intpx_to_ask_order_vec_[order_.int_price_].append(order_)
             print('liquidity')
 def SendOrderExch(
     self,
     _server_assigned_client_id_,
     _security_name_,
     _buysell_,
     _price_,
     _size_requested_,
     _int_price_,
     _client_assigned_order_sequence_,
 ):
     # print 'SendOrderExch'
     order_ = BaseOrder()
     order_.security_name_ = _security_name_
     order_.buysell_ = _buysell_
     order_.price_ = _price_
     order_.size_remaining_ = _size_requested_
     order_.int_price_ = _int_price_
     order_.order_status_ = "Conf"
     order_.size_requested_ = _size_requested_  # Check
     order_.num_events_seen_ = 0
     order_.client_assigned_order_sequence_ = _client_assigned_order_sequence_
     order_.server_assigned_order_sequence_ = self.server_assigned_order_sequence_
     order_.server_assigned_client_id_ = _server_assigned_client_id_
     self.server_assigned_order_sequence_ += 1
     # Not keeping masked_from_market_data_asks_map_ and alone_above_best_market
     if order_.buysell_ == "B":
         order_.queue_size_behind_ = 0
         order_.queue_size_ahead_ = 0
         if order_.int_price_ >= self.dep_market_view_.bestask_int_price():
             order_.int_price_ = self.dep_market_view_.bestask_int_price()
             order_.price_ = self.dep_market_view_.bestask_price()
             if self.dep_market_view_.bestask_size() >= order_.size_remaining():
                 size_executed_ = order_.ExecuteRemaining()
                 self.client_position_map_[_server_assigned_client_id_] += size_executed_
                 # self.global_position_to_send_map_[_server_assigned_client_id_] += size_executed_
                 self.BroadcastExecNotification(_server_assigned_client_id_, order_)
                 print ("executed")
             else:
                 size_executed_ = order_.MatchPartial(self.dep_market_view_.bestask_size())
                 self.client_position_map_[_server_assigned_client_id_] += size_executed_
                 # self.global_position_to_send_map_[_server_assigned_client_id_] += size_executed_
                 self.BroadcastExecNotification(_server_assigned_client_id_, order_)
                 if not order_.int_price_ in self.intpx_to_bid_order_vec_.keys():
                     self.intpx_to_bid_order_vec_[order_.int_price_] = []
                 self.intpx_to_bid_order_vec_[order_.int_price_].append(order_)
                 print ("liquidity")
         else:
             # print 'Adding Buy Liquidity order'
             if not order_.int_price_ in self.intpx_to_bid_order_vec_.keys():
                 self.intpx_to_bid_order_vec_[order_.int_price_] = []
             self.intpx_to_bid_order_vec_[order_.int_price_].append(order_)
             print ("liquidity")
     else:
         order_.queue_size_behind_ = 0
         order_.queue_size_ahead_ = 0
         if order_.int_price_ <= self.dep_market_view_.bestbid_int_price():
             order_.int_price_ = self.dep_market_view_.bestbid_int_price()
             order_.price_ = self.dep_market_view_.bestbid_price()
             if (self.dep_market_view_.bestbid_size()) >= order_.size_remaining():
                 size_executed = order_.ExecuteRemaining()
                 self.client_position_map_[_server_assigned_client_id_] -= size_executed
                 # self.global_position_to_send_map_[_server_assigned_client_id_] += size_executed
                 self.BroadcastExecNotification(_server_assigned_client_id_, order_)
                 print ("executed")
             else:
                 size_executed_ = order_.MatchPartial(self.dep_market_view.bestbid_size())
                 self.client_position_map_[_server_assigned_client_id_] -= size_executed_
                 # self.global_position_to_send_map_[_server_assigned_client_id_] += size_executed_
                 self.BroadcastExecNotification(_server_assigned_client_id_, order_)
                 if not order_.int_price_ in self.intpx_to_ask_order_vec_.keys():
                     self.intpx_to_ask_order_vec_[order_.int_price_] = []
                 self.intpx_to_ask_order_vec_[order_.int_price_].append(order_)
                 print ("liquidity")
         else:
             if not order_.int_price_ in self.intpx_to_ask_order_vec_.keys():
                 self.intpx_to_ask_order_vec_[order_.int_price_] = []
             self.intpx_to_ask_order_vec_[order_.int_price_].append(order_)
             print ("liquidity")