private static void PlaceAnOrder(string symbol, string price, string amount) { var tradeClient = new OrderClient(Config.AccessKey, Config.SecretKey); var request = new PlaceOrderRequest { AccountId = Config.AccountId, type = "sell-limit", symbol = symbol, source = "spot-api", amount = amount, price = price }; var response = tradeClient.PlaceOrderAsync(request).Result; switch (response.status) { case "ok": { AppLogger.Info($"Place order successfully, order id: {response.data}"); break; } case "error": { AppLogger.Info($"Place order fail, error code: {response.errorCode}, error message: {response.errorMessage}"); break; } } }
private static void GetLoanInfo() { var marginClient = new CrossMarginClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var response = marginClient.GetLoanInfo().Result; _logger.StopAndLog(); if (response != null) { switch (response.status) { case "ok": { if (response.data != null) { foreach (var c in response.data) { AppLogger.Info($"Currency: {c.currency}, interest: {c.interestRate}," + $" min: {c.maxLoanAmt}, max: {c.maxLoanAmt}, loanable: {c.loanableAmt}"); } } break; } case "error": { AppLogger.Info($"Get loan info fail, error code: {response.errorCode}, error message: {response.errorMessage}"); break; } } } }
private static void GetSubUserDepositAddress() { var walletClient = new WalletClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var result = walletClient.GetSubUserDepositAddressAsync(Config.SubUserId, "btc").Result; _logger.StopAndLog(); if (result != null) { if (result.data != null) { AppLogger.Info($"Get sub user deposit address, id={result.data.Length}"); foreach (var a in result.data) { AppLogger.Info($"currency: {a.currency}, addr: {a.address}, chain: {a.chain}"); } } else { AppLogger.Error($"Get sub user deposit address error: code={result.code}, message={result.message}"); } } }
private static void GetStableCoin() { var stableCoinClient = new StableCointClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var result = stableCoinClient.GetStableCoinAsync("tusd", "1000", "sell").Result; _logger.StopAndLog(); if (result != null) { switch (result.status) { case "ok": { var d = result.data; AppLogger.Info($"Get stable coin successfully, quoteId: {d.quoteId}, currency: {d.currency}, amount: {d.amount}, fee: {d.exchangeFee}"); break; } case "error": { AppLogger.Info($"Get stable coin fail, error code: {result.errorCode}, error message: {result.errorMessage}"); break; } } } }
private static void RepayLoan() { var marginClient = new CrossMarginClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var response = marginClient.Repay("123", "0.001").Result; _logger.StopAndLog(); if (response != null) { switch (response.status) { case "ok": { AppLogger.Info($"Repay successfully, margin order id: {response.data}"); break; } case "error": { AppLogger.Info($"Repay fail, error code: {response.errorCode}, error message: {response.errorMessage}"); break; } } } }
private static void TransferCurrencyFromSubToMaster() { var accountClient = new SubUserClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var result = accountClient.TransferCurrencyFromSubToMasterAsync(Config.SubUserId, "ht", 0.01m).Result; _logger.StopAndLog(); if (result != null) { switch (result.status) { case "ok": { AppLogger.Info($"Transfer successfully, trade id: {result.data}"); break; } case "error": { AppLogger.Info($"Transfer fail, error code: {result.errorCode}, error message: {result.errorMessage}"); break; } } } }
private static void CreateSubUser() { var client = new SubUserClient(Config.AccessKey, Config.SecretKey); var user1 = new UserList { userName = "******", note = "note" }; var request = new CreateSubUserRequest(); request.userList = new UserList[1]; request.userList[0] = user1; var result = client.CreateSubUserAsync(request).Result; if (result != null) { if (result.code == (int)ResponseCode.Success && result.data != null) { AppLogger.Info($"Create {result.data.Length} sub users"); foreach (var creation in result.data) { AppLogger.Info($"Create sub user success, uid: {creation.uid}, userName: {creation.userName}"); } } else { AppLogger.Error($"Create sub user error: {result.message}"); } } }
private static void TransferPoint() { var client = new AccountClient(Config.AccessKey, Config.SecretKey); var request = new TransferPointRequest { fromUid = "125753978", toUid = "128654685", groupId = 0, amount = "0" }; _logger.Start(); var result = client.TransferPointAsync(request).Result; _logger.StopAndLog(); if (result != null && result.code == 200 && result.data != null) { AppLogger.Info($"Transfer point success, transact Id: {result.data.transactId}, time: {result.data.transactTime}"); } else { AppLogger.Error($"Transfer point error, code: {result.code}, message: {result.message}"); } }
private static void GetLastTrades() { var marketClient = new MarketClient(); _logger.Start(); var result = marketClient.GetLastTradesAsync("btcusdt", 3).Result; _logger.StopAndLog(); if (result != null && result.data != null) { var data = result.data; foreach (var d in data) { if (d.data != null) { foreach (var t in d.data) { AppLogger.Info($"singapore time: {Timestamp.MSToLocal(t.ts)}," + $" trade-id: {t.tradeId}, amount: {t.amount}, price: {t.price}, direction: {t.direction}"); } AppLogger.Info($"There are latest {d.data.Length} tradings"); } } } }
private static void GetAccountLedger() { var client = new AccountClient(Config.AccessKey, Config.SecretKey); _logger.Start(); GetRequest request = new GetRequest() .AddParam("accountId", Config.AccountId); var result = client.GetAccountLedgerAsync(request).Result; _logger.StopAndLog(); if (result != null) { if (result.code == (int)ResponseCode.Success && result.data != null) { AppLogger.Info($"Get account ledger, count={result.data.Length}"); foreach (var l in result.data) { AppLogger.Info($"Get account ledger, accountId: {l.accountId}, currency: {l.currency}, amount: {l.transactAmt}, transferer: {l.transferer}, transferee: {l.transferee}"); } } else { AppLogger.Info($"Get account ledger error: {result.message}"); } } }
private static void TransferFromFutureToSpot() { var accountClient = new AccountClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var result = accountClient.TransferFromFutureToSpotAsync("ht", 1).Result; _logger.StopAndLog(); if (result != null) { switch (result.status) { case "ok": { AppLogger.Info($"Transfer successfully, trade id: {result.data}"); break; } case "error": { AppLogger.Info($"Transfer fail, error code: {result.errorCode}, error message: {result.errorMessage}"); break; } } } }
private static void GetAccountHistory() { var accountClient = new AccountClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var request = new GetRequest() .AddParam("account-id", Config.AccountId); var result = accountClient.GetAccountHistoryAsync(request).Result; _logger.StopAndLog(); if (result != null) { switch (result.status) { case "ok": { AppLogger.Info($"Get account history, count={result.data.Length}"); foreach (var h in result.data) { AppLogger.Info($"currency: {h.currency}, amount: {h.transactAmt}, type: {h.transactType}, time: {h.transactTime}"); } break; } case "error": { AppLogger.Info($"Get fail, error code: {result.errorCode}, error message: {result.errorMessage}"); break; } } } }
private static void TransferAccount() { var client = new AccountClient(Config.AccessKey, Config.SecretKey); var request = new TransferAccountRequest { fromUser = 125753978, fromAccountType = "spot", fromAccount = 11136102, toUser = 128654510, toAccountType = "spot", toAccount = 12825690, currency = "ht", amount = "0.1" }; var result = client.TransferAccountAsync(request).Result; if (result != null) { if (result.status == "ok" && result.data != null) { AppLogger.Info($"Transfer account success, id: {result.data.transactId}, time: {result.data.transactTime}"); } else { AppLogger.Error($"Transfer account error, code: {result.errCode}, message: {result.errMessage}"); } } }
private static void GetCurrency() { var client = new CommonClient(); _logger.Start(); var currencyResponse = client.GetCurrencyAsync("", false).Result; _logger.StopAndLog(); if (currencyResponse != null) { if (currencyResponse.code == (int)ResponseCode.Success) { foreach (var d in currencyResponse.data) { AppLogger.Info($"Currency: {d.currency}"); foreach (var c in d.chains) { AppLogger.Info($"Chain name: {c.chain}, base chain: {c.baseChain}, base chain protocol: {c.baseChainProtocol}"); } } } else { AppLogger.Info(currencyResponse.message); } } }
private static void GetMatchResults() { var tradeClient = new OrderClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var request = new GetRequest() .AddParam("symbol", "htusdt") .AddParam("start-date", "2020-11-02"); var response = tradeClient.GetMatchResultsAsync(request).Result; _logger.StopAndLog(); switch (response.status) { case "ok": { if (response.data != null) { foreach (var r in response.data) { AppLogger.Info($"Match result order id: {r.orderId}, symbol: {r.symbol}, price: {r.price}, amount: {r.filledAmount}, fee: {r.filledFees}, state: {r.feeDeductState}"); } AppLogger.Info($"There are total {response.data.Length} match results"); } break; } case "error": { AppLogger.Info($"Get mattch result fail, error code: {response.errorCode}, error message: {response.errorMessage}"); break; } } }
private static void GetDepth() { var marketClient = new MarketClient(); _logger.Start(); var request = new GetRequest() .AddParam("symbol", "btcusdt") .AddParam("depth", "5") .AddParam("type", "step0"); var result = marketClient.GetDepthAsync(request).Result; _logger.StopAndLog(); if (result != null && result.tick != null) { var asks = result.tick.asks; if (asks != null) { for (int i = asks.Length - 1; i >= 0; i--) { AppLogger.Info($"[{asks[i][0]}, {asks[i][1]}]"); } } AppLogger.Info($"----------"); var bids = result.tick.bids; if (bids != null) { for (int i = 0; i < bids.Length; i++) { AppLogger.Info($"[{bids[i][0]}, {bids[i][1]}]"); } } } }
private static void GetTransactFeeRate() { var tradeClient = new OrderClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var request = new GetRequest() .AddParam("symbols", "btcusdt,eosht"); var response = tradeClient.GetTransactFeeRateAsync(request).Result; _logger.StopAndLog(); if (response.code == (int)ResponseCode.Success) { if (response.data != null) { foreach (var f in response.data) { AppLogger.Info($"Symbol: {f.symbol}, maker-taker fee: {f.makerFeeRate}-{f.takerFeeRate}"); } } } else { AppLogger.Info($"Get transact fee rate error: {response.message}"); } }
private static void CancelOrdersByCriteria() { var tradeClient = new OrderClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var request = new CancelOrdersByCriteriaRequest { AccountId = Config.AccountId }; var response = tradeClient.CancelOrdersByCriteriaAsync(request).Result; _logger.StopAndLog(); switch (response.status) { case "ok": { if (response.data != null) { var d = response.data; AppLogger.Info($"Cancel success: {d.successCount}, fail: {d.failedCount}, next: {d.nextId}"); } break; } case "error": { AppLogger.Info($"Cancel orders fail, error code: {response.errorCode}, error message: {response.errorMessage}"); break; } } }
private static void GetSubuserAccountBalance() { var accountClient = new SubUserClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var result = accountClient.GetSubUserAccountBalanceAsync(Config.SubUserId).Result; _logger.StopAndLog(); if (result != null && result.data != null) { foreach (var a in result.data) { int availableCount = 0; AppLogger.Info($"account id: {a.id}, type: {a.type}"); foreach (var b in a.list) { if (Math.Abs(float.Parse(b.balance)) > 0.00001) { availableCount++; AppLogger.Info($"currency: {b.currency}, type: {b.type}, balance: {b.balance}"); } } AppLogger.Info($"There are total {a.list.Length} accounts and available {availableCount} currencys in this account"); } AppLogger.Info($"There are total {result.data.Length} accounts"); } }
private static void GetOrderById() { var tradeClient = new OrderClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var response = tradeClient.GetOrderByIdAsync("1").Result; _logger.StopAndLog(); switch (response.status) { case "ok": { if (response.data != null) { var o = response.data; AppLogger.Info($"Order symbol: {o.symbol}, price: {o.price}, amount: {o.amount}," + $" filled amount: {o.filledAmount}, filled cash amount: {o.filledCashAmount}, filled fees: {o.filledFees}"); } break; } case "error": { AppLogger.Info($"Get order fail, error code: {response.errorCode}, error message: {response.errorMessage}"); break; } } }
private static void GetETFSwapHistory() { var etfClient = new ETFClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var response = etfClient.GetETFSwapHistory(0, 1).Result; _logger.StopAndLog(); if (response != null) { string message = string.IsNullOrEmpty(response.message) ? "" : response.message; if (response.success) { if (response.data != null) { foreach (var h in response.data) { AppLogger.Info($"Currency: {h.currency}, amount {h.amount}"); } AppLogger.Info($"There are total {response.data.Length} ETF swap history"); } } else { AppLogger.Info($"Get Swap history fail: {message}"); } } }
private static void GetOrderByClient() { var tradeClient = new OrderClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var request = new GetRequest() .AddParam("clientOrderId", "cid1234"); var response = tradeClient.GetOrderByClientAsync(request).Result; _logger.StopAndLog(); switch (response.status) { case "ok": { if (response.data != null) { var o = response.data; AppLogger.Info($"Order symbol: {o.symbol}, price: {o.price}, amount: {o.amount}"); } break; } case "error": { AppLogger.Info($"Get order fail, error code: {response.errorCode}, error message: {response.errorMessage}"); break; } } }
private static void ExchangeStableCoin() { var stableCoinClient = new StableCointClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var response = stableCoinClient.ExchangeStableCoinAsync("123").Result; _logger.StopAndLog(); if (response != null) { switch (response.status) { case "ok": { AppLogger.Info($"Exchange successfully"); break; } case "error": { AppLogger.Info($"Exchange fail, error code: {response.errorCode}, error message: {response.errorMessage}"); break; } } } }
private static void GetMatchResultsById() { var tradeClient = new OrderClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var response = tradeClient.GetMatchResultsByIdAsync("137534048832590").Result; _logger.StopAndLog(); switch (response.status) { case "ok": { if (response.data != null) { foreach (var r in response.data) { AppLogger.Info($"Match result symbol: {r.symbol}, amount: {r.filledAmount}, fee: {r.filledFees}, state: {r.feeDeductState}"); } AppLogger.Info($"There are total {response.data.Length} match results"); } break; } case "error": { AppLogger.Info($"Get match result fail, error code: {response.errorCode}, error message: {response.errorMessage}"); break; } } }
private static void GetRepayment() { var client = new CrossMarginClient(Config.AccessKey, Config.SecretKey); var request = new GetRepaymentRequest { accountId = Config.AccountId, currency = "htusdt" }; var result = client.GetRepayment(request).Result; if ((result.code == (int)ResponseCode.Success) && result.data != null) { AppLogger.Info($"Get repayment success, count: {result.data.Length}"); foreach (var r in result.data) { AppLogger.Info($"Repay id: {r.repayId}, time: {r.repayTime}, currency: {r.currency}, amount: {r.repaidAmount}"); } } else { AppLogger.Error($"Get repayment error, code: {result.code}, message: {result.message}"); } }
private static void GetLast48hOrders() { var tradeClient = new OrderClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var request = new GetRequest() .AddParam("symbol", "btcusdt"); var response = tradeClient.GetLast48hOrdersAsync(request).Result; _logger.StopAndLog(); switch (response.status) { case "ok": { if (response.data != null) { foreach (var o in response.data) { AppLogger.Info($"Order symbol: {o.symbol}, amount: {o.amount}, state: {o.state}"); } AppLogger.Info($"There are total {response.data.Length} history orders"); } break; } case "error": { AppLogger.Info($"Get history orders fail, error code: {response.errorCode}, error message: {response.errorMessage}"); break; } } }
private static void TransferOut() { var marginClient = new IsolatedMarginClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var response = marginClient.TransferOutAsync("eosht", "eos", "0.01").Result; _logger.StopAndLog(); if (response != null) { switch (response.status) { case "ok": { AppLogger.Info($"Transfer successfully, transfer id: {response.data}"); break; } case "error": { AppLogger.Info($"Transfer fail, error code: {response.errorCode}, error message: {response.errorMessage}"); break; } } } }
private static void PlaceOrder() { var tradeClient = new OrderClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var request = new PlaceOrderRequest { AccountId = Config.AccountId, type = "buy-limit", symbol = "btcusdt", source = "spot-api", amount = "1", price = "1.1" }; var response = tradeClient.PlaceOrderAsync(request).Result; _logger.StopAndLog(); switch (response.status) { case "ok": { AppLogger.Info($"Place order successfully, order id: {response.data}"); break; } case "error": { AppLogger.Info($"Place order fail, error code: {response.errorCode}, error message: {response.errorMessage}"); break; } } }
private static void WithdrawCurrency() { var walletClient = new WalletClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var request = new WithdrawRequest { address = "" }; var result = walletClient.WithdrawCurrencyAsync(request).Result; _logger.StopAndLog(); if (result != null) { switch (result.status) { case "ok": { AppLogger.Info($"Withdraw successfully, transfer id: {result.data}"); break; } case "error": { AppLogger.Info($"Withdraw fail, error code: {result.errorCode}, error message: {result.errorMessage}"); break; } } } }
private static void GetOpenOrders() { var client = new AlgoOrderClient(Config.AccessKey, Config.SecretKey); _logger.Start(); var request = new GetRequest() .AddParam("symbol", "htusdt"); var response = client.GetOpenOrdersAsync(request).Result; _logger.StopAndLog(); if (response.code == (int)ResponseCode.Success) { if (response.data != null) { AppLogger.Info($"There are total {response.data.Length} open algo orders"); foreach (var o in response.data) { AppLogger.Info($"Algo order symbol: {o.symbol}, price: {o.orderPrice}, status: {o.orderStatus}"); } } } else { AppLogger.Info($"Get open algo orders fail, error code: {response.code}, error message: {response.message}"); } }