コード例 #1
0
        public static async Task CancelOrderDemo(SwitcheoRestService switcheoService,
                                                 AccountSignerTransactionManager accountSigner)
        {
            var cancelRequest = await switcheoService.PrepareCancelOrder("69c60da5-5832-4705-8390-de4bb4ed62c5");

            // turn into json
            var signableParams = JsonConvert.SerializeObject(cancelRequest);
            // serialize request params
            var serializedParams = SwitcheoHelper.PrepareParametersRequest(signableParams);
            // signs the serialized params
            var signature = accountSigner.SignMessage(serializedParams);

            // adds the 'address' and 'signature' fields to the json
            var apiParams = SwitcheoHelper.AddTransactFields(signableParams, signature,
                                                             accountSigner.AddressScriptHash.ToString().Remove(0, 2));

            // sends the 'create cancellation' request
            CreateResponse response = await switcheoService.CreateCancellation(apiParams);

            Debug.WriteLine(JsonConvert.SerializeObject(response));
            // check response to make sure is what you want

            // execute cancellation
            var tx          = Transaction.FromJson(Txn.ToJson(response.Transaction));
            var depositId   = response.Id.ToString();
            var signatureTx = accountSigner.SignTransaction(tx, false).ToHexString();

            // if everything is good it should return OK
            var execute = await switcheoService.ExecuteCancellation(signatureTx, depositId);

            Debug.WriteLine(JsonConvert.SerializeObject(execute));
        }
コード例 #2
0
        public static async Task OrderDemo(SwitcheoRestService switcheoService, AccountSignerTransactionManager accountSigner)
        {
            var orderRequest = await switcheoService.PrepareCreateOrder("SWTH_NEO", "buy", "0.00315200", "2050000000", true, "limit");

            // turn into json
            var signableParams = JsonConvert.SerializeObject(orderRequest);
            // serialize request params
            var serializedParams = SwitcheoHelper.PrepareParametersRequest(signableParams);
            // signs the serialized params
            var signature = accountSigner.SignMessage(serializedParams);

            // adds the 'address' and 'signature' fields to the json
            var apiParams = SwitcheoHelper.AddTransactFields(signableParams, signature,
                                                             accountSigner.AddressScriptHash.ToString().Remove(0, 2));

            // sends the 'create withdrawal' request
            OrderResponse response = await switcheoService.CreateOrder(apiParams);

            // check response to make sure is what you want
            Debug.WriteLine(JsonConvert.SerializeObject(response));

            var executeOrderDto = new ExecuteOrder();

            foreach (var responseFill in response.Fills)
            {
                var tx          = Transaction.FromJson(JsonConvert.SerializeObject(responseFill.Txn));
                var signatureTx = accountSigner.SignTransaction(tx, false).ToHexString();
                executeOrderDto.Fills.Add(responseFill.Id.ToString(), signatureTx);
            }

            foreach (var responseMakes in response.Makes)
            {
                var tx          = Transaction.FromJson(JsonConvert.SerializeObject(responseMakes.Txn));
                var signatureTx = accountSigner.SignTransaction(tx, false).ToHexString();
                executeOrderDto.Makes.Add(responseMakes.Id.ToString(), signatureTx);
            }

            ExecuteOrderResponse execute = await switcheoService.ExecuteOrder(executeOrderDto, response.Id.ToString());

            Debug.WriteLine(JsonConvert.SerializeObject(execute));
        }
コード例 #3
0
        public static async Task WithdrawalDemo(SwitcheoRestService switcheoService, AccountSignerTransactionManager accountSigner)
        {
            // create withdrawal DTO
            var transactObject = await switcheoService.PrepareCreateWithdrawal("neo", "SWTH", "3");

            // turn into json
            var signableParams = JsonConvert.SerializeObject(transactObject);
            // serialize request params
            var serializedParams = SwitcheoHelper.PrepareParametersRequest(signableParams);
            // signs the serialized params
            var signature = accountSigner.SignMessage(serializedParams);

            // adds the 'address' and 'signature' fields to the json
            var apiParams = SwitcheoHelper.AddTransactFields(signableParams, signature,
                                                             accountSigner.AddressScriptHash.ToString().Remove(0, 2));

            // sends the 'create withdrawal' request
            var response = await switcheoService.CreateWithdrawl(apiParams);

            Debug.WriteLine(JsonConvert.SerializeObject(response));

            // execute withdrawal
            JObject createWithdrawalResponse = JObject.Parse(response);

            createWithdrawalResponse.Remove("transaction"); // not in docs

            var executeWithdrawalDto = new ExecuteWithdrawl
            {
                Id        = new Guid(createWithdrawalResponse["id"].ToString()),
                Timestamp = await switcheoService.GetTimeStampAsync()
            };

            // serialize request params
            var serializedResponseParams = SwitcheoHelper.PrepareParametersRequest(JsonConvert.SerializeObject(executeWithdrawalDto));
            var responseSignature        = accountSigner.SignMessage(serializedResponseParams);

            WithdrawlResponse withdrawlResponse = await switcheoService.ExecuteWithdraw(executeWithdrawalDto, responseSignature);

            Debug.WriteLine(JsonConvert.SerializeObject(withdrawlResponse));
        }