コード例 #1
0
ファイル: SimulationTest.cs プロジェクト: treverson/dexr
        private bool SendTxOrderLimit(string symbol, string side, string amount, string price, int expiryBlocks, string sender, string fee, string privateKey)
        {
            try
            {
                TransactionOrderLimitRequest data = new TransactionOrderLimitRequest();
                data.Body              = new TransactionOrderLimitRequestBody();
                data.Body.Nonce        = DateTimeUtility.CurrentUnixTimeUTC();
                data.Body.Fee          = fee;
                data.Body.PairSymbol   = symbol;
                data.Body.Side         = side;
                data.Body.Price        = price;
                data.Body.Amount       = amount;
                data.Body.ExpiryBlocks = expiryBlocks;
                data.Body.Owner        = sender;
                data.Signature         = KeySignature.Sign(privateKey, JsonConvert.SerializeObject(data.Body));

                string endpoint = nodeServerAddress + "/transaction/limit-order";
                Log("Api:" + endpoint);
                string responseData = this.SendPostRequest(endpoint, JsonConvert.SerializeObject(data));
                Log("Response:" + responseData);

                return(true);
            }
            catch (Exception ex)
            {
                Log("Failed: " + ex.Message);
                return(false);
            }
        }
コード例 #2
0
        // POST: /transaction/limit-order
        public static HttpResponse AddOrderLimit(HttpRequest request)
        {
            TransactionOrderLimitRequest requestData = JsonConvert.DeserializeObject <TransactionOrderLimitRequest>(request.Content);

            TransactionController controller = new TransactionController();
            var response = controller.AddOrderLimit(requestData);

            Echo(request);

            return(CreateHttpResponse(response));
        }
コード例 #3
0
        public GenericResponse AddOrderLimit(TransactionOrderLimitRequest value)
        {
            try
            {
                VerifySignature(value.Body, value.Signature, value.Body.Owner);

                if (!ApplicationState.IsChainUpToDate)
                {
                    return(new GenericResponse(null, ResponseCodes.Success, ResponseMessages.NodeNotConsensusReady));
                }

                //Perform transaction
                TransactionServices transactionService = new TransactionServices();
                string txId = transactionService.AddLimitOrder(
                    value.Body.Nonce,
                    Convert.ToDecimal(value.Body.Fee),
                    value.Body.PairSymbol,
                    value.Body.Side,
                    Convert.ToDecimal(value.Body.Price),
                    Convert.ToDecimal(value.Body.Amount),
                    value.Body.ExpiryBlocks,
                    value.Body.Owner);

                ApplicationLog.Info("Transaction added to queue for next block. TxId: " + txId);
                return(new GenericResponse(txId, ResponseCodes.Success, "Transaction added to queue for next block."));
            }
            catch (ValidationException vex)
            {
                ApplicationLog.Warn("ValidationException [" + vex.Code + "]: " + vex.Message);
                return(new GenericResponse(null, vex.Code, vex.Message));
            }
            catch (Exception ex)
            {
                ApplicationLog.Exception(ex);
                return(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error));
            }
        }