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

Method SubmitOrder

engine/rpcserver.go:1157–1231  ·  view source on GitHub ↗

SubmitOrder submits an order specified by exchange, currency pair and asset type

(ctx context.Context, r *gctrpc.SubmitOrderRequest)

Source from the content-addressed store, hash-verified

1155
1156// SubmitOrder submits an order specified by exchange, currency pair and asset type
1157func (s *RPCServer) SubmitOrder(ctx context.Context, r *gctrpc.SubmitOrderRequest) (*gctrpc.SubmitOrderResponse, error) {
1158 a, err := asset.New(r.AssetType)
1159 if err != nil {
1160 return nil, err
1161 }
1162
1163 var marginType margin.Type
1164 if r.MarginType != "" {
1165 marginType, err = margin.StringToMarginType(r.MarginType)
1166 if err != nil {
1167 return nil, err
1168 }
1169 }
1170 if r.Pair == nil {
1171 return nil, errCurrencyPairUnset
1172 }
1173
1174 exch, err := s.GetExchangeByName(r.Exchange)
1175 if err != nil {
1176 return nil, err
1177 }
1178
1179 p := currency.NewPairWithDelimiter(r.Pair.Base, r.Pair.Quote, r.Pair.Delimiter)
1180
1181 err = checkParams(r.Exchange, exch, a, p)
1182 if err != nil {
1183 return nil, err
1184 }
1185
1186 side, err := order.StringToOrderSide(r.Side)
1187 if err != nil {
1188 return nil, err
1189 }
1190
1191 oType, err := order.StringToOrderType(r.OrderType)
1192 if err != nil {
1193 return nil, err
1194 }
1195
1196 submission := &order.Submit{
1197 Pair: p,
1198 Side: side,
1199 Type: oType,
1200 Amount: r.Amount,
1201 Price: r.Price,
1202 ClientID: r.ClientId,
1203 ClientOrderID: r.ClientId,
1204 Exchange: r.Exchange,
1205 AssetType: a,
1206 }
1207 if r.MarginType != "" {
1208 submission.MarginType = marginType
1209 }
1210
1211 resp, err := s.OrderManager.Submit(ctx, submission)
1212 if err != nil {
1213 return &gctrpc.SubmitOrderResponse{}, err
1214 }

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
StringToMarginTypeFunction · 0.92
NewPairWithDelimiterFunction · 0.92
StringToOrderSideFunction · 0.92
StringToOrderTypeFunction · 0.92
checkParamsFunction · 0.85
SubmitMethod · 0.80
WasOrderPlacedMethod · 0.80
GetExchangeByNameMethod · 0.65

Tested by

no test coverage detected