예제 #1
0
        /// <summary>
        /// Withdraw funds from exchange
        /// </summary>
        /// <param name="symbol">Symbol of token to withdraw</param>
        /// <param name="amount">Amount to withdraw</param>
        /// <returns>Boolean of withdraw attempt</returns>
        public async Task <bool> Withdraw(string symbol, decimal amount)
        {
            string     url            = baseUrl + "/withdraw";
            BigInteger withdrawAmount = new BigInteger(amount);

            var parameters = new Dictionary <string, object>();

            parameters.Add("contractAddress", _contractAddress);
            parameters.Add("token", currencyList[symbol].address);
            parameters.Add("amount", withdrawAmount);
            parameters.Add("address", _address);
            parameters.Add("nonce", new BigInteger(_dtHelper.UTCtoUnixTime()));

            //SignMessage
            var signature = new Nethereum.Signer.TransactionSigner();

            parameters.Add("v", 0);
            parameters.Add("r", string.Empty);
            parameters.Add("s", string.Empty);

            try
            {
                var response = await _restRepo.PostApi <Dictionary <string, object>, Dictionary <string, object> >(url, parameters);

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// Place an order on the exchange
        /// </summary>
        /// <param name="pair">Trading pair</param>
        /// <param name="price">Price of trade</param>
        /// <param name="quantity">Quantity to trade</param>
        /// <param name="type">Trade side ( buy | sell )</param>
        /// <returns></returns>
        private async Task <OrderResponse> OnOrder(string pair, decimal price, decimal quantity, TradeType type)
        {
            string url = baseUrl + "/order";

            var        buySymbol  = Helpers.BuySymbol(pair, type);
            var        sellSymbol = Helpers.SellSymbol(pair, type);
            BigInteger buyAmount  = type == TradeType.buy ? new BigInteger(quantity) : new BigInteger((price * quantity));
            BigInteger sellAmount = type == TradeType.buy ? new BigInteger((price * quantity)) : new BigInteger(quantity);

            var parameters = new Dictionary <string, object>();

            parameters.Add("contractAddress", _contractAddress);
            parameters.Add("tokenBuy", currencyList[buySymbol].address);
            parameters.Add("amountBuy", buyAmount);
            parameters.Add("tokenSell", currencyList[sellSymbol].address);
            parameters.Add("amountSell", sellAmount);
            parameters.Add("nonce", new BigInteger(_dtHelper.UTCtoUnixTime()));
            parameters.Add("address", _address);

            //SignMessage
            var signature = new Nethereum.Signer.TransactionSigner();


            parameters.Add("v", 0);
            parameters.Add("r", string.Empty);
            parameters.Add("s", string.Empty);

            var response = await _restRepo.PostApi <OrderResponse, Dictionary <string, object> >(url, parameters);

            return(response);
        }
예제 #3
0
        /// <summary>
        /// Cancel an open order
        /// </summary>
        /// <param name="orderHash">Order hash</param>
        /// <returns>Message of the cancel attempt</returns>
        public async Task <Dictionary <string, object> > CancelOrder(string orderHash)
        {
            string url = baseUrl + "/cancel";

            var parameters = new Dictionary <string, object>();

            parameters.Add("orderHash", orderHash);
            parameters.Add("nonce", new BigInteger(_dtHelper.UTCtoUnixTime()));

            //SignMessage
            var signature = new Nethereum.Signer.TransactionSigner();

            parameters.Add("address", _address);
            parameters.Add("v", 0);
            parameters.Add("r", string.Empty);
            parameters.Add("s", string.Empty);

            var response = await _restRepo.PostApi <Dictionary <string, object>, Dictionary <string, object> >(url, parameters);

            return(response);
        }
예제 #4
0
        /// <summary>
        /// Trade an order
        /// </summary>
        /// <param name="orderHash">Order hash to trade</param>
        /// <param name="amount">Amount received from order</param>
        /// <returns>Trade reponse object</returns>
        private async Task <TradeResponse> OnTrade(string orderHash, decimal amount)
        {
            string url = baseUrl + "/trade";

            BigInteger tradeAmount = new BigInteger(amount);

            var parameters = new Dictionary <string, object>();

            parameters.Add("orderHash", orderHash);
            parameters.Add("amount", tradeAmount);
            parameters.Add("address", _address);
            parameters.Add("nonce", new BigInteger(_dtHelper.UTCtoUnixTime()));

            //SignMessage
            var signature = new Nethereum.Signer.TransactionSigner();

            parameters.Add("v", 0);
            parameters.Add("r", string.Empty);
            parameters.Add("s", string.Empty);

            var response = await _restRepo.PostApi <TradeResponse, Dictionary <string, object> >(url, parameters);

            return(response);
        }