@@ -72,17 +72,17 @@ func (wrapper *ExchangeWrapperSimulator) BuyMarket(market *environment.Market, a
72
72
remainingAmount := decimal .NewFromFloat (amount )
73
73
expense := decimal .Zero
74
74
75
- for _ , bid := range orderbook .Bids {
76
- if remainingAmount .LessThanOrEqual (bid .Quantity ) {
75
+ for _ , ask := range orderbook .Asks {
76
+ if remainingAmount .LessThanOrEqual (ask .Quantity ) {
77
77
totalQuote = totalQuote .Add (remainingAmount )
78
- expense = expense .Add (remainingAmount .Mul (bid .Value ))
78
+ expense = expense .Add (remainingAmount .Mul (ask .Value ))
79
79
if expense .GreaterThan (* baseBalance ) {
80
80
return "" , fmt .Errorf ("cannot Buy not enough %s balance" , market .BaseCurrency )
81
81
}
82
82
break
83
83
}
84
- totalQuote = totalQuote .Add (bid .Quantity )
85
- expense = expense .Add (bid .Quantity .Mul (bid .Value ))
84
+ totalQuote = totalQuote .Add (ask .Quantity )
85
+ expense = expense .Add (bid .Quantity .Mul (ask .Value ))
86
86
if expense .GreaterThan (* baseBalance ) {
87
87
return "" , fmt .Errorf ("cannot Buy not enough %s balance" , market .BaseCurrency )
88
88
}
@@ -116,14 +116,14 @@ func (wrapper *ExchangeWrapperSimulator) SellMarket(market *environment.Market,
116
116
return "" , fmt .Errorf ("Cannot Sell: not enough %s balance" , market .MarketCurrency )
117
117
}
118
118
119
- for _ , ask := range orderbook .Asks {
120
- if remainingAmount .LessThanOrEqual (ask .Quantity ) {
119
+ for _ , bid := range orderbook .Bids {
120
+ if remainingAmount .LessThanOrEqual (bid .Quantity ) {
121
121
totalQuote = totalQuote .Add (remainingAmount )
122
- gain = gain .Add (remainingAmount .Mul (ask .Value ))
122
+ gain = gain .Add (remainingAmount .Mul (bid .Value ))
123
123
break
124
124
}
125
- totalQuote = totalQuote .Add (ask .Quantity )
126
- gain = gain .Add (ask .Quantity .Mul (ask .Value ))
125
+ totalQuote = totalQuote .Add (bid .Quantity )
126
+ gain = gain .Add (ask .Quantity .Mul (bid .Value ))
127
127
}
128
128
129
129
wrapper .balances [market .BaseCurrency ] = baseBalance .Add (gain )
0 commit comments