MCPcopy
hub / github.com/thrasher-corp/gocryptotrader / WhaleBomb

Method WhaleBomb

engine/rpcserver.go:1282–1329  ·  view source on GitHub ↗

WhaleBomb finds the amount required to reach a specific price target for a given exchange, pair and asset type

(_ context.Context, r *gctrpc.WhaleBombRequest)

Source from the content-addressed store, hash-verified

1280// WhaleBomb finds the amount required to reach a specific price target for a given exchange, pair
1281// and asset type
1282func (s *RPCServer) WhaleBomb(_ context.Context, r *gctrpc.WhaleBombRequest) (*gctrpc.SimulateOrderResponse, error) {
1283 if r.Pair == nil {
1284 return nil, errCurrencyPairUnset
1285 }
1286
1287 exch, err := s.GetExchangeByName(r.Exchange)
1288 if err != nil {
1289 return nil, err
1290 }
1291
1292 a, err := asset.New(r.AssetType)
1293 if err != nil {
1294 return nil, err
1295 }
1296
1297 p := currency.NewPairWithDelimiter(r.Pair.Base, r.Pair.Quote, r.Pair.Delimiter)
1298
1299 err = checkParams(r.Exchange, exch, a, p)
1300 if err != nil {
1301 return nil, err
1302 }
1303
1304 o, err := exch.GetCachedOrderbook(p, a)
1305 if err != nil {
1306 return nil, err
1307 }
1308
1309 buy := strings.EqualFold(r.Side, order.Buy.String()) || strings.EqualFold(r.Side, order.Bid.String())
1310
1311 result, err := o.WhaleBomb(r.PriceTarget, buy)
1312 if err != nil {
1313 return nil, err
1314 }
1315 var resp gctrpc.SimulateOrderResponse
1316 for x := range result.Orders {
1317 resp.Orders = append(resp.Orders, &gctrpc.OrderbookItem{
1318 Price: result.Orders[x].Price,
1319 Amount: result.Orders[x].Amount,
1320 })
1321 }
1322
1323 resp.Amount = result.Amount
1324 resp.MaximumPrice = result.MaximumPrice
1325 resp.MinimumPrice = result.MinimumPrice
1326 resp.PercentageGainLoss = result.PercentageGainOrLoss
1327 resp.Status = result.Status
1328 return &resp, err
1329}
1330
1331// CancelOrder cancels an order specified by exchange, currency pair and asset
1332// type

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
NewPairWithDelimiterFunction · 0.92
checkParamsFunction · 0.85
GetExchangeByNameMethod · 0.65
GetCachedOrderbookMethod · 0.65
StringMethod · 0.65
WhaleBombMethod · 0.65

Tested by

no test coverage detected