Example #1
0
    def execute(self):
        for order in self.orderbuf:

            utils.cancel_order(order)
        self.outgoingorder = []

        for order in self.buf:

            _temp = utils.new_order(common_pb2.NEW_ORDER, None, order[0],
                                    order[1], order[2], order[3], order[4],
                                    order[5])
            self.outgoingorder.append(_temp)
        self.buf = []
        self.orderbuf = []
Example #2
0
            for instrument in instruments:
                if counter == 0:
                    pass
                else:
                    if (abs(instrument.last_price - lastp[instrument.symbol]) >
                            0.5):
                        Sli[instrument.symbol] = 0.02
                    else:
                        Sli[instrument.symbol] = 0.01
                if instrument.symbol in SYMBOLS:
                    center_price[instrument.symbol] = instrument.last_price

                    for i in range(len(posbias)):
                        utils.new_order(
                            common_pb2.NEW_ORDER, None, common_pb2.BID,
                            instrument.symbol, posbias[i][1],
                            instrument.last_price - SLIPPER * posbias[i][0],
                            False, common_pb2.LONG)
                        # order.insert_openLongPosition(symbol=instrument.symbol, volume=posbias[i][1],
                        #                               price=center_price[instrument.symbol] - Sli[instrument.symbol]*posbias[i][0], is_market=False)
                    for j in range(len(negbias)):
                        utils.new_order(
                            common_pb2.NEW_ORDER, None, common_pb2.ASK,
                            instrument.symbol, negbias[i][1],
                            instrument.last_price - SLIPPER * negbias[i][0],
                            False, common_pb2.SHORT)
                        # order.insert_openShortPosition(symbol=instrument.symbol, volume=negbias[i][1],
                        #                               price=center_price[instrument.symbol] - Sli[instrument.symbol] * negbias[i][0],
                        #                               is_market=False)
                    lastp[instrument.symbol] = center_price[instrument.symbol]
                    continue
Example #3
0
 def execute(self):
     for order in self.buf:
         utils.new_order(common_pb2.NEW_ORDER, None, order[0], order[1],
                         order[2], order[3], order[4], order[5])
     self.buf = []
Example #4
0
import numpy as np
from scipy.stats import norm
if __name__=="__main__":
    flag=dict()
    for s in SYMBOLS:
        flag[s]=0
    channel = grpc.insecure_channel(MARKET_CHANNEL)  # 57500
    stub = broker_pb2_grpc.MarketDataStub(channel)
    while 1:
        response = stub.subscribe(common_pb2.Empty())
        for market_data in response:
            if int(market_data.instruments[0].timestamp)%900==899:
                for instrument in market_data.instruments:
                    if instrument.symbol in SYMBOLS:
                        if instrument.last_price-instrument.deliver_price>0.1:
                            utils.new_order(common_pb2.NEW_ORDER,None,common_pb2.ASK,instrument.symbol,50,None,True,common_pb2.SHORT)
                            flag[s]=-1
                            print("233")
                        if instrument.last_price - instrument.deliver_price < -0.1:
                            utils.new_order(common_pb2.NEW_ORDER, None, common_pb2.BID, instrument.symbol, 50, None,
                                            True, common_pb2.LONG)
                            flag[s]=1
                            print("233")
            else:
                if int(market_data.instruments[0].timestamp) % 900 == 1:
                    for s in SYMBOLS:
                        if flag[s]==-1:
                            utils.new_order(common_pb2.NEW_ORDER, None, common_pb2.BID, instrument.symbol, 50, None,
                                            True, common_pb2.SHORT)
                        if flag[s]==1:
                            utils.new_order(common_pb2.NEW_ORDER, None, common_pb2.ASK, instrument.symbol, 50, None,
Example #5
0
 flag2 = 0
 # if mktposition.occupiedcashlong[instrument.symbol] > 10000:
 #     utils.new_order(common_pb2.NEW_ORDER, None, common_pb2.ASK, instrument.symbol,
 #                     mktposition.marketLongPosition[instrument.symbol], None,
 #                     True, common_pb2.LONG)
 if mktposition.unrealizedPnllong[
         instrument.
         symbol] < -1000 or mktposition.unrealizedPnllong[
             instrument.
             symbol] > 1000 or mktposition.occupiedcashlong[
                 instrument.
                 symbol] > 10000 or mktposition.marketLongPosition[
                     instrument.symbol] > 150:
     utils.new_order(
         common_pb2.NEW_ORDER, None, common_pb2.ASK,
         instrument.symbol,
         mktposition.marketLongPosition[instrument.symbol],
         None, True, common_pb2.LONG)
     flag1 = 1
 # if mktposition.occupiedcashshort[instrument.symbol] > 10000:
 #     utils.new_order(common_pb2.NEW_ORDER, None, common_pb2.BID, instrument.symbol,
 #                     mktposition.marketShortPosition[instrument.symbol], None,
 #                     True, common_pb2.SHORT)
 if mktposition.unrealizedPnlshort[
         instrument.
         symbol] < -1000 or mktposition.unrealizedPnlshort[
             instrument.
             symbol] > 1000 or mktposition.occupiedcashshort[
                 instrument.
                 symbol] > 10000 or mktposition.marketShortPosition[
                     instrument.symbol] > 120:
Example #6
0
 def orderhelper(self, request_type, order_id, side, symbol, volume, price,
                 is_market, pos_type):
     self.outgoingorder.append(
         utils.new_order(request_type, order_id, side, symbol, volume,
                         price, is_market, pos_type))