예제 #1
0
        public static CryptsyOrder ReadFromJObject(JObject o, Int64 marketId = -1, ORDER_TYPE orderType = ORDER_TYPE.NA)
        {
            if (o == null)
            {
                return(null);
            }

            var order = new CryptsyOrder
            {
                Price            = o.Value <decimal>("price"),
                Quantity         = o.Value <decimal>("quantity"),
                Total            = o.Value <decimal>("total"),
                OriginalQuantity = o.Value <decimal?>("orig_quantity") ?? -1,
                MarketId         = o.Value <Int64?>("marketid") ?? marketId,

                //If ordertype is present, use it, if not: use the ordertype passed to the method
                OrderType =
                    o.Value <string>("ordertype") == null
                        ? orderType
                        : (o.Value <string>("ordertype").ToLower() == "buy" ? ORDER_TYPE.BUY : ORDER_TYPE.SELL),
                CreatedUtc = o.Value <DateTime?>("created")
            };

            if (order.CreatedUtc != null)
            {
                order.CreatedUtc = TimeZoneInfo.ConvertTime((DateTime)order.CreatedUtc, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"), TimeZoneInfo.Utc); //Convert to UTC
            }
            return(order);
        }
예제 #2
0
        /// <summary>
        /// キューブから任意の音を再生します
        /// https://toio.github.io/toio-spec/docs/ble_sound#midi-note-number-の再生
        /// </summary>
        /// <param name="repeatCount">繰り返し回数</param>
        /// <param name="operations">命令配列</param>
        /// <param name="order">命令の優先度</param>
        public override void PlaySound(int repeatCount, SoundOperation[] operations, ORDER_TYPE order)
        {
#if !RELEASE
            // v2.0.0に限り58以下
            if (58 < operations.Length)
            {
                Debug.LogErrorFormat("[Cube.playSound]最大メロディ数を超えました. operations.Length={0}", operations.Length);
            }
#endif
            if (!this.isConnected)
            {
                return;
            }

            repeatCount = Mathf.Clamp(repeatCount, 0, 255);
            var operation_length = Mathf.Clamp(operations.Length, 0, 58);

            byte[] buff = new byte[3 + operation_length * 3];
            buff[0] = 3;
            buff[1] = BitConverter.GetBytes(repeatCount)[0];
            buff[2] = BitConverter.GetBytes(operation_length)[0];

            for (int i = 0; i < operation_length; i++)
            {
                buff[3 + 3 * i] = BitConverter.GetBytes(Mathf.Clamp(operations[i].durationMs / 10, 1, 255))[0];
                buff[4 + 3 * i] = BitConverter.GetBytes(operations[i].note_number)[0];
                buff[5 + 3 * i] = BitConverter.GetBytes(operations[i].volume)[0];
            }

            this.Request(CHARACTERISTIC_SOUND, buff, true, order, "playSound", repeatCount, operations);
        }
 public PlacedOrder(HOUSE _name, Region _regionFrom, Region _regionTo, ORDER_TYPE _order)
 {
     this.ownerPlayerName = _name;
     this.regionFrom = _regionFrom;
     this.regionTo = _regionTo;
     this.order = _order;
 }
예제 #4
0
        private void CloseInternal()
        {
            bool success = false;

            if (ea.OrderSelect(ticket, SELECT_BY.SELECT_BY_TICKET) && ea.OrderCloseTime() != NULL_TIME)
            {
                return;
            }

            //ea.Print("try to close");

            ORDER_TYPE orderType = ea.OrderType();

            // should refactor to hierarcy

            if (orderType == ORDER_TYPE.OP_BUY)
            {
                success = ea.OrderClose(ticket, lots, ea.BuyClosePriceFor(symbol), 50);
            }
            else if (orderType == ORDER_TYPE.OP_SELL)
            {
                success = ea.OrderClose(ticket, lots, ea.SellClosePriceFor(symbol), 50);
            }
            else
            {
                success = ea.OrderDelete(ticket);
                ea.Print("delete ticket " + success);
            }

            if (!success)
            {
                ea.ThrowLatestException();
            }
        }
예제 #5
0
        //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
        //      CoreCube API
        //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

        //_/_/_/_/_/_/_/_/_/_/_/_/_/_/
        //      CoreCube API < send >
        //_/_/_/_/_/_/_/_/_/_/_/_/_/_/

        /// <summary>
        /// キューブのモーターを制御します
        /// https://toio.github.io/toio-spec/docs/ble_motor#時間指定付きモーター制御
        /// </summary>
        /// <param name="left">左モーター速度</param>
        /// <param name="right">右モーター速度</param>
        /// <param name="durationMs">持続時間(ミリ秒)</param>
        /// <param name="order">命令の優先度</param>
        public override void Move(int left, int right, int durationMs, ORDER_TYPE order)
        {
#if !RELEASE
            if (2550 < durationMs)
            {
                Debug.LogErrorFormat("[Cube.move]最大ミリ秒を超えました. durationMs={0}", durationMs);
            }
#endif
            if (!this.isConnected)
            {
                return;
            }

            var lSign      = left > 0 ? 1 : -1;
            var rSign      = right > 0 ? 1 : -1;
            var lDirection = left > 0 ? 1 : 2;
            var rDirection = right > 0 ? 1 : 2;
            var lPower     = Mathf.Min(Mathf.Abs(left), maxSpd);
            var rPower     = Mathf.Min(Mathf.Abs(right), maxSpd);
            var duration   = Mathf.Clamp(durationMs / 10, 0, 255);

            byte[] buff = new byte[8];
            buff[0] = 2;
            buff[1] = 1;
            buff[2] = BitConverter.GetBytes(lDirection)[0];
            buff[3] = BitConverter.GetBytes(lPower)[0];
            buff[4] = 2;
            buff[5] = BitConverter.GetBytes(rDirection)[0];
            buff[6] = BitConverter.GetBytes(rPower)[0];
            buff[7] = BitConverter.GetBytes(duration)[0];

            this.Request(CHARACTERISTIC_MOTOR, buff, false, order, "move", left, right, durationMs);
        }
예제 #6
0
    void SetOrderTypeAndSpawn()
    {
        customerLeftCount++;

        if (customerLeftCount < 5)
        {
            ORDER_GROUP = ORDER_TYPE.EASY;
        }
        else if (customerLeftCount < 10)
        {
            ORDER_GROUP = ORDER_TYPE.MEDIUM;
        }

        else if (customerLeftCount < 14)
        {
            ORDER_GROUP = ORDER_TYPE.EASY;
        }
        else
        {
            int i = Random.Range(2, 4);
            ORDER_GROUP = (ORDER_TYPE)i;
        }


        SpawnACustomere();
    }
예제 #7
0
        public int OpenOffer(MqlHandler handler, string symbol, ORDER_TYPE orderType, double orderAmount, double price, int slippage, double stopLoss, double takeProfit)
        {
            var result = _tradingFunctionsWrapper.OrderSend(handler, symbol, orderType, orderAmount, price, slippage, stopLoss, takeProfit);

            _log.DebugFormat("Send offer. Symbol={0}, OrderType={1}, OrderAmount={2}, Price={3}, Slippage={4}, StopLoss={5}, TakeProfit={6}", symbol, orderType, orderAmount, price, slippage, stopLoss, takeProfit);
            _log.DebugFormat("Send offer. Result={0}", result);
            return result;
        }
예제 #8
0
        public int OpenOffer(MqlHandler handler, string symbol, ORDER_TYPE orderType, double orderAmount, double price, int slippage, double stopLoss, double takeProfit)
        {
            var result = _tradingFunctionsWrapper.OrderSend(handler, symbol, orderType, orderAmount, price, slippage, stopLoss, takeProfit);

            _log.DebugFormat("Send offer. Symbol={0}, OrderType={1}, OrderAmount={2}, Price={3}, Slippage={4}, StopLoss={5}, TakeProfit={6}", symbol, orderType, orderAmount, price, slippage, stopLoss, takeProfit);
            _log.DebugFormat("Send offer. Result={0}", result);
            return(result);
        }
예제 #9
0
        ///////////////   COMMAND API  ///////////////

        public override void Move(int left, int right, int durationMs, ORDER_TYPE order = ORDER_TYPE.Weak)
        {
#if RELEASE
            CubeOrderBalancer.Instance.AddOrder(this, () => simulator.Move(left, right, durationMs), order);
#else
            CubeOrderBalancer.Instance.DEBUG_AddOrderParams(this, () => simulator.Move(left, right, durationMs), order, "move", left, right);
#endif
        }
예제 #10
0
        public override void ConfigSlopeThreshold(int angle, ORDER_TYPE order = ORDER_TYPE.Strong)
        {
#if RELEASE
            CubeOrderBalancer.Instance.AddOrder(this, () => simulator.SetSlopeThreshold(angle), order);
#else
            CubeOrderBalancer.Instance.DEBUG_AddOrderParams(this, () => simulator.SetSlopeThreshold(angle), order, "configSlopeThreshold", angle);
#endif
        }
예제 #11
0
 public Order(string description, int destinationTable, double price, ORDER_TYPE type)
 {
     this.description      = description;
     this.destinationTable = destinationTable;
     this.price            = price;
     state     = ORDER_STATE.NOT_PICKED;
     this.type = type;
 }
예제 #12
0
        // Light
        public override void TurnLedOff(ORDER_TYPE order = ORDER_TYPE.Weak)
        {
#if RELEASE
            CubeOrderBalancer.Instance.AddOrder(this, () => simulator.StopLight(), order);
#else
            CubeOrderBalancer.Instance.DEBUG_AddOrderParams(this, () => simulator.StopLight(), order, "turnLedOff");
#endif
        }
예제 #13
0
        public override void TurnLedOn(int red, int green, int blue, int durationMs, ORDER_TYPE order = ORDER_TYPE.Weak)
        {
#if RELEASE
            CubeOrderBalancer.Instance.AddOrder(this, () => simulator.SetLight(red, green, blue, duration), order);
#else
            CubeOrderBalancer.Instance.DEBUG_AddOrderParams(this, () => simulator.SetLight(red, green, blue, durationMs), order, "turnLedOn", red, green, blue, durationMs);
#endif
        }
예제 #14
0
        public override void PlayPresetSound(int soundId, int volume = 255, ORDER_TYPE order = ORDER_TYPE.Weak)
        {
#if RELEASE
            CubeOrderBalancer.Instance.AddOrder(this, () => simulator.PlayPresetSound(soundId, volume), order);
#else
            CubeOrderBalancer.Instance.DEBUG_AddOrderParams(this, () => simulator.PlayPresetSound(soundId, volume), order, "playPresetSound", soundId);
#endif
        }
예제 #15
0
        public override void StopSound(ORDER_TYPE order = ORDER_TYPE.Weak)
        {
#if RELEASE
            CubeOrderBalancer.Instance.AddOrder(this, () => simulator.StopSound(), order);
#else
            CubeOrderBalancer.Instance.DEBUG_AddOrderParams(this, () => simulator.StopSound(), order, "stopSound");
#endif
        }
예제 #16
0
        /*
         * // キューブのモーターを複数目標指定付き制御します
         * public override void MultiTargetMove(
         *  int[] targetXList,
         *  int[] targetYList,
         *  int[] targetAngleList,
         *  TargetRotationType[] multiRotationTypeList = null,
         *  int configID = 0,
         *  int timeOut = 0,
         *  TargetMoveType targetMoveType = TargetMoveType.RotatingMove,
         *  int maxSpd = 80,
         *  TargetSpeedType targetSpeedType = TargetSpeedType.UniformSpeed,
         *  MultiWriteType multiWriteType = MultiWriteType.Write,
         *  ORDER_TYPE order = ORDER_TYPE.Strong
         * ){
         *  if (!this.isConnected) { return; }
         #if !RELEASE
         *      if (29 < targetXList.Length){Debug.LogErrorFormat("[Cube.MultiTargetMove]追加目標数29を超えました. targetXList.Length={0}", targetXList.Length);}
         *      if (255 < configID || configID < 0){Debug.LogErrorFormat("[Cube.MultiTargetMove]制御識別値範囲を超えました. configID={0}", configID);}
         *      if (255 < timeOut || timeOut < 0){Debug.LogErrorFormat("[Cube.MultiTargetMove]制御時間範囲を超えました. timeOut={0}", timeOut);}
         *      if (this.maxSpd < maxSpd || maxSpd < 10){Debug.LogErrorFormat("[Cube.MultiTargetMove]速度範囲を超えました. maxSpd={0}", maxSpd);}
         #endif
         *
         *  multiRotationTypeList = multiRotationTypeList==null? new TargetRotationType[targetXList.Length] : multiRotationTypeList;
         *
         *  configID = Mathf.Clamp(configID, 0, 255);
         *  timeOut= Mathf.Clamp(timeOut, 0, 255);
         *  maxSpd = Mathf.Clamp(maxSpd, 10, this.maxSpd);
         *
         *  byte[] buff = new byte[targetXList.Length * 6 + 8];
         *  buff[0] = 4;
         *  buff[1] = (byte)configID;
         *  buff[2] = (byte)timeOut;
         *  buff[3] = (byte)targetMoveType;
         *  buff[4] = (byte)maxSpd;
         *  buff[5] = (byte)targetSpeedType;
         *  buff[6] = 0;
         *  buff[7] = (byte)multiWriteType;
         *
         *  for (int i = 0; i < targetXList.Length; i++)
         *  {
         #if !RELEASE
         *          if (28 < i){break;}
         *          if (65534 < targetXList[i]){Debug.LogErrorFormat("[Cube.MultiTargetMove]X座標範囲を超えました. targetX={0}", targetXList[i]);}
         *          if (65534 < targetYList[i]){Debug.LogErrorFormat("[Cube.MultiTargetMove]Y座標範囲を超えました. targetY={0}", targetYList[i]);}
         *          if (8191 < targetAngleList[i]){Debug.LogErrorFormat("[Cube.MultiTargetMove]回転角度範囲を超えました. targetAngle={0}", targetAngleList[i]);}
         #endif
         *      var targetX = targetXList[i] == -1 ? 65535 : Mathf.Clamp(targetXList[i], 0, 65534);
         *      var targetY = targetYList[i] == -1 ? 65535 : Mathf.Clamp(targetYList[i], 0, 65534);
         *      var targetAngle = Mathf.Clamp(targetAngleList[i], 0, 8191);
         *
         *      buff[i * 6 + 8] = (byte)(targetX & 0xFF);
         *      buff[i * 6 + 9] = (byte)((targetX >> 8) & 0xFF);
         *      buff[i * 6 + 10] = (byte)(targetY & 0xFF);
         *      buff[i * 6 + 11] = (byte)((targetY >> 8) & 0xFF);
         *      buff[i * 6 + 12] = (byte)(targetAngle & 0xFF);
         *      buff[i * 6 + 13] = (byte)((((int)multiRotationTypeList[i] & 0x0007) << 5 ) | ((targetAngle & 0x1FFF) >> 8));
         *  }
         *  this.Request(CHARACTERISTIC_MOTOR, buff, false, order, "MultiTargetMove",
         *      targetXList, targetYList, targetAngleList, multiRotationTypeList, configID, timeOut,
         *      targetMoveType, maxSpd, targetSpeedType, multiWriteType);
         * }
         */
        // キューブの加速度指定付きモーターを制御します
        public override void AccelerationMove(
            int targetSpeed,
            int acceleration,
            int rotationSpeed = 0,
            AccPriorityType accPriorityType = AccPriorityType.Translation,
            int controlTime  = 0,
            ORDER_TYPE order = ORDER_TYPE.Strong
            )
        {
            if (!this.isConnected)
            {
                return;
            }
            int accMoveType     = targetSpeed > 0 ? 0 : 1;
            int accRotationType = rotationSpeed > 0 ? 0 : 1;

            targetSpeed   = Math.Abs(targetSpeed);
            rotationSpeed = Math.Abs(rotationSpeed);

            #if !RELEASE
            if (this.maxSpd < targetSpeed || targetSpeed < deadzone)
            {
                Debug.LogErrorFormat("[Cube.AccelerationMove]直線速度範囲を超えました. targetSpeed={0}", targetSpeed);
            }
            if (255 < acceleration || acceleration < 0)
            {
                Debug.LogErrorFormat("[Cube.AccelerationMove]加速度範囲を超えました. acceleration={0}", acceleration);
            }
            if (65535 < rotationSpeed)
            {
                Debug.LogErrorFormat("[Cube.AccelerationMove]回転速度範囲を超えました. rotationSpeed={0}", rotationSpeed);
            }
            if (255 < controlTime || controlTime < 0)
            {
                Debug.LogErrorFormat("[Cube.AccelerationMove]制御時間範囲を超えました. controlTime={0}", controlTime);
            }
            #endif

            targetSpeed   = Mathf.Clamp(targetSpeed, deadzone, this.maxSpd);
            acceleration  = Mathf.Clamp(acceleration, 0, 255);
            rotationSpeed = Mathf.Clamp(rotationSpeed, 0, 65535);
            controlTime   = Mathf.Clamp(controlTime, 0, 255);

            byte[] buff = new byte[9];
            buff[0] = 5;
            buff[1] = (byte)(targetSpeed & 0xFF);
            buff[2] = (byte)(acceleration & 0xFF);
            buff[3] = (byte)(rotationSpeed & 0xFF);
            buff[4] = (byte)((rotationSpeed >> 8) & 0xFF);
            buff[5] = (byte)accRotationType;
            buff[6] = (byte)accMoveType;
            buff[7] = (byte)accPriorityType;
            buff[8] = (byte)(controlTime & 0xFF);

            this.Request(CHARACTERISTIC_MOTOR, buff, false, order, "AccelerationMove",
                         targetSpeed, acceleration, rotationSpeed, accRotationType, accMoveType, accPriorityType, controlTime);
        }
예제 #17
0
        /// <summary>
        ///     The main function used to open a position or place a pending order.
        /// </summary>
        /// <param name="handler"></param>
        /// <param name="symbol">SYMBOL for trading.</param>
        /// <param name="cmd">Operation type. It can be any of the Trade operation enumeration.</param>
        /// <param name="volume">Number of lots.</param>
        /// <param name="price">Preferred price of the trade.</param>
        /// <param name="slippage">Maximum price slippage for buy or sell orders.</param>
        /// <param name="stoploss">Stop loss level.</param>
        /// <param name="takeprofit">Take profit level.</param>
        /// <param name="comment">Order comment text. Last part of the comment may be changed by server.</param>
        /// <param name="magic">Order magic number. May be used as user defined identifier.</param>
        /// <param name="expiration">Order expiration time (for pending orders only).</param>
        /// <param name="arrow_color">Color of the opening arrow on the chart. If parameter is missing or has CLR_NONE value opening arrow is not drawn on the chart.</param>
        /// <returns></returns>
        public static int OrderSend(this MqlHandler handler, string symbol, ORDER_TYPE cmd, double volume, double price,
                                    int slippage, double stoploss, double takeprofit, string comment = "", int magic = 0,
                                    DateTime expiration = default(DateTime), int arrow_color = 0)
        {
            string retrunValue = handler.CallMqlMethod("OrderSend", symbol, (int)cmd, volume, price, slippage, stoploss,
                                                       takeprofit, comment, magic, expiration, arrow_color);

            return(Convertor.ToInt(retrunValue));
        }
        /// <summary>
        /// キューブから任意の音を再生します
        /// https://toio.github.io/toio-spec/docs/ble_sound#midi-note-number-の再生
        /// </summary>
        /// <param name="buff">命令プロトコル</param>
        /// <param name="order">命令の優先度</param>
        public override void PlaySound(byte[] buff, ORDER_TYPE order = ORDER_TYPE.Weak)
        {
            if (!this.isConnected)
            {
                return;
            }

            this.Request(CHARACTERISTIC_SOUND, buff, true, order, "playSound");
        }
예제 #19
0
        // Sound
        public override void PlaySound(int repeatCount, SoundOperation[] operations, ORDER_TYPE order = ORDER_TYPE.Weak)
        {
            repeatCount = Mathf.Clamp(repeatCount, 0, 255);

#if RELEASE
            CubeOrderBalancer.Instance.AddOrder(this, () => simulator.PlaySound(repeatCount, operations), order);
#else
            CubeOrderBalancer.Instance.DEBUG_AddOrderParams(this, () => simulator.PlaySound(repeatCount, operations), order, "playSound", repeatCount);
#endif
        }
예제 #20
0
        /// <summary>
        /// キューブの音再生を停止します
        /// https://toio.github.io/toio-spec/docs/ble_sound#再生の停止
        /// </summary>
        /// <param name="order">命令の優先度</param>
        public override void StopSound(ORDER_TYPE order)
        {
            if (!this.isConnected)
            {
                return;
            }

            byte[] buff = new byte[1];
            buff[0] = 1;

            this.Request(CHARACTERISTIC_SOUND, buff, true, order, "stopSound");
        }
예제 #21
0
        public int OrderSend(string symbol, ORDER_TYPE cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment = "", int magic = 0, DateTime expiration = default(DateTime), int arrow_color = -1)
        {
            int ticket = TradingFunctions.OrderSend(this, symbol, cmd, volume, price, slippage, stoploss, takeprofit, comment,
                                                    magic, DateTime.Now.AddDays(100), arrow_color);

            if (ticket == -1)
            {
                ThrowLatestOrderException();
            }

            return(ticket);
        }
예제 #22
0
        /// <summary>
        /// モーションセンサー情報を要求します
        /// https://toio.github.io/toio-spec/docs/ble_sensor#書き込み操作
        /// </summary>
        /// <param name="order">命令の優先度</param>
        public override void RequestSensor(ORDER_TYPE order)
        {
            if (!this.isConnected)
            {
                return;
            }

            byte[] buff = new byte[1];
            buff[0] = 0x81;

            this.Request(CHARACTERISTIC_SENSOR, buff, true, order, "requestSensor");
        }
예제 #23
0
        /// <summary>
        /// キューブ底面についている LED を消灯させます
        /// https://toio.github.io/toio-spec/docs/ble_light#全てのランプを消灯
        /// </summary>
        /// <param name="order">命令の優先度</param>
        public override void TurnLedOff(ORDER_TYPE order = ORDER_TYPE.Weak)
        {
            if (!this.isConnected)
            {
                return;
            }

            byte[] buff = new byte[1];
            buff[0] = 1;

            this.Request(CHARACTERISTIC_LIGHT, buff, true, order, "turnLedOff");
        }
예제 #24
0
        /// <summary>
        /// キューブからあらかじめ用意された効果音を再生します
        /// https://toio.github.io/toio-spec/docs/ble_sound#効果音の再生
        /// </summary>
        /// <param name="soundId">サウンドID</param>
        /// <param name="volume">音量</param>
        /// <param name="order">命令の優先度</param>
        public override void PlayPresetSound(int soundId, int volume, ORDER_TYPE order)
        {
            if (!this.isConnected)
            {
                return;
            }

            byte[] buff = new byte[3];
            buff[0] = 2;
            buff[1] = BitConverter.GetBytes(soundId)[0];
            buff[2] = BitConverter.GetBytes(volume)[0];

            this.Request(CHARACTERISTIC_SOUND, buff, true, order, "playPresetSound", soundId);
        }
예제 #25
0
        // キューブのダブルタップ検出の時間間隔を設定します
        public override void ConfigDoubleTapInterval(int interval, ORDER_TYPE order)
        {
            if (!this.isConnected)
            {
                return;
            }

            interval = Mathf.Clamp(interval, 0, 7);

            byte[] buff = new byte[3];
            buff[0] = 0x17;
            buff[1] = 0;
            buff[2] = BitConverter.GetBytes(interval)[0];

            this.Request(CHARACTERISTIC_CONFIG, buff, true, order, "ConfigDoubleTapinterval", interval);
        }
예제 #26
0
        /// <summary>
        /// キューブの衝突検出のしきい値を設定します
        /// https://toio.github.io/toio-spec/docs/ble_configuration#衝突検出のしきい値設定
        /// </summary>
        /// <param name="level">衝突検知の閾値</param>
        /// <param name="order">命令の優先度</param>
        public override void ConfigCollisionThreshold(int level, ORDER_TYPE order)
        {
            if (!this.isConnected)
            {
                return;
            }

            level = Mathf.Clamp(level, 1, 10);

            byte[] buff = new byte[3];
            buff[0] = 6;
            buff[1] = 0;
            buff[2] = BitConverter.GetBytes(level)[0];

            this.Request(CHARACTERISTIC_CONFIG, buff, true, order, "configCollisionThreshold", level);
        }
예제 #27
0
        /// <summary>
        /// キューブの水平検出のしきい値を設定します
        /// https://toio.github.io/toio-spec/docs/ble_configuration#水平検出のしきい値設定
        /// </summary>
        /// <param name="angle">傾き検知の閾値</param>
        /// <param name="order">命令の優先度</param>
        public override void ConfigSlopeThreshold(int _angle, ORDER_TYPE order)
        {
            if (!this.isConnected)
            {
                return;
            }

            _angle = Mathf.Clamp(_angle, 1, 45);

            byte[] buff = new byte[3];
            buff[0] = 5;
            buff[1] = 0;
            buff[2] = BitConverter.GetBytes(_angle)[0];

            this.Request(CHARACTERISTIC_CONFIG, buff, true, order, "configSlopeThreshold", _angle);
        }
예제 #28
0
        /// <summary>
        /// キューブから任意の音を再生します
        /// https://toio.github.io/toio-spec/docs/ble_sound#midi-note-number-の再生
        /// </summary>
        /// <param name="buff">命令プロトコル</param>
        /// <param name="order">命令の優先度</param>
        public override void PlaySound(byte[] buff, ORDER_TYPE order)
        {
#if !RELEASE
            // v2.0.0に限り58以下
            if (58 < buff[2])
            {
                Debug.LogErrorFormat("[Cube.playSound]最大メロディ数を超えました. Length={0}", buff[2]);
            }
#endif
            if (!this.isConnected)
            {
                return;
            }

            this.Request(CHARACTERISTIC_SOUND, buff, true, order, "playSound");
        }
예제 #29
0
        public void ChangeTakeProfitInPoints(double tpPoints)
        {
            ORDER_TYPE orderType = OrderType;

            double newTp = 0.0;

            if (IsKindOfBuyOrder)
            {
                newTp = OpenPrice + (tpPoints * Points) + Spread;
            }
            else if (IsKindOfSellOrder)
            {
                newTp = OpenPrice - (tpPoints * Points) - Spread;
            }

            ModifyTakeProfit(newTp);
        }
예제 #30
0
        public void ProtectProfit(double pointsValue)
        {
            ORDER_TYPE orderType = OrderType;

            double newSl = 0.0;

            if (orderType == ORDER_TYPE.OP_BUY)
            {
                newSl = OpenPrice + (pointsValue * Points) + Spread;
            }
            else if (orderType == ORDER_TYPE.OP_SELL)
            {
                newSl = OpenPrice - (pointsValue * Points) - Spread;
            }

            ModifyStopLoss(newSl);
        }
예제 #31
0
        public Order PendingSell(string symbol, double size, double entry, double stopLoss = 0, double takeProfit = 0)
        {
            // check if stopLoss and take profit valid for buy
            if (stopLoss != 0 && stopLoss <= entry)
            {
                throw new ApplicationException("Stop Loss for Sell have to more than entry price");
            }

            if (takeProfit != 0 && takeProfit >= entry)
            {
                throw new ApplicationException("Take profit for Sell have to less than entry price");
            }

            ORDER_TYPE orderType = default(ORDER_TYPE);

            if (SellOpenPriceFor(symbol) < entry)
            {
                // sell limit
                orderType = ORDER_TYPE.OP_SELLLIMIT;
            }
            else
            {
                // sell stop
                orderType = ORDER_TYPE.OP_SELLSTOP;
            }

            int ticket = OrderSend(symbol, orderType, size, entry, 3, stopLoss, takeProfit, "", 12134,
                                   DateTime.Now.AddDays(100), CLR_NONE);

            // check if we can create and order to ecn

            // should host compatible handler in server

            if (ticket == -1)
            {
                ThrowLatestException();
            }

            return(new Order(symbol, ticket, size, this));
            //return new Order(
        }
예제 #32
0
    public void Serve(Transform target, List <string> currentOrder, UnityAction <bool, ORDER_TYPE, PLAYER> callback)
    {
        Transform salad = saladHolder.GetChild(0);

        salad.SetParent(target);
        salad.transform.localScale = Vector3.one;
        ORDER_TYPE oRDER_TYPE = (ORDER_TYPE)currentOrder.Count;



        bool result = true;



        for (int i = 0; i < currentOrder.Count; i++)
        {
            if (!foodsInHand.Contains(currentOrder[i]))
            {
                Debug.Log(currentOrder[i] + " not found");
                result = false;
            }
        }


        SaladInHandIndicator(false);

        //foreach (SpriteRenderer item in salad)
        //{
        //    item.sortingOrder = 10;
        //}
        //salad.transform.localScale = foodTargetScale;


        Sequence sequence = DOTween.Sequence();

        sequence.Append(salad.DOLocalMove(Vector3.zero, 0.3f));
        sequence.Append(salad.transform.DOScale(Vector3.zero, 0.3f)).OnComplete(() => { callback?.Invoke(result, oRDER_TYPE, playerType); Destroy(salad.gameObject); });
    }
예제 #33
0
    public void getData(string userKey,  RANKING_TYPE type, ORDER_TYPE order, int limit)
    {
        string os = "";

        #if UNITY_ANDROID
        os = "android";
        #endif

        #if UNITY_IPHONE
        os = "iOS";
        #endif

        string hostURL = Property.ApiUrl;

        StartCoroutine(GetRankingData(hostURL + "ranking/get",
                                      userKey,
                                      os,
                                      App.GameControl.RankingMode.APP_ID,
                                      0,
                                      (int)type,
                                      order.ToString(),
                 					  limit));
    }
예제 #34
0
        public static Order ReadFromJObject(JObject o, Int64 marketID = -1, ORDER_TYPE orderType = ORDER_TYPE.NA)
        {
            if (o == null)
                return null;

            var order = new Order()
            {
                Price = o.Value<decimal>("price"),
                Quantity = o.Value<decimal>("quantity"),
                Total = o.Value<decimal>("total"),
                OriginalQuantity = o.Value<decimal?>("orig_quantity") ?? -1,
                MarketID = o.Value<Int64?>("marketid") ?? marketID,

                //If ordertype is present, use it, if not: use the ordertype passed to the method
                OrderType = o.Value<string>("ordertype") == null ? orderType : (o.Value<string>("ordertype").ToLower() == "buy" ? ORDER_TYPE.BUY : ORDER_TYPE.SELL)

            };

            order.CreatedUTC = o.Value<DateTime?>("created");
            if (order.CreatedUTC != null)
                order.CreatedUTC = TimeZoneInfo.ConvertTime((DateTime)order.CreatedUTC, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"), TimeZoneInfo.Utc); //Convert to UTC

            return order;
        }
예제 #35
0
 public static double AccountFreeMarginCheck(this MqlHandler handler, string symbol, ORDER_TYPE cmd, double volume)
 {
     return Convertor.ToDouble(handler.CallMqlMethod("AccountFreeMarginCheck", (object) symbol, (object) cmd, (object) volume));
 }
예제 #36
0
        /// <summary>
        /// The main function used to open a position or place a pending order.
        /// </summary>
        /// <param name="handler"></param>
        /// <param name="symbol">SYMBOL for trading.</param>
        /// <param name="cmd">Operation type. It can be any of the Trade operation enumeration.</param>
        /// <param name="volume">Number of lots.</param>
        /// <param name="price">Preferred price of the trade.</param>
        /// <param name="slippage">Maximum price slippage for buy or sell orders.</param>
        /// <param name="stoploss">Stop loss level.</param>
        /// <param name="takeprofit">Take profit level.</param>
        /// <param name="comment">Order comment text. Last part of the comment may be changed by server.</param>
        /// <param name="magic">Order magic number. May be used as user defined identifier.</param>
        /// <param name="expiration">Order expiration time (for pending orders only).</param>
        /// <param name="arrow_color">Color of the opening arrow on the chart. If parameter is missing or has CLR_NONE value opening arrow is not drawn on the chart.</param>
        /// <returns></returns>
        public static int OrderSend(this MqlHandler handler, string symbol, ORDER_TYPE cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment = "", int magic = 0, DateTime expiration = default(DateTime), int arrow_color = 0)
        {
            string retrunValue = handler.CallMqlMethod("OrderSend", symbol, (int)cmd, volume, price, slippage, stoploss, takeprofit, comment, magic, expiration, arrow_color);

            return Convertor.ToInt(retrunValue);
        }
예제 #37
0
        /// <summary>
        ///     Returns free margin that remains after the specified position has been opened at the current price on the current account. If the free margin is insufficient, an error 134 (ERR_NOT_ENOUGH_MONEY) will be generated.
        /// </summary>
        /// <param name="handler"></param>
        /// <param name="symbol"></param>
        /// <param name="cmd"></param>
        /// <param name="volume"></param>
        /// <returns></returns>
        public static double AccountFreeMarginCheck(this MqlHandler handler, string symbol, ORDER_TYPE cmd,
                                                    double volume)
        {
            string retrunValue = handler.CallMqlMethod("AccountFreeMarginCheck", symbol, (int) cmd, volume);

            return Convertor.ToDouble(retrunValue);
        }
예제 #38
0
        public int OrderSend(string symbol, ORDER_TYPE cmd, double volume, double price, int slippage, double stoploss,
                             double takeprofit, string comment = "", int magic = 0,
                             DateTime expiration = default(DateTime), int arrow_color = -1)
        {
            int ticket = TradingFunctions.OrderSend(this, symbol, cmd, volume, price, slippage, stoploss, takeprofit,
                                                    comment,
                                                    magic, DateTime.Now.AddDays(100), arrow_color);

            if (ticket == -1)
            {
                ThrowLatestOrderException();
            }

            return ticket;
        }
예제 #39
0
 public static int OrderSend(this MqlHandler handler, string symbol, ORDER_TYPE cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment = "", int magic = 0, DateTime expiration = null, int arrow_color = 0)
 {
     return Convertor.ToInt(handler.CallMqlMethod("OrderSend", (object) symbol, (object) cmd, (object) volume, (object) price, (object) slippage, (object) stoploss, (object) takeprofit, (object) comment, (object) magic, (object) expiration, (object) arrow_color));
 }