SimulateOrder simulates an order specified by exchange, currency pair and asset type
(_ context.Context, r *gctrpc.SimulateOrderRequest)
| 1233 | // SimulateOrder simulates an order specified by exchange, currency pair and asset |
| 1234 | // type |
| 1235 | func (s *RPCServer) SimulateOrder(_ context.Context, r *gctrpc.SimulateOrderRequest) (*gctrpc.SimulateOrderResponse, error) { |
| 1236 | if r.Pair == nil { |
| 1237 | return nil, errCurrencyPairUnset |
| 1238 | } |
| 1239 | |
| 1240 | exch, err := s.GetExchangeByName(r.Exchange) |
| 1241 | if err != nil { |
| 1242 | return nil, err |
| 1243 | } |
| 1244 | |
| 1245 | p := currency.NewPairWithDelimiter(r.Pair.Base, r.Pair.Quote, r.Pair.Delimiter) |
| 1246 | |
| 1247 | err = checkParams(r.Exchange, exch, asset.Spot, p) |
| 1248 | if err != nil { |
| 1249 | return nil, err |
| 1250 | } |
| 1251 | |
| 1252 | o, err := exch.GetCachedOrderbook(p, asset.Spot) |
| 1253 | if err != nil { |
| 1254 | return nil, err |
| 1255 | } |
| 1256 | |
| 1257 | buy := strings.EqualFold(r.Side, order.Buy.String()) || strings.EqualFold(r.Side, order.Bid.String()) |
| 1258 | |
| 1259 | result, err := o.SimulateOrder(r.Amount, buy) |
| 1260 | if err != nil { |
| 1261 | return nil, err |
| 1262 | } |
| 1263 | |
| 1264 | var resp gctrpc.SimulateOrderResponse |
| 1265 | for x := range result.Orders { |
| 1266 | resp.Orders = append(resp.Orders, &gctrpc.OrderbookItem{ |
| 1267 | Price: result.Orders[x].Price, |
| 1268 | Amount: result.Orders[x].Amount, |
| 1269 | }) |
| 1270 | } |
| 1271 | |
| 1272 | resp.Amount = result.Amount |
| 1273 | resp.MaximumPrice = result.MaximumPrice |
| 1274 | resp.MinimumPrice = result.MinimumPrice |
| 1275 | resp.PercentageGainLoss = result.PercentageGainOrLoss |
| 1276 | resp.Status = result.Status |
| 1277 | return &resp, nil |
| 1278 | } |
| 1279 | |
| 1280 | // WhaleBomb finds the amount required to reach a specific price target for a given exchange, pair |
| 1281 | // and asset type |
nothing calls this directly
no test coverage detected