Exemplo n.º 1
0
        private bool SendTxOrderMarket(string symbol, string side, string amount, string sender, string fee, string privateKey)
        {
            try
            {
                TransactionOrderMarketRequest data = new TransactionOrderMarketRequest();
                data.Body            = new TransactionOrderMarketRequestBody();
                data.Body.Nonce      = DateTimeUtility.CurrentUnixTimeUTC();
                data.Body.Fee        = fee;
                data.Body.PairSymbol = symbol;
                data.Body.Side       = side;
                data.Body.Amount     = amount;
                data.Body.Owner      = sender;
                data.Signature       = KeySignature.Sign(privateKey, JsonConvert.SerializeObject(data.Body));

                string endpoint = nodeServerAddress + "/transaction/market-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);
            }
        }
Exemplo n.º 2
0
        public void RunEmitTransactions()
        {
            try
            {
                int successCount = 0;
                int failedCount  = 0;

                Parallel.For(0, 1000, new ParallelOptions {
                    MaxDegreeOfParallelism = 4
                }, delegate(int i)
                {
                    bool isSuccessful = SendTransaction("http://localhost:8080", (DateTimeUtility.CurrentUnixTimeUTC() + i));

                    if (isSuccessful)
                    {
                        successCount++;
                        Console.WriteLine("Successfully sent transaction " + (i + 1).ToString());
                    }
                    else
                    {
                        failedCount++;
                    }
                });

                Console.WriteLine(string.Format("Total Success: {0}, Total Failed: {1}", successCount, failedCount));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 3
0
        private bool SendTxCreateToken(string symbol, string name, long totalSupply, short decimals, string owner, string privateKey)
        {
            try
            {
                TransactionCreateTokenRequest data = new TransactionCreateTokenRequest();
                data.Body             = new TransactionCreateTokenRequestBody();
                data.Body.Nonce       = DateTimeUtility.CurrentUnixTimeUTC();
                data.Body.Fee         = "0";
                data.Body.Symbol      = symbol;
                data.Body.Name        = name;
                data.Body.TotalSupply = totalSupply;
                data.Body.Decimals    = decimals;
                data.Body.Owner       = owner;
                data.Signature        = KeySignature.Sign(privateKey, JsonConvert.SerializeObject(data.Body));

                string endpoint = nodeServerAddress + "/transaction/create-token";
                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);
            }
        }
Exemplo n.º 4
0
        public List <string> MakeTrade(string transactionId, string tradingPair, string side, decimal amount, string owner)
        {
            List <string> transactionIds = new List <string>();

            //FindTradeMatch
            var tradeMatches = FindMatchedOrdersByAvailableBalance(tradingPair, side, amount, owner);

            //Prepare to make transactions
            string ownerSendingToken   = null;
            string ownerReceivingToken = null;

            if (side == TradeSides.Buy)
            {
                ownerReceivingToken = tradingPair.Split('/')[0];
                ownerSendingToken   = tradingPair.Split('/')[1];

                //Perform transactions
                TransactionServices transactionService = new TransactionServices();
                foreach (var trade in tradeMatches)
                {
                    //Transfer from owner to matcher
                    string txId1 = transactionService.AddTransfer(
                        DateTimeUtility.CurrentUnixTimeUTC(),
                        0,
                        ownerSendingToken,
                        owner,
                        trade.Address,
                        trade.Amount * trade.Price);

                    //Transfer from matcher to owner
                    string txId2 = transactionService.AddTransfer(
                        DateTimeUtility.CurrentUnixTimeUTC(),
                        0,
                        ownerReceivingToken,
                        trade.Address,
                        owner,
                        trade.Amount);

                    //Add trade match record (For audit record purpose)
                    string txMatch = transactionService.AddTradeMatch(
                        DateTimeUtility.CurrentUnixTimeUTC(),
                        side,
                        tradingPair,
                        trade.Amount,
                        trade.Price,
                        trade.TransactionId,
                        trade.Address,
                        transactionId,
                        owner,
                        trade.PartialOrFull);

                    transactionIds.Add(txMatch);
                }
            }
            else if (side == TradeSides.Sell)
            {
                ownerReceivingToken = tradingPair.Split('/')[1];
                ownerSendingToken   = tradingPair.Split('/')[0];

                //Perform transactions
                TransactionServices transactionService = new TransactionServices();
                foreach (var trade in tradeMatches)
                {
                    //Transfer from owner to matcher
                    string txId1 = transactionService.AddTransfer(
                        DateTimeUtility.CurrentUnixTimeUTC(),
                        0,
                        ownerSendingToken,
                        owner,
                        trade.Address,
                        trade.Amount);

                    //Transfer from matcher to owner
                    string txId2 = transactionService.AddTransfer(
                        DateTimeUtility.CurrentUnixTimeUTC(),
                        0,
                        ownerReceivingToken,
                        trade.Address,
                        owner,
                        trade.Amount * trade.Price);

                    //Add trade match record (For audit record purpose)
                    string txMatch = transactionService.AddTradeMatch(
                        DateTimeUtility.CurrentUnixTimeUTC(),
                        side,
                        tradingPair,
                        trade.Amount,
                        trade.Price,
                        trade.TransactionId,
                        trade.Address,
                        transactionId,
                        owner,
                        trade.PartialOrFull);

                    transactionIds.Add(txMatch);
                }
            }

            return(transactionIds);
        }