@@ -5,6 +5,7 @@ import { decodeUTF8 } from 'tweetnacl-util';
55import WebSocket from 'ws' ;
66
77const SEND_INTERVAL = 500 ;
8+ const MAX_BUFFERED_AMOUNT = 10 * 1024 ; // 10 KB as worst case scenario
89
910type Quote = {
1011 bidPrice : BN ;
@@ -97,7 +98,10 @@ export class IndicativeQuotesSender {
9798 is_oracle_offset : quote . isOracleOffset ,
9899 } ;
99100 try {
100- if ( this . ws ?. readyState === WebSocket . OPEN ) {
101+ if (
102+ this . ws ?. readyState === WebSocket . OPEN &&
103+ this . ws ?. bufferedAmount < MAX_BUFFERED_AMOUNT
104+ ) {
101105 this . ws . send ( JSON . stringify ( message ) ) ;
102106 }
103107 } catch ( err ) {
@@ -123,7 +127,7 @@ export class IndicativeQuotesSender {
123127 ws . on ( 'unexpected-response' , async ( request , response ) => {
124128 console . error (
125129 'Unexpected response, reconnecting in 5s:' ,
126- response . statusCode
130+ response ? .statusCode
127131 ) ;
128132 setTimeout ( ( ) => {
129133 if ( this . heartbeatTimeout ) clearTimeout ( this . heartbeatTimeout ) ;
@@ -156,6 +160,22 @@ export class IndicativeQuotesSender {
156160 if ( ! this . connected ) {
157161 console . warn ( 'Setting quote before connected to the server, ignoring' ) ;
158162 }
163+ if (
164+ quote . marketIndex == null ||
165+ quote . bidPrice == null ||
166+ quote . askPrice == null ||
167+ quote . bidBaseAssetAmount == null ||
168+ quote . askBaseAssetAmount == null
169+ ) {
170+ console . warn (
171+ 'Received incomplete quote, ignoring and deleting old quote' ,
172+ quote
173+ ) ;
174+ if ( quote . marketIndex != null ) {
175+ this . quotes . delete ( quote . marketIndex ) ;
176+ }
177+ return ;
178+ }
159179 this . quotes . set ( quote . marketIndex , quote ) ;
160180 }
161181
0 commit comments