MCPcopy
hub / github.com/danpaquin/coinbasepro-python / place_order

Method place_order

cbpro/authenticated_client.py:203–283  ·  view source on GitHub ↗

Place an order. The three order types (limit, market, and stop) can be placed using this method. Specific methods are provided for each order type, but if a more generic interface is desired this method is available. Args: product_id (str): Product to o

(self, product_id, side, order_type=None, **kwargs)

Source from the content-addressed store, hash-verified

201
202
203 def place_order(self, product_id, side, order_type=None, **kwargs):
204 """ Place an order.
205
206 The three order types (limit, market, and stop) can be placed using this
207 method. Specific methods are provided for each order type, but if a
208 more generic interface is desired this method is available.
209
210 Args:
211 product_id (str): Product to order (eg. 'BTC-USD')
212 side (str): Order side ('buy' or 'sell)
213 order_type (str): Order type ('limit', or 'market')
214 **client_oid (str): Order ID selected by you to identify your order.
215 This should be a UUID, which will be broadcast in the public
216 feed for `received` messages.
217 **stp (str): Self-trade prevention flag. cbpro doesn't allow self-
218 trading. This behavior can be modified with this flag.
219 Options:
220 'dc' Decrease and Cancel (default)
221 'co' Cancel oldest
222 'cn' Cancel newest
223 'cb' Cancel both
224 **overdraft_enabled (Optional[bool]): If true funding above and
225 beyond the account balance will be provided by margin, as
226 necessary.
227 **funding_amount (Optional[Decimal]): Amount of margin funding to be
228 provided for the order. Mutually exclusive with
229 `overdraft_enabled`.
230 **kwargs: Additional arguments can be specified for different order
231 types. See the limit/market/stop order methods for details.
232
233 Returns:
234 dict: Order details. Example::
235 {
236 "id": "d0c5340b-6d6c-49d9-b567-48c4bfca13d2",
237 "price": "0.10000000",
238 "size": "0.01000000",
239 "product_id": "BTC-USD",
240 "side": "buy",
241 "stp": "dc",
242 "type": "limit",
243 "time_in_force": "GTC",
244 "post_only": false,
245 "created_at": "2016-12-08T20:02:28.53864Z",
246 "fill_fees": "0.0000000000000000",
247 "filled_size": "0.00000000",
248 "executed_value": "0.0000000000000000",
249 "status": "pending",
250 "settled": false
251 }
252
253 """
254 # Margin parameter checks
255 if kwargs.get('overdraft_enabled') is not None and \
256 kwargs.get('funding_amount') is not None:
257 raise ValueError('Margin funding must be specified through use of '
258 'overdraft or by setting a funding amount, but not'
259 ' both')
260

Callers 11

buyMethod · 0.95
sellMethod · 0.95
place_limit_orderMethod · 0.95
place_market_orderMethod · 0.95
place_stop_orderMethod · 0.95
test_place_orderMethod · 0.80

Calls 1

_send_messageMethod · 0.80

Tested by 6

test_place_orderMethod · 0.64