@@ -12,7 +12,7 @@ namespace Telegram.CoinConvertBot.BgServices
1212{
1313 public class UpdateRateService : BaseScheduledService
1414 {
15- const string baseUrl = "https://www.okx .com" ;
15+ const string baseUrl = "https://www.binance .com" ;
1616 const string User_Agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" ;
1717 private readonly IConfiguration _configuration ;
1818 private readonly IServiceProvider _serviceProvider ;
@@ -58,81 +58,75 @@ protected override async Task ExecuteAsync()
5858 }
5959 else
6060 {
61- var side = "buy" ;
6261 try
6362 {
64-
6563 var convert1 = await baseUrl
6664 . WithClient ( client )
6765 . WithHeaders ( new { User_Agent } )
68- . AppendPathSegment ( "v2/asset/quick/exchange/ quote" )
66+ . AppendPathSegment ( "bapi/margin/v2/public/new-otc/get- quote" )
6967 //.SetQueryParams()
7068 . PostJsonAsync ( new
7169 {
72- side ,
73- baseCcy = Currency . TRX . ToString ( ) ,
74- quoteCcy = Currency . USDT . ToString ( ) ,
75- rfqSz = 1 ,
76- rfqSzCcy = Currency . USDT . ToString ( ) ,
70+ fromCoin = Currency . USDT . ToString ( ) ,
71+ toCoin = Currency . TRX . ToString ( ) ,
72+ requestAmount = 100 ,
73+ requestCoin = Currency . USDT . ToString ( ) ,
7774 } )
7875 . ReceiveJson < Root > ( ) ;
79- if ( convert1 . code == 0 )
76+ if ( convert1 . success )
8077 {
8178 list . Add ( new TokenRate
8279 {
8380 Id = $ "USDT_{ Currency . TRX } ",
8481 Currency = Currency . USDT ,
8582 ConvertCurrency = Currency . TRX ,
8683 LastUpdateTime = DateTime . Now ,
87- Rate = convert1 . data . askBaseSz ,
88- ReverseRate = convert1 . data . askPx ,
84+ Rate = convert1 . data . quotePrice ,
85+ ReverseRate = convert1 . data . inversePrice ,
8986 } ) ;
9087 }
9188 else
9289 {
93- // _logger.LogWarning("TRX -> USDT 汇率获取失败!错误信息:{msg}", convert1.msg ?? convert1.error_message );
90+ _logger . LogWarning ( "TRX -> USDT 汇率获取失败!错误信息:{msg}\n 详细错误信息:{msg2} " , convert1 . message ?? "无" , convert1 . messageDetail ?? "无" ) ;
9491 }
9592 }
9693 catch ( Exception e )
9794 {
9895 _logger . LogWarning ( "TRX -> USDT 汇率获取失败!错误信息:{msg}" , e ? . InnerException ? . Message + "; " + e ? . Message ) ;
9996 }
100- }
10197
102- foreach ( var item in list )
103- {
104- _logger . LogInformation ( "更新汇率,{a} -> {b} = {c}" , item . Currency , item . ConvertCurrency , item . Rate ) ;
105- await _repository . InsertOrUpdateAsync ( item ) ;
98+ foreach ( var item in list )
99+ {
100+ _logger . LogInformation ( "更新汇率,{a} -> {b} = {c}" , item . Currency , item . ConvertCurrency , item . Rate ) ;
101+ await _repository . InsertOrUpdateAsync ( item ) ;
102+ }
103+ _logger . LogInformation ( "------------------{tips}------------------" , "结束更新汇率" ) ;
106104 }
107- _logger . LogInformation ( "------------------{tips}------------------" , "结束更新汇率" ) ;
108105 }
106+ #pragma warning disable CS8618
107+ public class Root
108+ {
109+ public string code { get ; set ; }
110+ public string message { get ; set ; }
111+ public string messageDetail { get ; set ; }
112+ public Data data { get ; set ; }
113+ public bool success { get ; set ; }
114+ }
115+ public class Data
116+ {
117+ public decimal quotePrice { get ; set ; }
118+ public decimal inversePrice { get ; set ; }
119+ public int expireTime { get ; set ; }
120+ public long expireTimestamp { get ; set ; }
121+ public string fromCoin { get ; set ; }
122+ public string toCoin { get ; set ; }
123+ public decimal toCoinAmount { get ; set ; }
124+ public decimal fromCoinAmount { get ; set ; }
125+ public string requestCoin { get ; set ; }
126+ public decimal requestAmount { get ; set ; }
127+ public bool fromIsBase { get ; set ; }
128+ public bool split { get ; set ; }
129+ }
130+ #pragma warning restore CS8618
109131 }
110-
111- class Datum
112- {
113- public Currency baseCcy { get ; set ; }
114- public Currency quoteCcy { get ; set ; }
115- public decimal askPx { get ; set ; }
116- public decimal askQuoteSz { get ; set ; }
117- public decimal askBaseSz { get ; set ; }
118- }
119-
120- class Root
121- {
122- public int code { get ; set ; }
123- #pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
124- public Datum data { get ; set ; }
125- public string detailMsg { get ; set ; }
126- public string error_code { get ; set ; }
127- public string error_message { get ; set ; }
128- public string msg { get ; set ; }
129- #pragma warning restore CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
130- }
131-
132- enum OkxSide
133- {
134- Buy ,
135- Sell
136- }
137-
138132}
0 commit comments