@@ -20,6 +20,7 @@ public class OrderInstance
20
20
private Order LastOrderStats ;
21
21
private double StartingPrice ;
22
22
private double StartingAmount ;
23
+ private DateTime DecreaseTime ;
23
24
24
25
#endregion
25
26
@@ -47,6 +48,7 @@ public OrderInstance(int SL, int Algo, double MaximalPrice, double Limit, Pool P
47
48
OrderID = ID ;
48
49
StartingPrice = Price ;
49
50
StartingAmount = Amount ;
51
+ DecreaseTime = DateTime . Now - APIWrapper . PRICE_DECREASE_INTERVAL ;
50
52
51
53
OrderThread = new Thread ( ThreadRun ) ;
52
54
OrderThread . Start ( ) ;
@@ -233,8 +235,13 @@ private double GetMinimalNeededPrice(Order[] AllOrders, double TotalSpeed)
233
235
234
236
private bool IncreasePrice ( Order MyOrder , Order [ ] AllOrders , double MinimalPrice )
235
237
{
236
- // Do not make price higher if we are already on top of the list
237
- if ( AllOrders [ 0 ] == MyOrder ) return false ;
238
+ // Do not make price higher if we are already on top of the list (first alive).
239
+ foreach ( Order O in AllOrders )
240
+ {
241
+ if ( ! O . Alive ) continue ;
242
+ if ( O == MyOrder ) return false ;
243
+ else break ;
244
+ }
238
245
239
246
// Do not increase price, if we already have price higher or equal compared to minimal price.
240
247
if ( MyOrder . Price >= MinimalPrice ) return false ;
@@ -245,27 +252,39 @@ private bool IncreasePrice(Order MyOrder, Order[] AllOrders, double MinimalPrice
245
252
LibConsole . WriteLine ( LibConsole . TEXT_TYPE . INFO , "Setting price order #" + MyOrder . ID + " to " + MinimalPrice . ToString ( "F4" ) ) ;
246
253
double NewP = MyOrder . SetPrice ( MinimalPrice ) ;
247
254
if ( NewP > 0 ) MyOrder . Price = NewP ;
255
+
256
+ return true ;
248
257
}
249
258
else if ( MyOrder . Price < MaxPrice )
250
259
{
251
260
// We can at least set price to be MaxPrice
252
261
LibConsole . WriteLine ( LibConsole . TEXT_TYPE . INFO , "Setting price order #" + MyOrder . ID + " to " + MaxPrice . ToString ( "F4" ) ) ;
253
262
double NewP = MyOrder . SetPrice ( MaxPrice ) ;
254
263
if ( NewP > 0 ) MyOrder . Price = NewP ;
264
+
265
+ return true ;
255
266
}
256
267
257
- return true ; // Return true anyway, we don't want to check for price decrease, because we should increase the price.
268
+ return false ;
258
269
}
259
270
260
271
261
272
private void DecreasePrice ( Order MyOrder , Order [ ] AllOrders , double MinimalPrice )
262
273
{
263
- // Decrease only in case if we are still above or equal to minimal price.
264
- if ( MyOrder . Price + APIWrapper . PriceDecreaseSteps [ MyOrder . Algorithm ] >= MinimalPrice )
274
+ // Check time if decrase is possible.
275
+ if ( DecreaseTime + APIWrapper . PRICE_DECREASE_INTERVAL > DateTime . Now ) return ;
276
+
277
+ // Decrease only in case if we are still above or equal to minimal price. Or if we are above maximal price.
278
+ if ( MyOrder . Price + APIWrapper . PRICE_DECREASE_STEP [ MyOrder . Algorithm ] >= MinimalPrice ||
279
+ MyOrder . Price > MaxPrice )
265
280
{
266
- LibConsole . WriteLine ( LibConsole . TEXT_TYPE . INFO , "Decreasing price order #" + MyOrder . ID ) ;
267
281
double NewP = MyOrder . SetPriceDecrease ( ) ;
268
- if ( NewP > 0 ) MyOrder . Price = NewP ;
282
+ if ( NewP > 0 )
283
+ {
284
+ MyOrder . Price = NewP ;
285
+ LibConsole . WriteLine ( LibConsole . TEXT_TYPE . INFO , "Decreasing price order #" + MyOrder . ID + " to " + NewP . ToString ( "F4" ) ) ;
286
+ DecreaseTime = DateTime . Now ;
287
+ }
269
288
}
270
289
}
271
290
0 commit comments