@@ -172,12 +172,10 @@ where
172172 type Successful = R ;
173173 type Unsuccessful = BinanceHandlerError ;
174174
175- fn request_config ( & self ) -> RequestConfig {
176- let mut config = self . options . request_config . clone ( ) ;
177- if self . options . http_url != BinanceHttpUrl :: None {
175+ fn patch_request_config ( & self , config : & mut RequestConfig ) {
176+ if self . options . http_url == BinanceHttpUrl :: default ( ) {
178177 config. url_prefix = self . options . http_url . as_str ( ) . to_owned ( ) ;
179178 }
180- config
181179 }
182180
183181 #[ tracing:: instrument( skip_all, fields( ?builder) ) ]
@@ -227,6 +225,9 @@ where
227225 } )
228226 } else {
229227 // https://binance-docs.github.io/apidocs/spot/en/#limits
228+ //TODO: error parsing from status
229+ //let error_code = BinanceErrorCode::from(status.as_u16());
230+ //XXX: binance doesn't even return these
230231 if status == 429 || status == 418 {
231232 let retry_after = if let Some ( value) = headers. get ( "Retry-After" ) {
232233 if let Ok ( string) = value. to_str ( ) {
@@ -399,3 +400,201 @@ impl Default for BinanceOption {
399400 Self :: Default
400401 }
401402}
403+
404+ #[ derive( Debug , Serialize , Deserialize , PartialEq ) ]
405+ #[ serde( from = "i32" ) ]
406+ pub enum BinanceErrorCode {
407+ // 10xx - General Server/Network
408+ Unknown ,
409+ Disconnected ,
410+ Unauthorized ,
411+ TooManyRequests ,
412+ UnexpectedResponse ,
413+ Timeout ,
414+ ServerBusy ,
415+ InvalidMessage ,
416+ UnknownOrderComposition ,
417+ TooManyOrders ,
418+ ServiceShuttingDown ,
419+ UnsupportedOperation ,
420+ InvalidTimestamp ,
421+ InvalidSignature ,
422+
423+ // 11xx - Request issues
424+ IllegalChars ,
425+ TooManyParameters ,
426+ MandatoryParamEmptyOrMalformed ,
427+ UnknownParam ,
428+ UnreadParameters ,
429+ ParamEmpty ,
430+ ParamNotRequired ,
431+ ParamOverflow ,
432+ BadPrecision ,
433+ NoDepth ,
434+ TifNotRequired ,
435+ InvalidTif ,
436+ InvalidOrderType ,
437+ InvalidSide ,
438+ EmptyNewClOrdId ,
439+ EmptyOrgClOrdId ,
440+ BadInterval ,
441+ BadSymbol ,
442+ InvalidSymbolStatus ,
443+ InvalidListenKey ,
444+ MoreThanXXHours ,
445+ OptionalParamsBadCombo ,
446+ InvalidParameter ,
447+ BadStrategyType ,
448+ InvalidJson ,
449+ InvalidTickerType ,
450+ InvalidCancelRestrictions ,
451+ DuplicateSymbols ,
452+ InvalidSbeHeader ,
453+ UnsupportedSchemaId ,
454+ SbeDisabled ,
455+ OcoOrderTypeRejected ,
456+ OcoIcebergqtyTimeinforce ,
457+ DeprecatedSchema ,
458+ BuyOcoLimitMustBeBelow ,
459+ SellOcoLimitMustBeAbove ,
460+ BothOcoOrdersCannotBeLimit ,
461+ InvalidTagNumber ,
462+ TagNotDefinedInMessage ,
463+ TagAppearsMoreThanOnce ,
464+ TagOutOfOrder ,
465+ GroupFieldsOutOfOrder ,
466+ InvalidComponent ,
467+ ResetSeqNumSupport ,
468+ AlreadyLoggedIn ,
469+ GarbledMessage ,
470+ BadSenderCompid ,
471+ BadSeqNum ,
472+ ExpectedLogon ,
473+ TooManyMessages ,
474+ ParamsBadCombo ,
475+ NotAllowedInDropCopySessions ,
476+ DropCopySessionNotAllowed ,
477+ DropCopySessionRequired ,
478+ NotAllowedInOrderEntrySessions ,
479+ NotAllowedInMarketDataSessions ,
480+ IncorrectNumInGroupCount ,
481+ DuplicateEntriesInAGroup ,
482+ InvalidRequestId ,
483+ TooManySubscriptions ,
484+ BuyOcoStopLossMustBeAbove ,
485+ SellOcoStopLossMustBeBelow ,
486+ BuyOcoTakeProfitMustBeBelow ,
487+ SellOcoTakeProfitMustBeAbove ,
488+
489+ // 20xx - Business logic errors
490+ NewOrderRejected ,
491+ CancelRejected ,
492+ NoSuchOrder ,
493+ BadApiKeyFmt ,
494+ RejectedMbxKey ,
495+ NoTradingWindow ,
496+ OrderArchived ,
497+ OrderCancelReplacePartiallyFailed ,
498+ OrderCancelReplaceFailed ,
499+
500+ // Unknown error code
501+ Other ( i32 ) ,
502+ }
503+
504+ impl From < i32 > for BinanceErrorCode {
505+ fn from ( code : i32 ) -> Self {
506+ match code {
507+ -1000 => Self :: Unknown ,
508+ -1001 => Self :: Disconnected ,
509+ -1002 => Self :: Unauthorized ,
510+ -1003 => Self :: TooManyRequests ,
511+ -1006 => Self :: UnexpectedResponse ,
512+ -1007 => Self :: Timeout ,
513+ -1008 => Self :: ServerBusy ,
514+ -1013 => Self :: InvalidMessage ,
515+ -1014 => Self :: UnknownOrderComposition ,
516+ -1015 => Self :: TooManyOrders ,
517+ -1016 => Self :: ServiceShuttingDown ,
518+ -1020 => Self :: UnsupportedOperation ,
519+ -1021 => Self :: InvalidTimestamp ,
520+ -1022 => Self :: InvalidSignature ,
521+
522+ -1100 => Self :: IllegalChars ,
523+ -1101 => Self :: TooManyParameters ,
524+ -1102 => Self :: MandatoryParamEmptyOrMalformed ,
525+ -1103 => Self :: UnknownParam ,
526+ -1104 => Self :: UnreadParameters ,
527+ -1105 => Self :: ParamEmpty ,
528+ -1106 => Self :: ParamNotRequired ,
529+ -1108 => Self :: ParamOverflow ,
530+ -1111 => Self :: BadPrecision ,
531+ -1112 => Self :: NoDepth ,
532+ -1114 => Self :: TifNotRequired ,
533+ -1115 => Self :: InvalidTif ,
534+ -1116 => Self :: InvalidOrderType ,
535+ -1117 => Self :: InvalidSide ,
536+ -1118 => Self :: EmptyNewClOrdId ,
537+ -1119 => Self :: EmptyOrgClOrdId ,
538+ -1120 => Self :: BadInterval ,
539+ -1121 => Self :: BadSymbol ,
540+ -1122 => Self :: InvalidSymbolStatus ,
541+ -1125 => Self :: InvalidListenKey ,
542+ -1127 => Self :: MoreThanXXHours ,
543+ -1128 => Self :: OptionalParamsBadCombo ,
544+ -1130 => Self :: InvalidParameter ,
545+ -1134 => Self :: BadStrategyType ,
546+ -1135 => Self :: InvalidJson ,
547+ -1139 => Self :: InvalidTickerType ,
548+ -1145 => Self :: InvalidCancelRestrictions ,
549+ -1151 => Self :: DuplicateSymbols ,
550+ -1152 => Self :: InvalidSbeHeader ,
551+ -1153 => Self :: UnsupportedSchemaId ,
552+ -1155 => Self :: SbeDisabled ,
553+ -1158 => Self :: OcoOrderTypeRejected ,
554+ -1160 => Self :: OcoIcebergqtyTimeinforce ,
555+ -1161 => Self :: DeprecatedSchema ,
556+ -1165 => Self :: BuyOcoLimitMustBeBelow ,
557+ -1166 => Self :: SellOcoLimitMustBeAbove ,
558+ -1168 => Self :: BothOcoOrdersCannotBeLimit ,
559+ -1169 => Self :: InvalidTagNumber ,
560+ -1170 => Self :: TagNotDefinedInMessage ,
561+ -1171 => Self :: TagAppearsMoreThanOnce ,
562+ -1172 => Self :: TagOutOfOrder ,
563+ -1173 => Self :: GroupFieldsOutOfOrder ,
564+ -1174 => Self :: InvalidComponent ,
565+ -1175 => Self :: ResetSeqNumSupport ,
566+ -1176 => Self :: AlreadyLoggedIn ,
567+ -1177 => Self :: GarbledMessage ,
568+ -1178 => Self :: BadSenderCompid ,
569+ -1179 => Self :: BadSeqNum ,
570+ -1180 => Self :: ExpectedLogon ,
571+ -1181 => Self :: TooManyMessages ,
572+ -1182 => Self :: ParamsBadCombo ,
573+ -1183 => Self :: NotAllowedInDropCopySessions ,
574+ -1184 => Self :: DropCopySessionNotAllowed ,
575+ -1185 => Self :: DropCopySessionRequired ,
576+ -1186 => Self :: NotAllowedInOrderEntrySessions ,
577+ -1187 => Self :: NotAllowedInMarketDataSessions ,
578+ -1188 => Self :: IncorrectNumInGroupCount ,
579+ -1189 => Self :: DuplicateEntriesInAGroup ,
580+ -1190 => Self :: InvalidRequestId ,
581+ -1191 => Self :: TooManySubscriptions ,
582+ -1196 => Self :: BuyOcoStopLossMustBeAbove ,
583+ -1197 => Self :: SellOcoStopLossMustBeBelow ,
584+ -1198 => Self :: BuyOcoTakeProfitMustBeBelow ,
585+ -1199 => Self :: SellOcoTakeProfitMustBeAbove ,
586+
587+ -2010 => Self :: NewOrderRejected ,
588+ -2011 => Self :: CancelRejected ,
589+ -2013 => Self :: NoSuchOrder ,
590+ -2014 => Self :: BadApiKeyFmt ,
591+ -2015 => Self :: RejectedMbxKey ,
592+ -2016 => Self :: NoTradingWindow ,
593+ -2021 => Self :: OrderCancelReplacePartiallyFailed ,
594+ -2022 => Self :: OrderCancelReplaceFailed ,
595+ -2026 => Self :: OrderArchived ,
596+
597+ code => Self :: Other ( code) ,
598+ }
599+ }
600+ }
0 commit comments