@@ -40,7 +40,7 @@ function Manager(b) {
4040 savings = require ( './savings.js' ) ;
4141 /*if(!process.TESTING)*/ await bot . report ( true ) ;
4242 savings ( ) . setTickers ( Bot . tickers ) ;
43- if ( ! process . TESTING ) listen ( ) ;
43+ if ( ! process . TESTING || process . argv . length > 2 ) listen ( ) ;
4444 else {
4545 console . log ( "42:" , portfolio ) ;
4646 this . already = true ;
@@ -95,19 +95,19 @@ function Manager(b) {
9595 Note that handleArgs handles string arguments as collected from process.stdin.
9696 This means that true and 1, as args, are strings, not a boolean and a number.
9797 */
98- async function handleArgs ( bot , portfolio , args , uref = 0 ) {
98+ async function handleArgs ( bot , args , uref = 0 , p = portfolio ) {
9999 if ( [ 'args' , whoami ( ) ] . includes ( process . TESTING ) )
100100 console . log ( whoami ( ) , "called with " , arguments ) ;
101101 let buysell , xmrbtc , price , amt , posP ;
102102 if ( / ^ ( b u y | s e l l ) $ / . test ( args [ 0 ] ) ) {
103103 let pair ;
104104 [ buysell , xmrbtc , price , amt , posP ] = args ;
105- pair = Bot . findPair ( xmrbtc , portfolio . Numeraire , - 1 ) ;
105+ pair = Bot . findPair ( xmrbtc , p . Numeraire , - 1 ) ;
106106 if ( pair ) xmrbtc = pair [ 1 ] . base ;
107- if ( 'undefined' == typeof ( portfolio [ xmrbtc ] ) ) {
107+ if ( 'undefined' == typeof ( p [ xmrbtc ] ) ) {
108108 // Try the asset's altname
109109 // -----------------------
110- if ( 'undefined' == typeof ( portfolio [ Bot . alts [ xmrbtc ] ] ) )
110+ if ( 'undefined' == typeof ( p [ Bot . alts [ xmrbtc ] ] ) )
111111 throw new Error ( xmrbtc + " is not a recognized symbol. Try 'asset' command." ) ;
112112 console . log ( "Using" , Bot . alts [ xmrbtc ] , "instead of" , xmrbtc ) ;
113113 xmrbtc = Bot . alts [ xmrbtc ] ;
@@ -119,12 +119,12 @@ function Manager(b) {
119119
120120 // Do we need leverage?
121121 // --------------------
122- let lev = bot . getLev ( portfolio , buysell , price , amt , xmrbtc , posP ) ;
123- let cPrice = ! isNaN ( portfolio [ 'G' ] [ uref ] )
124- ? portfolio [ 'G' ] [ uref ] [ buysell == 'buy' ?'sell' :'buy' ] : 0 ;
122+ let lev = bot . getLev ( p , buysell , price , amt , xmrbtc , posP ) ;
123+ let cPrice = ! isNaN ( p [ 'G' ] [ uref ] )
124+ ? p [ 'G' ] [ uref ] [ buysell == 'buy' ?'sell' :'buy' ] : 0 ;
125125 // Without a record of a closing price, use the last one we found.
126126 // ---------------------------------------------------------------
127- if ( ! cPrice ) cPrice = portfolio [ xmrbtc ] [ 1 ] ;
127+ if ( ! cPrice ) cPrice = p [ xmrbtc ] [ 1 ] ;
128128 // When passing 1 as close, it will mean close at 1 (if Risky)
129129 // or at current price (without Risky)
130130 // -----------------------------------------------------------
@@ -135,16 +135,16 @@ function Manager(b) {
135135 console . log ( "New order: " + ret ) ;
136136 return ;
137137 } else if ( args [ 0 ] == 'set' ) {
138- await bot . set ( portfolio , args [ 1 ] , args [ 2 ] , args [ 3 ] ) ;
138+ await bot . set ( p , args [ 1 ] , args [ 2 ] , args [ 3 ] ) ;
139139 } else if ( args [ 0 ] == 'reset' ) {
140- portfolio [ 'G' ] = [ ] ;
141- await bot . listOpens ( portfolio ) ;
140+ p [ 'G' ] = [ ] ;
141+ await bot . listOpens ( ) ;
142142 } else if ( args [ 0 ] == 'delev' ) {
143- await bot . deleverage ( portfolio [ 'O' ] , args [ 1 ] - 1 ) ;
143+ await bot . deleverage ( p [ 'O' ] , args [ 1 ] - 1 ) ;
144144 } else if ( args [ 0 ] == 'addlev' ) {
145- await bot . deleverage ( portfolio [ 'O' ] , args [ 1 ] - 1 , true ) ;
145+ await bot . deleverage ( p [ 'O' ] , args [ 1 ] - 1 , true ) ;
146146 } else if ( args [ 0 ] == 'refnum' ) {
147- await bot . refnum ( portfolio [ 'O' ] , args [ 1 ] - 1 , args [ 2 ] ) ;
147+ await bot . refnum ( p [ 'O' ] , args [ 1 ] - 1 , args [ 2 ] ) ;
148148 } else if ( args [ 0 ] == 'list' ) {
149149 await bot . list ( args ) ;
150150 } else if ( / ^ ( l e s s | m o r e ) $ / . test ( args [ 0 ] ) ) {
@@ -159,7 +159,7 @@ function Manager(b) {
159159 }
160160 let label = args [ 3 ] ? args [ 3 ] : "default" ,
161161 tkr = 'REMOVE' == args [ 1 ] ? args [ 2 ] : args [ 1 ] ,
162- account = portfolio . Savings . find ( a => a . label == label ) ;
162+ account = p . Savings . find ( a => a . label == label ) ;
163163 if ( Bot . alts [ tkr ] ) tkr = Bot . alts [ tkr ] ;
164164 if ( ! account ) {
165165 if ( 'REMOVE' == args [ 1 ] ) {
@@ -175,15 +175,15 @@ function Manager(b) {
175175 assets :[ { ticker :tkr , amount :Number ( args [ 2 ] ) } ]
176176 } ) ;
177177 console . log ( "Created new account, " , label ) ;
178- portfolio . Savings . push ( JSON . parse ( account . save ( ) ) ) ;
178+ p . Savings . push ( JSON . parse ( account . save ( ) ) ) ;
179179 if ( args [ 3 ] ) account . labelMe ( args [ 3 ] ) ;
180180 } else {
181181 account = savings ( account ) ;
182182 }
183183 if ( 'REMOVE' == args [ 1 ] ) {
184184 if ( 'ACCOUNT' == args [ 2 ] . toUpperCase ( ) ) {
185- let smaller = portfolio . Savings . filter ( x => x . label != args [ 3 ] ) ;
186- portfolio . Savings = smaller ;
185+ let smaller = p . Savings . filter ( x => x . label != args [ 3 ] ) ;
186+ p . Savings = smaller ;
187187 bot . save ( ) ;
188188 console . log ( "Account" , label , "has been removed." ) ;
189189 } else {
@@ -200,10 +200,10 @@ function Manager(b) {
200200 bot . save ( ) ;
201201 }
202202 } else if ( args [ 0 ] == 'assets' ) {
203- let sav , pnum = portfolio . Numeraire ;
204- ret = portfolio . Savings . length + ': ' ;
205- for ( h = 0 ; h < portfolio . Savings . length ; ++ h ) {
206- sav = savings ( portfolio . Savings [ h ] ) ;
203+ let sav , pnum = p . Numeraire ;
204+ ret = p . Savings . length + ': ' ;
205+ for ( h = 0 ; h < p . Savings . length ; ++ h ) {
206+ sav = savings ( p . Savings [ h ] ) ;
207207 if ( ! ( args [ 1 ] ) || sav . label == args [ 1 ] )
208208 console . log ( h , sav . list ( ) ) ;
209209 else if ( args [ 1 ] ) {
@@ -214,7 +214,7 @@ function Manager(b) {
214214 // Include the assets on the Exchange
215215 // ----------------------------------
216216 sav = savings ( { label :'OnExchange' , assets :
217- [ { ticker :pnum , amount :portfolio [ pnum ] [ 0 ] } ] } ) ;
217+ [ { ticker :pnum , amount :p [ pnum ] [ 0 ] } ] } ) ;
218218 return ret ;
219219 } else if ( args [ 0 ] == 'allocation' ) {
220220 let d = await getAllocation ( true ) , c ; // Desired
@@ -285,8 +285,8 @@ function Manager(b) {
285285 if ( 'undefined' == typeof ( alloc )
286286 || isNaN ( p ) || isNaN ( a ) ) {
287287 console . log ( usage ) ;
288- } else if ( a < 0 || p < 0 || a > 100 * alloc . target || p > 100 ) {
289- console . log ( "apct must be between 0 and" , 100 * alloc . target ,
288+ } else if ( a < 0 || p < 0 || a > 100 * ( 1 - alloc . target ) || p > 100 ) {
289+ console . log ( "apct must be between 0 and" , 100 - 100 * alloc . target ,
290290 "and ppct must be between zero and 100." ) ;
291291 } else {
292292 t = alloc . ticker ;
@@ -297,14 +297,14 @@ function Manager(b) {
297297 if ( args . length < 3 || isNaN ( args [ 1 ] ) || isNaN ( args [ 2 ] ) ) {
298298 console . log ( "Usage: limits AtLeast AtMost\n" +
299299 "The allocation command will make trades only if the\n" +
300- "amount in " + portfolio . Numeraire + " is at least the \n" +
300+ "amount in " + p . Numeraire + " is at least the \n" +
301301 "AtLeast amount and no more than the AtMost amount.\n" +
302302 "If AtMost is -1, there is no upper limit (dangerous!)." ) ;
303303 } else if ( Number ( args [ 1 ] ) > Number ( args [ 2 ] ) && - 1 != Number ( args [ 2 ] ) ) {
304304 console . log ( "Doing nothing becuase you seem to have\n" +
305305 "switched the arguments." ) ;
306306 } else {
307- portfolio . limits = [ Number ( args [ 1 ] ) , Number ( args [ 2 ] ) ] ;
307+ p . limits = [ Number ( args [ 1 ] ) , Number ( args [ 2 ] ) ] ;
308308 bot . save ( ) ;
309309 }
310310 } else if ( args [ 0 ] == 'test' ) {
@@ -336,7 +336,7 @@ function Manager(b) {
336336 let args = cmds [ cdx ++ ] . split ( ' ' ) . map ( ( x ) => { return x . trim ( ) ; } ) ;
337337 console . log ( "...(" + cdx + ")> " + args . join ( ' ' ) ) ;
338338 //try {
339- if ( args [ 0 ] == 'kill' ) await bot . kill ( args [ 1 ] , bot . portfolio [ 'O' ] ) ;
339+ if ( args [ 0 ] == 'kill' ) await bot . kill ( args [ 1 ] , portfolio [ 'O' ] ) ;
340340 else if ( args [ 0 ] == "keys" ) { await bot . keys ( ) ; }
341341 else if ( args [ 0 ] == "ws" ) {
342342 if ( kwsCheck ) console . log ( "Kraken WebSocket heartbeat at " + kwsCheck ) ;
@@ -379,9 +379,9 @@ function Manager(b) {
379379 } else if ( args [ 0 ] == 'margin' ) {
380380 await bot . marginReport ( ) ;
381381 } else if ( args [ 0 ] == 'show' ) {
382- if ( args [ 2 ] ) console . log ( args [ 2 ] , { value :bot . portfolio [ args [ 1 ] ] [ args [ 2 ] ] } ) ;
383- if ( args [ 1 ] ) console . log ( args [ 1 ] , { value :bot . portfolio [ args [ 1 ] ] } ) ;
384- else console . log ( { Portfolio :bot . portfolio , Bot} ) ;
382+ if ( args [ 2 ] ) console . log ( args [ 2 ] , { value :portfolio [ args [ 1 ] ] [ args [ 2 ] ] } ) ;
383+ else if ( args [ 1 ] ) console . log ( args [ 1 ] , { value :portfolio [ args [ 1 ] ] } ) ;
384+ else console . log ( { Portfolio :portfolio , Bot} ) ;
385385 } else if ( args [ 0 ] == 'web' ) {
386386 if ( args [ 1 ] ) {
387387 if ( args [ 1 ] . toUpperCase ( ) == 'ON' )
@@ -392,7 +392,7 @@ function Manager(b) {
392392 + "This starts the web interface or stops it." ) ;
393393 }
394394 } else {
395- ret = await handleArgs ( bot , bot . portfolio , args , 0 ) ;
395+ ret = await handleArgs ( bot , args , 0 ) ;
396396 if ( bot . FLAGS . verbose ) console . log ( ret ) ;
397397 }
398398 //}
0 commit comments