private static void QueryEmptySellDetailAndUpdate(string userName, long orderId) { try { PlatformApi api = PlatformApi.GetInstance(userName); var orderDetail = api.QueryOrderDetail(orderId); if (orderDetail.Status == "ok" && orderDetail.Data.state == "filled") { var orderMatchResult = api.QueryOrderMatchResult(orderId); decimal minPrice = 25000; foreach (var item in orderMatchResult.Data) { if (minPrice > item.price) { minPrice = item.price; } } if (orderMatchResult.Status == "ok") { // 完成 new DogEmptySellDao().UpdateDogEmptySellWhenSuccess(orderId, orderDetail, orderMatchResult, minPrice); } } } catch (Exception ex) { logger.Error(ex.Message, ex); } }
private static void RunHistoryKline(CommonSymbols symbol) { Task.Run(() => { var countSuccess = 0; var countError = 0; PlatformApi api = PlatformApi.GetInstance("xx"); // 下面api和角色无关. 随便指定一个xx var begin = DateTime.Now; while (true) { try { var period = "1min"; var klines = api.GetHistoryKline(symbol.BaseCurrency + symbol.QuoteCurrency, period); var key = HistoryKlinePools.GetKey(symbol, period); HistoryKlinePools.Init(key, klines); countSuccess++; } catch (Exception ex) { countError++; } if (countSuccess % 20 == 0) { Console.WriteLine($"RunHistoryKline -> {symbol.BaseCurrency}, Success:{countSuccess}, Error:{countError}, AvageSecond:{(DateTime.Now - begin).TotalSeconds / (countSuccess + countError)}"); } Thread.Sleep(1000 * 6); } }); }
public static void RunAlert(CommonSymbol symbol, decimal big, decimal small) { Task.Run(() => { while (true) { try { PlatformApi api = PlatformApi.GetInstance("xx"); var period = "1min"; var klines = api.GetHistoryKline(symbol.BaseCurrency + symbol.QuoteCurrency, period); var nowPrice = klines[0].Close; Console.WriteLine(klines[0].Close); if (nowPrice > big) { System.Diagnostics.Process.Start("explorer.exe", "http://blog.csdn.net/testcs_dn"); } if (nowPrice < small) { System.Diagnostics.Process.Start("explorer.exe", "http://blog.csdn.net/testcs_dn"); } } catch (Exception ex) { } Thread.Sleep(1000 * 5); } }); }
private static void QueryEmptyBuyDetailAndUpdate(string userName, long orderId) { try { PlatformApi api = PlatformApi.GetInstance(userName); var orderDetail = api.QueryOrderDetail(orderId); Console.WriteLine($"orderDetail: {JsonConvert.SerializeObject(orderDetail)}"); if (orderDetail.Status == "ok" && orderDetail.Data.state == "filled") { var orderMatchResult = api.QueryOrderMatchResult(orderId); decimal maxPrice = 0; foreach (var item in orderMatchResult.Data) { if (maxPrice < item.price) { maxPrice = item.price; } } if (orderMatchResult.Status == "ok") { // 完成 new DogEmptyBuyDao().UpdateDogEmptyBuyWhenSuccess(orderId, orderDetail, orderMatchResult, maxPrice); } } } catch (Exception ex) { logger.Error(ex.Message, ex); } }
protected override void DoBind(EndPoint localAddress) { if (!this.Open) { return; } Debug.Assert(this.EventLoop.InEventLoop); if (!this.IsInState(StateFlags.Active)) { var address = (IPEndPoint)localAddress; var loopExecutor = (LoopExecutor)this.EventLoop; uint flags = PlatformApi.GetAddressFamily(address.AddressFamily); this.tcpListener = new TcpListener(loopExecutor.UnsafeLoop, flags); // Apply the configuration right after the tcp handle is created // because SO_REUSEPORT cannot be configured after bind this.config.Apply(); this.tcpListener.Bind(address); this.isBound = true; this.tcpListener.Listen((TcpServerChannelUnsafe)this.Unsafe, this.config.Backlog); this.CacheLocalAddress(); this.SetState(StateFlags.Active); } }
public async Task BuyTest(string quoteCurrency) { var symbols = CoinUtils.GetAllCommonSymbols(quoteCurrency); var account = AccountConfigUtils.GetAccountConfig("qq"); foreach (var symbol in symbols) { PlatformApi api = PlatformApi.GetInstance("qq"); OrderPlaceRequest req = new OrderPlaceRequest(); req.account_id = account.MainAccountId; req.amount = "0.0000001"; req.price = "0.001"; req.source = "api"; req.symbol = symbol.BaseCurrency + symbol.QuoteCurrency; req.type = "buy-limit"; try { HBResponse <long> order = api.OrderPlace(req); logger.Error($"3 ------------------------"); } catch (Exception ex) { logger.Error($"{ symbol.BaseCurrency + symbol.QuoteCurrency}" + ex.Message, ex); } } }
public static void InitMarketInDB(int index, CommonSymbol symbol, bool forceUpdate = false) { try { PlatformApi api = PlatformApi.GetInstance("xx"); // 下面api和角色无关. 随便指定一个xx var period = "1min"; var count = 12; var klines = api.GetHistoryKline(symbol.BaseCurrency + symbol.QuoteCurrency, period, count); if (klines == null || klines.Count == 0) { return; } var client = new RestClient("http://118.31.44.235/api/Control/newSymbolData"); RestRequest req = new RestRequest(Method.POST); req.AddHeader("content-type", "application/json"); req.AddHeader("cache-type", "no-cache"); req.AddJsonBody(new { BaseCurrency = symbol.BaseCurrency, QuoteCurrency = symbol.QuoteCurrency, HistoryKlines = klines }); var response = client.ExecuteTaskAsync(req).Result; } catch (Exception ex) { logger.Error("InitMarketInDB --> " + ex.Message, ex); } }
private static void QueryBuyDetailAndUpdate(string userName, long orderId) { try { PlatformApi api = PlatformApi.GetInstance(userName); var orderDetail = api.QueryOrderDetail(orderId); if (orderDetail.Status == "ok" && orderDetail.Data.state == "filled") { var orderMatchResult = api.QueryOrderMatchResult(orderId); if (orderMatchResult == null || orderMatchResult.Data == null) { return; } decimal maxPrice = 0; foreach (var item in orderMatchResult.Data) { if (maxPrice < item.price) { maxPrice = item.price; } } if (orderMatchResult.Status == "ok" && maxPrice > 0) { new DogMoreBuyDao().UpdateDogMoreBuySuccess(orderId, orderDetail, orderMatchResult, maxPrice); } } if (orderDetail.Status == "ok" && orderDetail.Data.state == StateConst.PartialCanceled) { var orderMatchResult = api.QueryOrderMatchResult(orderId); decimal maxPrice = 0; decimal buyQuantity = 0; foreach (var item in orderMatchResult.Data) { if (maxPrice < item.price) { maxPrice = item.price; } buyQuantity += item.FilledAmount; } if (orderMatchResult.Status == "ok") { new DogMoreBuyDao().UpdateDogMoreBuySuccess(orderId, buyQuantity, orderDetail, orderMatchResult, maxPrice); } } if (orderDetail.Status == "ok" && orderDetail.Data.state == StateConst.Canceled) { // 完成 new DogMoreBuyDao().UpdateDogMoreBuyWhenCancel(orderId); } } catch (Exception ex) { logger.Error(ex.Message, ex); logger.Error($"QueryBuyDetailAndUpdate, orderId:{orderId} 查询数据出错"); } }
public Window(PlatformApi platformApi) { _windowImplementation = platformApi switch { PlatformApi.GlfwDesktop => new GlfwWindow(), _ => throw new ArgumentOutOfRangeException(nameof(platformApi), platformApi, null) }; }
public async Task <object> List(string quoteCurrency) { try { var res = await new DogControlDao().ListDogControl(quoteCurrency); res = res.OrderBy(it => it.SymbolName).ToList(); var nowPriceList = new DogNowPriceDao().ListDogNowPrice(quoteCurrency); Dictionary <string, decimal> closeDic = new Dictionary <string, decimal>(); foreach (var item in nowPriceList) { if (item.QuoteCurrency != quoteCurrency) { continue; } closeDic.Add(item.SymbolName, item.NowPrice); } //var outList = new List<string> { "mtl", "ncash", "phx", "sbtc", "adx", "mtl", "mtl", "mtl", "mtl", "mtl" }; PlatformApi api = PlatformApi.GetInstance("xx"); var tickers = api.GetTickers(); var notInControl = new List <string>(); foreach (var ticker in tickers) { if (ticker.symbol.EndsWith(quoteCurrency)) { var find = res.Find(it => ticker.symbol.StartsWith(it.SymbolName)); if (find == null) { notInControl.Add(ticker.symbol); } } } return(new { list = res.Select(it => new { it.HistoryMin, it.HistoryMax, it.EmptyPrice, it.MaxInputPrice, it.QuoteCurrency, it.SymbolName, AvgPrice = decimal.Round(it.AvgPrice, 9).ToString() + (it.MaxInputPrice > it.AvgPrice ? " 大于加权平均 " : "") + " -- " + decimal.Round(it.Min8, 9).ToString() + (it.MaxInputPrice > it.Min8 ? " 大于8阶层" : ""), it.WillDelist, }).ToList(), closeDic, notInControl, allItems = res.Select(it => it.SymbolName).ToList() }); } catch (Exception ex) { logger.Error(ex.Message, ex); throw ex; } }
public static void SearchOrder(long orderId) { var userName = "******"; AccountConfig account = AccountConfigUtils.GetAccountConfig(userName); PlatformApi api = PlatformApi.GetInstance(userName); var orderDetail = api.QueryOrderDetail(orderId); Console.WriteLine(orderDetail.Status); Console.WriteLine(orderDetail.Data.state); if (orderDetail.Status == "ok" && orderDetail.Data.state == "filled") { Console.WriteLine(orderDetail.Data.price); Console.WriteLine(orderDetail.Data.id); Console.WriteLine(orderDetail.Data.symbol.Replace("usdt", "")); Console.WriteLine(orderDetail.Data.amount); if (new PigMoreDao().GetByBOrderId(orderId) != null) { Console.WriteLine("订单存在"); return; } new PigMoreDao().CreatePigMore(new PigMore() { Name = orderDetail.Data.symbol.Replace("usdt", ""), AccountId = account.MainAccountId, UserName = account.UserName, FlexPercent = (decimal)1.04, BQuantity = orderDetail.Data.amount, BOrderP = orderDetail.Data.price, BDate = DateTime.Now, BOrderResult = "", BState = StateConst.Submitting, BTradeP = 0, BOrderId = orderId, BFlex = "", BMemo = "", BOrderDetail = "", BOrderMatchResults = "", SOrderId = 0, SOrderResult = "", SDate = DateTime.MinValue, SFlex = "", SMemo = "", SOrderDetail = "", SOrderMatchResults = "", SOrderP = 0, SQuantity = 0, SState = "", STradeP = 0, }); } }
private static void RunCoin(List <CommonSymbol> symbols) { Task.Run(() => { while (true) { var begin = DateTime.Now; CoinTrade.RunCount = 0; try { var tickers = PlatformApi.GetInstance("xx").GetTickers(); for (var i = 0; i < symbols.Count; i++) { var symbol = symbols[i]; try { DateTime now = DateTime.Now; var bl = CoinTrade.Run(i, symbol, tickers); var mis = (DateTime.Now - now).TotalMilliseconds; if (mis > 1000) { Console.WriteLine("每轮------------------------>" + mis); } if (bl) { Thread.Sleep(150); } } catch (Exception ex) { logger.Error("RunCoin: " + ex.Message, ex); } } } catch (Exception ex) { logger.Error(ex.Message, ex); } var useTime = (DateTime.Now - begin).TotalSeconds; logger.Error("一轮总共耗时:" + (DateTime.Now - begin).TotalSeconds + ", 执行次数:" + CoinTrade.RunCount); Thread.Sleep(1000); if (DateTime.Now.Hour == 0 || DateTime.Now.Hour == 4 || DateTime.Now.Hour == 8 || DateTime.Now.Hour == 12 || DateTime.Now.Hour == 16 || DateTime.Now.Hour == 20) { if (DateTime.Now.Minute < 25) { new DogOrderStatDao().AddStatRecord(); } } } }); }
public static void RefreshHistoryMaxMinAsync(string symbolName, string quoteCurrency) { try { // 先计算最近500天的数据, 如果数据量少, 则计算4小时数据1000天 PlatformApi api = PlatformApi.GetInstance("xx"); var klines = api.GetHistoryKline(symbolName + quoteCurrency, "1day", 500); if (klines.Count < 180) { klines = api.GetHistoryKline(symbolName + quoteCurrency, "4hour", 1000); } var min = decimal.MinValue; var max = decimal.MaxValue; min = klines.Where(it => it.Low > min).Min(it => it.Low); min = klines.Where(it => it.Low > min).Min(it => it.Low); min = klines.Where(it => it.Low > min).Min(it => it.Low); max = klines.Where(it => it.High < max).Max(it => it.High); max = klines.Where(it => it.High < max).Max(it => it.High); max = klines.Where(it => it.High < max).Max(it => it.High); // 判断max var maxNotSell = new DogMoreBuyDao().GetMaxPriceOfNotSellFinished(quoteCurrency, symbolName); if (maxNotSell > max) { max = maxNotSell; } var avgPrice = (decimal)0; foreach (var item in klines) { avgPrice += (item.Open + item.Close) / 2; } avgPrice = avgPrice / klines.Count; var dogControl = new DogControl() { HistoryMax = max, HistoryMin = min, SymbolName = symbolName, QuoteCurrency = quoteCurrency, AvgPrice = avgPrice }; new DogControlDao().UpdateDogControlMaxAndMin(dogControl); } catch (Exception ex) { logger.Error(ex.Message, ex); throw ex; } }
public async Task <object> EmptyInfo(string userName, string symbolName, string quoteCurrency) { PlatformApi api = PlatformApi.GetInstance(userName); var accountInfo = api.GetAccountBalance(AccountConfigUtils.GetAccountConfig(userName).MainAccountId); var balanceItem = accountInfo.Data.list.Find(it => it.currency == symbolName); var list = new DogEmptySellDao().ListDogEmptySellNotFinished(symbolName, userName, quoteCurrency); var totalQuantity = new DogMoreBuyDao().GetBuyQuantityOfDogMoreBuyIsNotFinished(userName, symbolName); return(new { balanceItem, list, totalQuantity }); }
public static void GetAccount() { var userName = "******"; PlatformApi api = PlatformApi.GetInstance(userName); var accounts = api.GetAllAccount(); Console.WriteLine(JsonConvert.SerializeObject(accounts)); var account = api.GetAccountBalance("529880"); Console.WriteLine(JsonConvert.SerializeObject(account)); }
public static void SearchBuyOrder(long orderId) { var userName = "******"; AccountConfig account = AccountConfigUtils.GetAccountConfig(userName); PlatformApi api = PlatformApi.GetInstance(userName); var orderDetail = api.QueryOrderDetail(orderId); Console.WriteLine(orderDetail.Status); Console.WriteLine(orderDetail.Data.state); if (orderDetail.Status == "ok" && orderDetail.Data.state == "filled") { Console.WriteLine(JsonConvert.SerializeObject(orderDetail)); Console.WriteLine(orderDetail.Data.id); Console.WriteLine(orderDetail.Data.symbol.Replace("usdt", "")); Console.WriteLine(orderDetail.Data.amount); if (orderDetail.Data.type != "buy-limit") { Console.WriteLine(orderDetail.Data.type); Thread.Sleep(1000 * 60 * 5); } if (new DogMoreBuyDao().GetByBuyOrderId(orderId) != null) { Console.WriteLine("订单存在"); return; } new DogMoreBuyDao().CreateDogMoreBuy(new DogMoreBuy() { SymbolName = orderDetail.Data.symbol.Replace("usdt", ""), //QuoteCurrency = AccountId = account.MainAccountId, UserName = account.UserName, BuyQuantity = orderDetail.Data.amount, BuyOrderPrice = orderDetail.Data.price, BuyDate = DateTime.Now, BuyOrderResult = "", BuyState = StateConst.Submitting, BuyTradePrice = 0, BuyOrderId = orderId, BuyMemo = "", BuyOrderDetail = "", BuyOrderMatchResults = "", IsFinished = false }); } }
public static InputManager Create(PlatformApi api) { IEnumerable <IInputManagerFactory> systems = CollectSystems(); foreach (IInputManagerFactory system in systems) { if ((system.Api & api) == api || (api == PlatformApi.AutoDetect)) { return(system.Create()); } } throw new Exception("No Supported Input system found."); }
static void SetReuseAddress(TcpListener listener, int value) { try { PlatformApi.SetReuseAddress(listener, value); } catch (ObjectDisposedException ex) { throw new ChannelException(ex); } catch (SocketException ex) { throw new ChannelException(ex); } }
static void SetReuseAddress(Tcp tcp, int value) { try { PlatformApi.SetReuseAddress(tcp, value); } catch (ObjectDisposedException ex) { ThrowHelper.ThrowChannelException(ex); } catch (SocketException ex) { ThrowHelper.ThrowChannelException(ex); } }
static void SetReusePort(TcpListener listener, int value) { try { PlatformApi.SetReusePort(listener, value); } catch (ObjectDisposedException ex) { ThrowHelper.ThrowChannelException(ex); } catch (SocketException ex) { ThrowHelper.ThrowChannelException(ex); } }
public static List <HistoryKline> ListKlines(CommonSymbol symbol) { var now = DateTime.Now; PlatformApi api = PlatformApi.GetInstance("xx"); var period = "1min"; var count = 200; var klines = api.GetHistoryKline(symbol.BaseCurrency + symbol.QuoteCurrency, period, count); if (klines == null || klines.Count == 0) { return(null); } Console.WriteLine($"listklines: 花费时间:{(DateTime.Now - now).TotalMilliseconds}, {klines[0].Id} {klines[klines.Count - 1].Id}"); return(klines); }
bool GetReuseAddress() { try { var channel = (TcpChannel)this.Channel; var tcpListener = (Tcp)channel.GetHandle(); return(PlatformApi.GetReuseAddress(tcpListener)); } catch (ObjectDisposedException ex) { throw new ChannelException(ex); } catch (SocketException ex) { throw new ChannelException(ex); } }
/// <summary> /// Creates appropriate input system dependent on platform. /// </summary> /// <param name="api">Specifies which <see cref="PlatformApi"/> to use for the input</param> /// <param name="args">contains OS specific info (such as HWND and HINSTANCE for window apps), and access mode.</param> /// <returns>A reference to the created manager, or raises an Exception</returns> /// <exception cref="Exception">Exception</exception> /// <exception cref="ArgumentException">ArgumentException</exception> public static InputManager CreateInputSystem(PlatformApi api, ParameterList args) { InputManager im; // Since this is a required parameter for all InputManagers, check it here instead of having each if (!args.Any(p => { return(p.first.ToUpperInvariant() == "WINDOW"); })) { var ae = new ArgumentException("Cannot initialize InputManager instance, no 'WINDOW' parameter present."); //log.Error( "", ae ); throw ae; } im = PlatformFactory.Create(api); im._initialize(args); return(im); }
bool GetReuseAddress() { try { var channel = (INativeChannel)this.Channel; var tcpListener = (Tcp)channel.GetHandle(); return(PlatformApi.GetReuseAddress(tcpListener)); } catch (ObjectDisposedException ex) { ThrowHelper.ThrowChannelException(ex); } catch (SocketException ex) { ThrowHelper.ThrowChannelException(ex); } return(false); }
public static void InitOneKine(CommonSymbols symbol) { try { PlatformApi api = PlatformApi.GetInstance("xx"); // 下面api和角色无关. 随便指定一个xx var period = "1min"; var klines = api.GetHistoryKline(symbol.BaseCurrency + symbol.QuoteCurrency, period); var key = HistoryKlinePools.GetKey(symbol, period); HistoryKlinePools.Init(key, klines); // 记录到数据库 Record(symbol.BaseCurrency, klines[0]); } catch (Exception ex) { logger.Error("InitOneKine --> " + ex.Message, ex); } }
public static void RunAlert() { var symbols = CoinUtils.GetAllCommonSymbols("usdt"); Task.Run(() => { while (true) { try { foreach (var symbol in symbols) { PlatformApi api = PlatformApi.GetInstance("xx"); var period = "1min"; var klines = api.GetHistoryKline(symbol.BaseCurrency + symbol.QuoteCurrency, period); var nowPrice = klines[0].Close; // 5分钟内有5%, 或者 15分钟内有10% foreach (var item in klines) { if (Utils.GetDateById(item.Id) > DateTime.Now.AddMinutes(-5) && ( item.Close / nowPrice > (decimal)1.05 || nowPrice / item.Close > (decimal)1.05)) { Console.WriteLine($"{symbol.BaseCurrency}, now:{nowPrice} ->{ item.Close} "); OpenUrlUtils.Open(); } if (Utils.GetDateById(item.Id) > DateTime.Now.AddMinutes(-15) && ( item.Close / nowPrice > (decimal)1.10 || nowPrice / item.Close > (decimal)1.10)) { Console.WriteLine($"{symbol.BaseCurrency}, now:{nowPrice} ->{ item.Close} "); OpenUrlUtils.Open(); } } } } catch (Exception ex) { } } }); }
public void OrderPlaceTest() { PlatformApi api = PlatformApi.GetInstance("xx"); var accounts = api.GetAllAccount(); var spotAccountId = accounts.FirstOrDefault(a => a.Type == "spot" && a.State == "working")?.Id; if (spotAccountId <= 0) { throw new ArgumentException("spot account unavailable"); } OrderPlaceRequest req = new OrderPlaceRequest(); req.account_id = spotAccountId.ToString(); req.amount = "0.1"; req.price = "800"; req.source = "api"; req.symbol = "ethusdt"; req.type = "buy-limit"; var result = api.OrderPlace(req); //Assert.AreEqual(result.Status, "ok"); }
private static void QuerySellDetailAndUpdate(string userName, long orderId) { PlatformApi api = PlatformApi.GetInstance(userName); var orderDetail = api.QueryOrderDetail(orderId); if (orderDetail.Status == "ok" && orderDetail.Data.state == "filled") { var orderMatchResult = api.QueryOrderMatchResult(orderId); decimal minPrice = 99999999; foreach (var item in orderMatchResult.Data) { if (minPrice > item.price) { minPrice = item.price; } } // 完成 new PigMoreDao().UpdateTradeRecordSellSuccess(orderId, orderDetail, orderMatchResult, minPrice); } }
public static void ForceShouge(CommonSymbol symbol, decimal price, string orderId) { try { PlatformApi api = PlatformApi.GetInstance("xx"); var period = "1min"; var klines = api.GetHistoryKline(symbol.BaseCurrency + symbol.QuoteCurrency, period); var nowPrice = klines[0].Close; Console.WriteLine(klines[0].Close); if (nowPrice < price) { System.Diagnostics.Process.Start("explorer.exe", "http://118.31.44.235/api/empty/forceShouge?orderid=" + orderId); } } catch (Exception ex) { } Thread.Sleep(1000 * 5); }
private static void QueryBuyDetailAndUpdate(string userName, long orderId) { PlatformApi api = PlatformApi.GetInstance(userName); var orderDetail = api.QueryOrderDetail(orderId); if (orderDetail.Status == "ok" && orderDetail.Data.state == "filled") { var matchResult = api.QueryOrderMatchResult(orderId); decimal maxPrice = 0; foreach (var item in matchResult.Data) { if (maxPrice < item.price) { maxPrice = item.price; } } if (matchResult.Status == "ok") { new PigMoreDao().UpdatePigMoreBuySuccess(orderId, orderDetail, matchResult, maxPrice); } } }