From 006e0bcf47aeabd2de181f9c9bf51eeec8e68c09 Mon Sep 17 00:00:00 2001 From: Passiv Ops Date: Thu, 19 Jun 2025 12:37:14 +0000 Subject: [PATCH 1/5] Regenerate SDKs --- .konfig/generate-id.txt | 2 +- README.md | 342 +-- lib/Api/CryptoTradingApi.php | 1576 ++++++++++++++ lib/Api/TradingApi.php | 3329 +++++++++-------------------- lib/Client.php | 3 + test/Api/CryptoTradingApiTest.php | 96 + test/Api/TradingApiTest.php | 36 - 7 files changed, 2800 insertions(+), 2584 deletions(-) create mode 100644 lib/Api/CryptoTradingApi.php create mode 100644 test/Api/CryptoTradingApiTest.php diff --git a/.konfig/generate-id.txt b/.konfig/generate-id.txt index b5594c3..dfbccd3 100644 --- a/.konfig/generate-id.txt +++ b/.konfig/generate-id.txt @@ -1 +1 @@ -7e414ad1-54b9-43e9-8767-cfcd23fb4c3b \ No newline at end of file +1dc41628-32db-4ae6-8a20-5b80ee3d317e \ No newline at end of file diff --git a/README.md b/README.md index d5deead..9e528d2 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,9 @@ Connect brokerage accounts to your app for live positions and trading * [`snaptrade.connections.removeBrokerageAuthorization`](#snaptradeconnectionsremovebrokerageauthorization) * [`snaptrade.connections.returnRates`](#snaptradeconnectionsreturnrates) * [`snaptrade.connections.sessionEvents`](#snaptradeconnectionssessionevents) + * [`snaptrade.cryptoTrading.getCryptocurrencyPairQuote`](#snaptradecryptotradinggetcryptocurrencypairquote) + * [`snaptrade.cryptoTrading.placeSimpleOrder`](#snaptradecryptotradingplacesimpleorder) + * [`snaptrade.cryptoTrading.searchCryptocurrencyPairInstruments`](#snaptradecryptotradingsearchcryptocurrencypairinstruments) * [`snaptrade.options.getOptionStrategy`](#snaptradeoptionsgetoptionstrategy) * [`snaptrade.options.getOptionsChain`](#snaptradeoptionsgetoptionschain) * [`snaptrade.options.getOptionsStrategyQuote`](#snaptradeoptionsgetoptionsstrategyquote) @@ -63,17 +66,14 @@ Connect brokerage accounts to your app for live positions and trading * [`snaptrade.referenceData.symbolSearchUserAccount`](#snaptradereferencedatasymbolsearchuseraccount) * [`snaptrade.trading.cancelOrder`](#snaptradetradingcancelorder) * [`snaptrade.trading.cancelUserAccountOrder`](#snaptradetradingcanceluseraccountorder) - * [`snaptrade.trading.getCryptocurrencyPairQuote`](#snaptradetradinggetcryptocurrencypairquote) * [`snaptrade.trading.getOrderImpact`](#snaptradetradinggetorderimpact) * [`snaptrade.trading.getUserAccountQuotes`](#snaptradetradinggetuseraccountquotes) * [`snaptrade.trading.placeBracketOrder`](#snaptradetradingplacebracketorder) * [`snaptrade.trading.placeForceOrder`](#snaptradetradingplaceforceorder) * [`snaptrade.trading.placeMlegOrder`](#snaptradetradingplacemlegorder) * [`snaptrade.trading.placeOrder`](#snaptradetradingplaceorder) - * [`snaptrade.trading.placeSimpleOrder`](#snaptradetradingplacesimpleorder) * [`snaptrade.trading.previewSimpleOrder`](#snaptradetradingpreviewsimpleorder) * [`snaptrade.trading.replaceOrder`](#snaptradetradingreplaceorder) - * [`snaptrade.trading.searchCryptocurrencyPairInstruments`](#snaptradetradingsearchcryptocurrencypairinstruments) * [`snaptrade.transactionsAndReporting.getActivities`](#snaptradetransactionsandreportinggetactivities) * [`snaptrade.transactionsAndReporting.getReportingCustomRange`](#snaptradetransactionsandreportinggetreportingcustomrange) @@ -1121,6 +1121,174 @@ Optional comma separated list of session IDs used to filter the request on speci --- +### `snaptrade.cryptoTrading.getCryptocurrencyPairQuote` + +Gets a quote for the specified account. + + + +#### 🛠️ Usage + +```php +$result = $snaptrade->cryptoTrading->getCryptocurrencyPairQuote( + user_id: "snaptrade-user-123", + user_secret: "adf2aa34-8219-40f7-a6b3-60156985cc61", + account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631", + instrument_symbol: "BTC-USD" +); +``` + +#### ⚙️ Parameters + +##### user_id: `string` + +##### user_secret: `string` + +##### account_id: `string` + +##### instrument_symbol: `string` + + +#### 🔄 Return + +[**CryptocurrencyPairQuote**](./lib/Model/CryptocurrencyPairQuote.php) + +#### 🌐 Endpoint + +`/accounts/{accountId}/trading/instruments/cryptocurrencyPairs/{instrumentSymbol}/quote` `GET` + +[🔙 **Back to Table of Contents**](#table-of-contents) + +--- + + +### `snaptrade.cryptoTrading.placeSimpleOrder` + +Places an order in the specified account. +This endpoint does not compute the impact to the account balance from the order before submitting the order. + + + +#### 🛠️ Usage + +```php +$result = $snaptrade->cryptoTrading->placeSimpleOrder( + instrument: [ + "symbol" => "AAPL", + "type" => "EQUITY", + ], + side: "BUY", + type: "MARKET", + time_in_force: "GTC", + amount: "123.45", + user_id: "snaptrade-user-123", + user_secret: "adf2aa34-8219-40f7-a6b3-60156985cc61", + account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631", + limit_price: "123.45", + stop_price: "123.45", + post_only: False, + expiration_date: "2024-01-01T00:00:00Z" +); +``` + +#### ⚙️ Parameters + +##### instrument: [`TradingInstrument`](./lib/Model/TradingInstrument.php) + +##### side: + +##### type: `string` + +The type of order to place. + +##### time_in_force: `string` + +The Time in Force type for the order. This field indicates how long the order will remain active before it is executed or expires. - `GTC` - Good Til Canceled. The order is valid until it is executed or canceled. - `FOK` - Fill Or Kill. The order must be executed in its entirety immediately or be canceled completely. - `IOC` - Immediate Or Cancel. The order must be executed immediately. Any portion of the order that cannot be filled immediately will be canceled. - `GTD` - Good Til Date. The order is valid until the specified date. + +##### amount: `float` + +The amount of the base currency to buy or sell. + +##### user_id: `string` + +##### user_secret: `string` + +##### account_id: `string` + +##### limit_price: `float` + +The limit price. Required if the order type is LIMIT, STOP_LOSS_LIMIT or TAKE_PROFIT_LIMIT. + +##### stop_price: `float` + +The stop price. Required if the order type is STOP_LOSS_MARKET, STOP_LOSS_LIMIT, TAKE_PROFIT_MARKET or TAKE_PROFIT_LIMIT. + +##### post_only: `bool` + +Valid and required only for order type LIMIT. If true orders that would be filled immediately are rejected to avoid incurring TAKER fees. + +##### expiration_date: `\DateTime` + +The expiration date of the order. Required if the time_in_force is GTD. + + +#### 🔄 Return + +[**OrderUpdatedResponse**](./lib/Model/OrderUpdatedResponse.php) + +#### 🌐 Endpoint + +`/accounts/{accountId}/trading/simple` `POST` + +[🔙 **Back to Table of Contents**](#table-of-contents) + +--- + + +### `snaptrade.cryptoTrading.searchCryptocurrencyPairInstruments` + +Searches cryptocurrency pairs instruments accessible to the specified account. + + + +#### 🛠️ Usage + +```php +$result = $snaptrade->cryptoTrading->searchCryptocurrencyPairInstruments( + user_id: "snaptrade-user-123", + user_secret: "adf2aa34-8219-40f7-a6b3-60156985cc61", + account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631", + base: "BTC", + quote: "USD" +); +``` + +#### ⚙️ Parameters + +##### user_id: `string` + +##### user_secret: `string` + +##### account_id: `string` + +##### base: `string` + +##### quote: `string` + + +#### 🔄 Return + +[**TradingSearchCryptocurrencyPairInstruments200Response**](./lib/Model/TradingSearchCryptocurrencyPairInstruments200Response.php) + +#### 🌐 Endpoint + +`/accounts/{accountId}/trading/instruments/cryptocurrencyPairs` `GET` + +[🔙 **Back to Table of Contents**](#table-of-contents) + +--- + + ### `snaptrade.options.getOptionStrategy` Creates an option strategy object that will be used to place an option strategy order. @@ -1773,47 +1941,6 @@ Order ID returned by brokerage. This is the unique identifier for the order in t --- -### `snaptrade.trading.getCryptocurrencyPairQuote` - -Gets a quote for the specified account. - - - -#### 🛠️ Usage - -```php -$result = $snaptrade->trading->getCryptocurrencyPairQuote( - user_id: "snaptrade-user-123", - user_secret: "adf2aa34-8219-40f7-a6b3-60156985cc61", - account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631", - instrument_symbol: "BTC-USD" -); -``` - -#### ⚙️ Parameters - -##### user_id: `string` - -##### user_secret: `string` - -##### account_id: `string` - -##### instrument_symbol: `string` - - -#### 🔄 Return - -[**CryptocurrencyPairQuote**](./lib/Model/CryptocurrencyPairQuote.php) - -#### 🌐 Endpoint - -`/accounts/{accountId}/trading/instruments/cryptocurrencyPairs/{instrumentSymbol}/quote` `GET` - -[🔙 **Back to Table of Contents**](#table-of-contents) - ---- - - ### `snaptrade.trading.getOrderImpact` Simulates an order and its impact on the account. This endpoint does not place the order with the brokerage. If successful, it returns a `Trade` object and the ID of the object can be used to place the order with the brokerage using the [place checked order endpoint](/reference/Trading/Trading_placeOrder). Please note that the `Trade` object returned expires after 5 minutes. Any order placed using an expired `Trade` will be rejected. @@ -2214,89 +2341,6 @@ Optional, defaults to true. Determines if a wait is performed to check on order --- -### `snaptrade.trading.placeSimpleOrder` - -Places an order in the specified account. -This endpoint does not compute the impact to the account balance from the order before submitting the order. - - - -#### 🛠️ Usage - -```php -$result = $snaptrade->trading->placeSimpleOrder( - instrument: [ - "symbol" => "AAPL", - "type" => "EQUITY", - ], - side: "BUY", - type: "MARKET", - time_in_force: "GTC", - amount: "123.45", - user_id: "snaptrade-user-123", - user_secret: "adf2aa34-8219-40f7-a6b3-60156985cc61", - account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631", - limit_price: "123.45", - stop_price: "123.45", - post_only: False, - expiration_date: "2024-01-01T00:00:00Z" -); -``` - -#### ⚙️ Parameters - -##### instrument: [`TradingInstrument`](./lib/Model/TradingInstrument.php) - -##### side: - -##### type: `string` - -The type of order to place. - -##### time_in_force: `string` - -The Time in Force type for the order. This field indicates how long the order will remain active before it is executed or expires. - `GTC` - Good Til Canceled. The order is valid until it is executed or canceled. - `FOK` - Fill Or Kill. The order must be executed in its entirety immediately or be canceled completely. - `IOC` - Immediate Or Cancel. The order must be executed immediately. Any portion of the order that cannot be filled immediately will be canceled. - `GTD` - Good Til Date. The order is valid until the specified date. - -##### amount: `float` - -The amount of the base currency to buy or sell. - -##### user_id: `string` - -##### user_secret: `string` - -##### account_id: `string` - -##### limit_price: `float` - -The limit price. Required if the order type is LIMIT, STOP_LOSS_LIMIT or TAKE_PROFIT_LIMIT. - -##### stop_price: `float` - -The stop price. Required if the order type is STOP_LOSS_MARKET, STOP_LOSS_LIMIT, TAKE_PROFIT_MARKET or TAKE_PROFIT_LIMIT. - -##### post_only: `bool` - -Valid and required only for order type LIMIT. If true orders that would be filled immediately are rejected to avoid incurring TAKER fees. - -##### expiration_date: `\DateTime` - -The expiration date of the order. Required if the time_in_force is GTD. - - -#### 🔄 Return - -[**OrderUpdatedResponse**](./lib/Model/OrderUpdatedResponse.php) - -#### 🌐 Endpoint - -`/accounts/{accountId}/trading/simple` `POST` - -[🔙 **Back to Table of Contents**](#table-of-contents) - ---- - - ### `snaptrade.trading.previewSimpleOrder` Previews an order using the specified account. @@ -2453,50 +2497,6 @@ The price at which a stop order is triggered for `Stop` and `StopLimit` orders. --- -### `snaptrade.trading.searchCryptocurrencyPairInstruments` - -Searches cryptocurrency pairs instruments accessible to the specified account. - - - -#### 🛠️ Usage - -```php -$result = $snaptrade->trading->searchCryptocurrencyPairInstruments( - user_id: "snaptrade-user-123", - user_secret: "adf2aa34-8219-40f7-a6b3-60156985cc61", - account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631", - base: "BTC", - quote: "USD" -); -``` - -#### ⚙️ Parameters - -##### user_id: `string` - -##### user_secret: `string` - -##### account_id: `string` - -##### base: `string` - -##### quote: `string` - - -#### 🔄 Return - -[**TradingSearchCryptocurrencyPairInstruments200Response**](./lib/Model/TradingSearchCryptocurrencyPairInstruments200Response.php) - -#### 🌐 Endpoint - -`/accounts/{accountId}/trading/instruments/cryptocurrencyPairs` `GET` - -[🔙 **Back to Table of Contents**](#table-of-contents) - ---- - - ### `snaptrade.transactionsAndReporting.getActivities` ![Deprecated](https://img.shields.io/badge/deprecated-yellow) diff --git a/lib/Api/CryptoTradingApi.php b/lib/Api/CryptoTradingApi.php new file mode 100644 index 0000000..7e27f30 --- /dev/null +++ b/lib/Api/CryptoTradingApi.php @@ -0,0 +1,1576 @@ + [ + 'application/json', + ], + 'placeSimpleOrder' => [ + 'application/json', + ], + 'searchCryptocurrencyPairInstruments' => [ + 'application/json', + ], + ]; + +/** + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector + * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec + */ + public function __construct( + Configuration $config = null, + ClientInterface $client = null, + HeaderSelector $selector = null, + $hostIndex = 0 + ) { + $clientOptions = []; + if (!$config->getVerifySsl()) $clientOptions["verify"] = false; + + // Do not truncate error messages + // https://github.com/guzzle/guzzle/issues/2185#issuecomment-800293420 + $stack = new HandlerStack(Utils::chooseHandler()); + $stack->push(Middleware::httpErrors(new BodySummarizer(10000)), 'http_errors'); + $stack->push(Middleware::redirect(), 'allow_redirects'); + $stack->push(Middleware::cookies(), 'cookies'); + $stack->push(Middleware::prepareBody(), 'prepare_body'); + $clientOptions["handler"] = $stack; + + $this->client = $client ?: new Client($clientOptions); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); + $this->hostIndex = $hostIndex; + } + + /** + * Set the host index + * + * @param int $hostIndex Host index (required) + */ + public function setHostIndex($hostIndex): void + { + $this->hostIndex = $hostIndex; + } + + /** + * Get the host index + * + * @return int Host index + */ + public function getHostIndex() + { + return $this->hostIndex; + } + + /** + * @return Configuration + */ + public function getConfig() + { + return $this->config; + } + + /** + * For initializing request body parameter + */ + private function setRequestBodyProperty(&$body, $property, $value) { + if ($body === null) $body = []; + // user did not pass in a value for this parameter + if ($value === SENTINEL_VALUE) return; + $body[$property] = $value; + } + + /** + * Operation getCryptocurrencyPairQuote + * + * Get cryptocurrency pair quote + * + * Gets a quote for the specified account. + * + * @param string $user_id user_id (required) + * @param string $user_secret user_secret (required) + * @param string $account_id account_id (required) + * @param string $instrument_symbol instrument_symbol (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getCryptocurrencyPairQuote'] to see the possible values for this operation + * + * @throws \SnapTrade\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \SnapTrade\Model\CryptocurrencyPairQuote|\SnapTrade\Model\Model400FailedRequestResponse + */ + public function getCryptocurrencyPairQuote( + $user_id, + $user_secret, + $account_id, + $instrument_symbol, + + string $contentType = self::contentTypes['getCryptocurrencyPairQuote'][0] + ) + { + + list($response) = $this->getCryptocurrencyPairQuoteWithHttpInfo($user_id, $user_secret, $account_id, $instrument_symbol, $contentType); + return $response; + } + + /** + * Operation getCryptocurrencyPairQuoteWithHttpInfo + * + * Get cryptocurrency pair quote + * + * Gets a quote for the specified account. + * + * @param string $user_id (required) + * @param string $user_secret (required) + * @param string $account_id (required) + * @param string $instrument_symbol (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getCryptocurrencyPairQuote'] to see the possible values for this operation + * + * @throws \SnapTrade\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \SnapTrade\Model\CryptocurrencyPairQuote|\SnapTrade\Model\Model400FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) + */ + public function getCryptocurrencyPairQuoteWithHttpInfo($user_id, $user_secret, $account_id, $instrument_symbol, string $contentType = self::contentTypes['getCryptocurrencyPairQuote'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + { + ["request" => $request, "serializedBody" => $serializedBody] = $this->getCryptocurrencyPairQuoteRequest($user_id, $user_secret, $account_id, $instrument_symbol, $contentType); + + // Customization hook + $this->beforeSendHook($request, $requestOptions, $this->config); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + if ( + ($e->getCode() == 401 || $e->getCode() == 403) && + !empty($this->getConfig()->getAccessToken()) && + $requestOptions->shouldRetryOAuth() + ) { + return $this->getCryptocurrencyPairQuoteWithHttpInfo( + $user_id, + $user_secret, + $account_id, + $instrument_symbol, + $contentType, + $requestOptions->setRetryOAuth(false) + ); + } + + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('\SnapTrade\Model\CryptocurrencyPairQuote' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\SnapTrade\Model\CryptocurrencyPairQuote' !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, '\SnapTrade\Model\CryptocurrencyPairQuote', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 400: + if ('\SnapTrade\Model\Model400FailedRequestResponse' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\SnapTrade\Model\Model400FailedRequestResponse' !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model400FailedRequestResponse', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = '\SnapTrade\Model\CryptocurrencyPairQuote'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SnapTrade\Model\CryptocurrencyPairQuote', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 400: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SnapTrade\Model\Model400FailedRequestResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getCryptocurrencyPairQuoteAsync + * + * Get cryptocurrency pair quote + * + * Gets a quote for the specified account. + * + * @param string $user_id (required) + * @param string $user_secret (required) + * @param string $account_id (required) + * @param string $instrument_symbol (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getCryptocurrencyPairQuote'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getCryptocurrencyPairQuoteAsync( + $user_id, + $user_secret, + $account_id, + $instrument_symbol, + + string $contentType = self::contentTypes['getCryptocurrencyPairQuote'][0] + ) + { + + return $this->getCryptocurrencyPairQuoteAsyncWithHttpInfo($user_id, $user_secret, $account_id, $instrument_symbol, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getCryptocurrencyPairQuoteAsyncWithHttpInfo + * + * Get cryptocurrency pair quote + * + * Gets a quote for the specified account. + * + * @param string $user_id (required) + * @param string $user_secret (required) + * @param string $account_id (required) + * @param string $instrument_symbol (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getCryptocurrencyPairQuote'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getCryptocurrencyPairQuoteAsyncWithHttpInfo($user_id, $user_secret, $account_id, $instrument_symbol, string $contentType = self::contentTypes['getCryptocurrencyPairQuote'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + { + $returnType = '\SnapTrade\Model\CryptocurrencyPairQuote'; + ["request" => $request, "serializedBody" => $serializedBody] = $this->getCryptocurrencyPairQuoteRequest($user_id, $user_secret, $account_id, $instrument_symbol, $contentType); + + // Customization hook + $this->beforeSendHook($request, $requestOptions, $this->config); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'getCryptocurrencyPairQuote' + * + * @param string $user_id (required) + * @param string $user_secret (required) + * @param string $account_id (required) + * @param string $instrument_symbol (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getCryptocurrencyPairQuote'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getCryptocurrencyPairQuoteRequest($user_id, $user_secret, $account_id, $instrument_symbol, string $contentType = self::contentTypes['getCryptocurrencyPairQuote'][0]) + { + + // Check if $user_id is a string + if ($user_id !== SENTINEL_VALUE && !is_string($user_id)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_id, true), gettype($user_id))); + } + // verify the required parameter 'user_id' is set + if ($user_id === SENTINEL_VALUE || (is_array($user_id) && count($user_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter user_id when calling getCryptocurrencyPairQuote' + ); + } + // Check if $user_secret is a string + if ($user_secret !== SENTINEL_VALUE && !is_string($user_secret)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_secret, true), gettype($user_secret))); + } + // verify the required parameter 'user_secret' is set + if ($user_secret === SENTINEL_VALUE || (is_array($user_secret) && count($user_secret) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter user_secret when calling getCryptocurrencyPairQuote' + ); + } + // Check if $account_id is a string + if ($account_id !== SENTINEL_VALUE && !is_string($account_id)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($account_id, true), gettype($account_id))); + } + // verify the required parameter 'account_id' is set + if ($account_id === SENTINEL_VALUE || (is_array($account_id) && count($account_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter account_id when calling getCryptocurrencyPairQuote' + ); + } + // Check if $instrument_symbol is a string + if ($instrument_symbol !== SENTINEL_VALUE && !is_string($instrument_symbol)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($instrument_symbol, true), gettype($instrument_symbol))); + } + // verify the required parameter 'instrument_symbol' is set + if ($instrument_symbol === SENTINEL_VALUE || (is_array($instrument_symbol) && count($instrument_symbol) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter instrument_symbol when calling getCryptocurrencyPairQuote' + ); + } + + + $resourcePath = '/accounts/{accountId}/trading/instruments/cryptocurrencyPairs/{instrumentSymbol}/quote'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + if ($user_id !== SENTINEL_VALUE) { + // query params + $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( + $user_id, + 'userId', // param base name + 'string', // openApiType + 'form', // style + true, // explode + true // required + ) ?? []); + } + if ($user_secret !== SENTINEL_VALUE) { + // query params + $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( + $user_secret, + 'userSecret', // param base name + 'string', // openApiType + 'form', // style + true, // explode + true // required + ) ?? []); + } + + + // path params + if ($account_id !== SENTINEL_VALUE) { + $resourcePath = str_replace( + '{' . 'accountId' . '}', + ObjectSerializer::toPathValue($account_id), + $resourcePath + ); + } + // path params + if ($instrument_symbol !== SENTINEL_VALUE) { + $resourcePath = str_replace( + '{' . 'instrumentSymbol' . '}', + ObjectSerializer::toPathValue($instrument_symbol), + $resourcePath + ); + } + + + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('clientId'); + if ($apiKey !== null) { + $queryParams['clientId'] = $apiKey; + } + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('Signature'); + if ($apiKey !== null) { + $headers['Signature'] = $apiKey; + } + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('timestamp'); + if ($apiKey !== null) { + $queryParams['timestamp'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $method = 'GET'; + $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return [ + "request" => new Request( + $method, + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ), + "serializedBody" => $httpBody + ]; + } + + /** + * Operation placeSimpleOrder + * + * Place order v2 + * + * Places an order in the specified account. This endpoint does not compute the impact to the account balance from the order before submitting the order. + * + * @param string $user_id user_id (required) + * @param string $user_secret user_secret (required) + * @param string $account_id account_id (required) + * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form simple_order_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeSimpleOrder'] to see the possible values for this operation + * + * @throws \SnapTrade\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \SnapTrade\Model\OrderUpdatedResponse|\SnapTrade\Model\Model400FailedRequestResponse + */ + public function placeSimpleOrder( + + $instrument, + $side, + $type, + $time_in_force, + $amount, + $user_id, + $user_secret, + $account_id, + $limit_price = SENTINEL_VALUE, + $stop_price = SENTINEL_VALUE, + $post_only = SENTINEL_VALUE, + $expiration_date = SENTINEL_VALUE, + string $contentType = self::contentTypes['placeSimpleOrder'][0] + ) + { + $_body = []; + $this->setRequestBodyProperty($_body, "instrument", $instrument); + $this->setRequestBodyProperty($_body, "side", $side); + $this->setRequestBodyProperty($_body, "type", $type); + $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); + $this->setRequestBodyProperty($_body, "amount", $amount); + $this->setRequestBodyProperty($_body, "limit_price", $limit_price); + $this->setRequestBodyProperty($_body, "stop_price", $stop_price); + $this->setRequestBodyProperty($_body, "post_only", $post_only); + $this->setRequestBodyProperty($_body, "expiration_date", $expiration_date); + $simple_order_form = $_body; + + list($response) = $this->placeSimpleOrderWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, $contentType); + return $response; + } + + /** + * Operation placeSimpleOrderWithHttpInfo + * + * Place order v2 + * + * Places an order in the specified account. This endpoint does not compute the impact to the account balance from the order before submitting the order. + * + * @param string $user_id (required) + * @param string $user_secret (required) + * @param string $account_id (required) + * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeSimpleOrder'] to see the possible values for this operation + * + * @throws \SnapTrade\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \SnapTrade\Model\OrderUpdatedResponse|\SnapTrade\Model\Model400FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) + */ + public function placeSimpleOrderWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, string $contentType = self::contentTypes['placeSimpleOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + { + ["request" => $request, "serializedBody" => $serializedBody] = $this->placeSimpleOrderRequest($user_id, $user_secret, $account_id, $simple_order_form, $contentType); + + // Customization hook + $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + if ( + ($e->getCode() == 401 || $e->getCode() == 403) && + !empty($this->getConfig()->getAccessToken()) && + $requestOptions->shouldRetryOAuth() + ) { + return $this->placeSimpleOrderWithHttpInfo( + $user_id, + $user_secret, + $account_id, + $simple_order_form, + $contentType, + $requestOptions->setRetryOAuth(false) + ); + } + + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('\SnapTrade\Model\OrderUpdatedResponse' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\SnapTrade\Model\OrderUpdatedResponse' !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, '\SnapTrade\Model\OrderUpdatedResponse', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 400: + if ('\SnapTrade\Model\Model400FailedRequestResponse' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\SnapTrade\Model\Model400FailedRequestResponse' !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model400FailedRequestResponse', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = '\SnapTrade\Model\OrderUpdatedResponse'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SnapTrade\Model\OrderUpdatedResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 400: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SnapTrade\Model\Model400FailedRequestResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation placeSimpleOrderAsync + * + * Place order v2 + * + * Places an order in the specified account. This endpoint does not compute the impact to the account balance from the order before submitting the order. + * + * @param string $user_id (required) + * @param string $user_secret (required) + * @param string $account_id (required) + * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeSimpleOrder'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function placeSimpleOrderAsync( + + $instrument, + $side, + $type, + $time_in_force, + $amount, + $user_id, + $user_secret, + $account_id, + $limit_price = SENTINEL_VALUE, + $stop_price = SENTINEL_VALUE, + $post_only = SENTINEL_VALUE, + $expiration_date = SENTINEL_VALUE, + string $contentType = self::contentTypes['placeSimpleOrder'][0] + ) + { + $_body = []; + $this->setRequestBodyProperty($_body, "instrument", $instrument); + $this->setRequestBodyProperty($_body, "side", $side); + $this->setRequestBodyProperty($_body, "type", $type); + $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); + $this->setRequestBodyProperty($_body, "amount", $amount); + $this->setRequestBodyProperty($_body, "limit_price", $limit_price); + $this->setRequestBodyProperty($_body, "stop_price", $stop_price); + $this->setRequestBodyProperty($_body, "post_only", $post_only); + $this->setRequestBodyProperty($_body, "expiration_date", $expiration_date); + $simple_order_form = $_body; + + return $this->placeSimpleOrderAsyncWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation placeSimpleOrderAsyncWithHttpInfo + * + * Place order v2 + * + * Places an order in the specified account. This endpoint does not compute the impact to the account balance from the order before submitting the order. + * + * @param string $user_id (required) + * @param string $user_secret (required) + * @param string $account_id (required) + * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeSimpleOrder'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function placeSimpleOrderAsyncWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, string $contentType = self::contentTypes['placeSimpleOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + { + $returnType = '\SnapTrade\Model\OrderUpdatedResponse'; + ["request" => $request, "serializedBody" => $serializedBody] = $this->placeSimpleOrderRequest($user_id, $user_secret, $account_id, $simple_order_form, $contentType); + + // Customization hook + $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'placeSimpleOrder' + * + * @param string $user_id (required) + * @param string $user_secret (required) + * @param string $account_id (required) + * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeSimpleOrder'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function placeSimpleOrderRequest($user_id, $user_secret, $account_id, $simple_order_form, string $contentType = self::contentTypes['placeSimpleOrder'][0]) + { + + // Check if $user_id is a string + if ($user_id !== SENTINEL_VALUE && !is_string($user_id)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_id, true), gettype($user_id))); + } + // verify the required parameter 'user_id' is set + if ($user_id === SENTINEL_VALUE || (is_array($user_id) && count($user_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter user_id when calling placeSimpleOrder' + ); + } + // Check if $user_secret is a string + if ($user_secret !== SENTINEL_VALUE && !is_string($user_secret)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_secret, true), gettype($user_secret))); + } + // verify the required parameter 'user_secret' is set + if ($user_secret === SENTINEL_VALUE || (is_array($user_secret) && count($user_secret) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter user_secret when calling placeSimpleOrder' + ); + } + // Check if $account_id is a string + if ($account_id !== SENTINEL_VALUE && !is_string($account_id)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($account_id, true), gettype($account_id))); + } + // verify the required parameter 'account_id' is set + if ($account_id === SENTINEL_VALUE || (is_array($account_id) && count($account_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter account_id when calling placeSimpleOrder' + ); + } + if ($simple_order_form !== SENTINEL_VALUE) { + if (!($simple_order_form instanceof \SnapTrade\Model\SimpleOrderForm)) { + if (!is_array($simple_order_form)) + throw new \InvalidArgumentException('"simple_order_form" must be associative array or an instance of \SnapTrade\Model\SimpleOrderForm CryptoTradingApi.placeSimpleOrder.'); + else + $simple_order_form = new \SnapTrade\Model\SimpleOrderForm($simple_order_form); + } + } + // verify the required parameter 'simple_order_form' is set + if ($simple_order_form === SENTINEL_VALUE || (is_array($simple_order_form) && count($simple_order_form) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter simple_order_form when calling placeSimpleOrder' + ); + } + + + $resourcePath = '/accounts/{accountId}/trading/simple'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + if ($user_id !== SENTINEL_VALUE) { + // query params + $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( + $user_id, + 'userId', // param base name + 'string', // openApiType + 'form', // style + true, // explode + true // required + ) ?? []); + } + if ($user_secret !== SENTINEL_VALUE) { + // query params + $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( + $user_secret, + 'userSecret', // param base name + 'string', // openApiType + 'form', // style + true, // explode + true // required + ) ?? []); + } + + + // path params + if ($account_id !== SENTINEL_VALUE) { + $resourcePath = str_replace( + '{' . 'accountId' . '}', + ObjectSerializer::toPathValue($account_id), + $resourcePath + ); + } + + + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (isset($simple_order_form)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($simple_order_form)); + } else { + $httpBody = $simple_order_form; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('clientId'); + if ($apiKey !== null) { + $queryParams['clientId'] = $apiKey; + } + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('Signature'); + if ($apiKey !== null) { + $headers['Signature'] = $apiKey; + } + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('timestamp'); + if ($apiKey !== null) { + $queryParams['timestamp'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $method = 'POST'; + $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return [ + "request" => new Request( + $method, + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ), + "serializedBody" => $httpBody + ]; + } + + /** + * Operation searchCryptocurrencyPairInstruments + * + * Search cryptocurrency pairs instruments + * + * Searches cryptocurrency pairs instruments accessible to the specified account. + * + * @param string $user_id user_id (required) + * @param string $user_secret user_secret (required) + * @param string $account_id account_id (required) + * @param string $base base (optional) + * @param string $quote quote (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['searchCryptocurrencyPairInstruments'] to see the possible values for this operation + * + * @throws \SnapTrade\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response|\SnapTrade\Model\Model400FailedRequestResponse + */ + public function searchCryptocurrencyPairInstruments( + $user_id, + $user_secret, + $account_id, + $base = SENTINEL_VALUE, + $quote = SENTINEL_VALUE, + + string $contentType = self::contentTypes['searchCryptocurrencyPairInstruments'][0] + ) + { + + list($response) = $this->searchCryptocurrencyPairInstrumentsWithHttpInfo($user_id, $user_secret, $account_id, $base, $quote, $contentType); + return $response; + } + + /** + * Operation searchCryptocurrencyPairInstrumentsWithHttpInfo + * + * Search cryptocurrency pairs instruments + * + * Searches cryptocurrency pairs instruments accessible to the specified account. + * + * @param string $user_id (required) + * @param string $user_secret (required) + * @param string $account_id (required) + * @param string $base (optional) + * @param string $quote (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['searchCryptocurrencyPairInstruments'] to see the possible values for this operation + * + * @throws \SnapTrade\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response|\SnapTrade\Model\Model400FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) + */ + public function searchCryptocurrencyPairInstrumentsWithHttpInfo($user_id, $user_secret, $account_id, $base = null, $quote = null, string $contentType = self::contentTypes['searchCryptocurrencyPairInstruments'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + { + ["request" => $request, "serializedBody" => $serializedBody] = $this->searchCryptocurrencyPairInstrumentsRequest($user_id, $user_secret, $account_id, $base, $quote, $contentType); + + // Customization hook + $this->beforeSendHook($request, $requestOptions, $this->config); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + if ( + ($e->getCode() == 401 || $e->getCode() == 403) && + !empty($this->getConfig()->getAccessToken()) && + $requestOptions->shouldRetryOAuth() + ) { + return $this->searchCryptocurrencyPairInstrumentsWithHttpInfo( + $user_id, + $user_secret, + $account_id, + $base, + $quote, + $contentType, + $requestOptions->setRetryOAuth(false) + ); + } + + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('\SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response' !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, '\SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + case 400: + if ('\SnapTrade\Model\Model400FailedRequestResponse' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\SnapTrade\Model\Model400FailedRequestResponse' !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model400FailedRequestResponse', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = '\SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + case 400: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SnapTrade\Model\Model400FailedRequestResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation searchCryptocurrencyPairInstrumentsAsync + * + * Search cryptocurrency pairs instruments + * + * Searches cryptocurrency pairs instruments accessible to the specified account. + * + * @param string $user_id (required) + * @param string $user_secret (required) + * @param string $account_id (required) + * @param string $base (optional) + * @param string $quote (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['searchCryptocurrencyPairInstruments'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function searchCryptocurrencyPairInstrumentsAsync( + $user_id, + $user_secret, + $account_id, + $base = SENTINEL_VALUE, + $quote = SENTINEL_VALUE, + + string $contentType = self::contentTypes['searchCryptocurrencyPairInstruments'][0] + ) + { + + return $this->searchCryptocurrencyPairInstrumentsAsyncWithHttpInfo($user_id, $user_secret, $account_id, $base, $quote, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation searchCryptocurrencyPairInstrumentsAsyncWithHttpInfo + * + * Search cryptocurrency pairs instruments + * + * Searches cryptocurrency pairs instruments accessible to the specified account. + * + * @param string $user_id (required) + * @param string $user_secret (required) + * @param string $account_id (required) + * @param string $base (optional) + * @param string $quote (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['searchCryptocurrencyPairInstruments'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function searchCryptocurrencyPairInstrumentsAsyncWithHttpInfo($user_id, $user_secret, $account_id, $base = null, $quote = null, string $contentType = self::contentTypes['searchCryptocurrencyPairInstruments'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + { + $returnType = '\SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response'; + ["request" => $request, "serializedBody" => $serializedBody] = $this->searchCryptocurrencyPairInstrumentsRequest($user_id, $user_secret, $account_id, $base, $quote, $contentType); + + // Customization hook + $this->beforeSendHook($request, $requestOptions, $this->config); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'searchCryptocurrencyPairInstruments' + * + * @param string $user_id (required) + * @param string $user_secret (required) + * @param string $account_id (required) + * @param string $base (optional) + * @param string $quote (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['searchCryptocurrencyPairInstruments'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function searchCryptocurrencyPairInstrumentsRequest($user_id, $user_secret, $account_id, $base = SENTINEL_VALUE, $quote = SENTINEL_VALUE, string $contentType = self::contentTypes['searchCryptocurrencyPairInstruments'][0]) + { + + // Check if $user_id is a string + if ($user_id !== SENTINEL_VALUE && !is_string($user_id)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_id, true), gettype($user_id))); + } + // verify the required parameter 'user_id' is set + if ($user_id === SENTINEL_VALUE || (is_array($user_id) && count($user_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter user_id when calling searchCryptocurrencyPairInstruments' + ); + } + // Check if $user_secret is a string + if ($user_secret !== SENTINEL_VALUE && !is_string($user_secret)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_secret, true), gettype($user_secret))); + } + // verify the required parameter 'user_secret' is set + if ($user_secret === SENTINEL_VALUE || (is_array($user_secret) && count($user_secret) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter user_secret when calling searchCryptocurrencyPairInstruments' + ); + } + // Check if $account_id is a string + if ($account_id !== SENTINEL_VALUE && !is_string($account_id)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($account_id, true), gettype($account_id))); + } + // verify the required parameter 'account_id' is set + if ($account_id === SENTINEL_VALUE || (is_array($account_id) && count($account_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter account_id when calling searchCryptocurrencyPairInstruments' + ); + } + // Check if $base is a string + if ($base !== SENTINEL_VALUE && !is_string($base)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($base, true), gettype($base))); + } + // Check if $quote is a string + if ($quote !== SENTINEL_VALUE && !is_string($quote)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($quote, true), gettype($quote))); + } + + + $resourcePath = '/accounts/{accountId}/trading/instruments/cryptocurrencyPairs'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + if ($user_id !== SENTINEL_VALUE) { + // query params + $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( + $user_id, + 'userId', // param base name + 'string', // openApiType + 'form', // style + true, // explode + true // required + ) ?? []); + } + if ($user_secret !== SENTINEL_VALUE) { + // query params + $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( + $user_secret, + 'userSecret', // param base name + 'string', // openApiType + 'form', // style + true, // explode + true // required + ) ?? []); + } + if ($base !== SENTINEL_VALUE) { + // query params + $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( + $base, + 'base', // param base name + 'string', // openApiType + 'form', // style + true, // explode + false // required + ) ?? []); + } + if ($quote !== SENTINEL_VALUE) { + // query params + $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( + $quote, + 'quote', // param base name + 'string', // openApiType + 'form', // style + true, // explode + false // required + ) ?? []); + } + + + // path params + if ($account_id !== SENTINEL_VALUE) { + $resourcePath = str_replace( + '{' . 'accountId' . '}', + ObjectSerializer::toPathValue($account_id), + $resourcePath + ); + } + + + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\json_encode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('clientId'); + if ($apiKey !== null) { + $queryParams['clientId'] = $apiKey; + } + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('Signature'); + if ($apiKey !== null) { + $headers['Signature'] = $apiKey; + } + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('timestamp'); + if ($apiKey !== null) { + $queryParams['timestamp'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $method = 'GET'; + $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return [ + "request" => new Request( + $method, + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ), + "serializedBody" => $httpBody + ]; + } + + /** + * Create http client option + * + * @throws \RuntimeException on file opening failure + * @return array of http client options + */ + protected function createHttpClientOption() + { + $options = []; + if ($this->config->getDebug()) { + $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a'); + if (!$options[RequestOptions::DEBUG]) { + throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile()); + } + } + + return $options; + } +} diff --git a/lib/Api/TradingApi.php b/lib/Api/TradingApi.php index 644fb07..96286bc 100644 --- a/lib/Api/TradingApi.php +++ b/lib/Api/TradingApi.php @@ -68,9 +68,6 @@ class TradingApi extends \SnapTrade\CustomApi 'cancelUserAccountOrder' => [ 'application/json', ], - 'getCryptocurrencyPairQuote' => [ - 'application/json', - ], 'getOrderImpact' => [ 'application/json', ], @@ -89,18 +86,12 @@ class TradingApi extends \SnapTrade\CustomApi 'placeOrder' => [ 'application/json', ], - 'placeSimpleOrder' => [ - 'application/json', - ], 'previewSimpleOrder' => [ 'application/json', ], 'replaceOrder' => [ 'application/json', ], - 'searchCryptocurrencyPairInstruments' => [ - 'application/json', - ], ]; /** @@ -1106,59 +1097,75 @@ public function cancelUserAccountOrderRequest($user_id, $user_secret, $account_i } /** - * Operation getCryptocurrencyPairQuote + * Operation getOrderImpact * - * Get cryptocurrency pair quote + * Check order impact * - * Gets a quote for the specified account. + * Simulates an order and its impact on the account. This endpoint does not place the order with the brokerage. If successful, it returns a `Trade` object and the ID of the object can be used to place the order with the brokerage using the [place checked order endpoint](/reference/Trading/Trading_placeOrder). Please note that the `Trade` object returned expires after 5 minutes. Any order placed using an expired `Trade` will be rejected. * * @param string $user_id user_id (required) * @param string $user_secret user_secret (required) - * @param string $account_id account_id (required) - * @param string $instrument_symbol instrument_symbol (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getCryptocurrencyPairQuote'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeForm $manual_trade_form manual_trade_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderImpact'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return \SnapTrade\Model\CryptocurrencyPairQuote|\SnapTrade\Model\Model400FailedRequestResponse + * @return \SnapTrade\Model\ManualTradeAndImpact|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse */ - public function getCryptocurrencyPairQuote( + public function getOrderImpact( + + $account_id, + $action, + $universal_symbol_id, + $order_type, + $time_in_force, $user_id, $user_secret, - $account_id, - $instrument_symbol, - - string $contentType = self::contentTypes['getCryptocurrencyPairQuote'][0] + $price = SENTINEL_VALUE, + $stop = SENTINEL_VALUE, + $units = SENTINEL_VALUE, + $notional_value = SENTINEL_VALUE, + string $contentType = self::contentTypes['getOrderImpact'][0] ) { + $_body = []; + $this->setRequestBodyProperty($_body, "account_id", $account_id); + $this->setRequestBodyProperty($_body, "action", $action); + $this->setRequestBodyProperty($_body, "universal_symbol_id", $universal_symbol_id); + $this->setRequestBodyProperty($_body, "order_type", $order_type); + $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); + $this->setRequestBodyProperty($_body, "price", $price); + $this->setRequestBodyProperty($_body, "stop", $stop); + $this->setRequestBodyProperty($_body, "units", $units); + $this->setRequestBodyProperty($_body, "notional_value", $notional_value); + $manual_trade_form = $_body; - list($response) = $this->getCryptocurrencyPairQuoteWithHttpInfo($user_id, $user_secret, $account_id, $instrument_symbol, $contentType); + list($response) = $this->getOrderImpactWithHttpInfo($user_id, $user_secret, $manual_trade_form, $contentType); return $response; } /** - * Operation getCryptocurrencyPairQuoteWithHttpInfo + * Operation getOrderImpactWithHttpInfo * - * Get cryptocurrency pair quote + * Check order impact * - * Gets a quote for the specified account. + * Simulates an order and its impact on the account. This endpoint does not place the order with the brokerage. If successful, it returns a `Trade` object and the ID of the object can be used to place the order with the brokerage using the [place checked order endpoint](/reference/Trading/Trading_placeOrder). Please note that the `Trade` object returned expires after 5 minutes. Any order placed using an expired `Trade` will be rejected. * * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param string $instrument_symbol (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getCryptocurrencyPairQuote'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeForm $manual_trade_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderImpact'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return array of \SnapTrade\Model\CryptocurrencyPairQuote|\SnapTrade\Model\Model400FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) + * @return array of \SnapTrade\Model\ManualTradeAndImpact|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) */ - public function getCryptocurrencyPairQuoteWithHttpInfo($user_id, $user_secret, $account_id, $instrument_symbol, string $contentType = self::contentTypes['getCryptocurrencyPairQuote'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function getOrderImpactWithHttpInfo($user_id, $user_secret, $manual_trade_form, string $contentType = self::contentTypes['getOrderImpact'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { - ["request" => $request, "serializedBody" => $serializedBody] = $this->getCryptocurrencyPairQuoteRequest($user_id, $user_secret, $account_id, $instrument_symbol, $contentType); + ["request" => $request, "serializedBody" => $serializedBody] = $this->getOrderImpactRequest($user_id, $user_secret, $manual_trade_form, $contentType); // Customization hook - $this->beforeSendHook($request, $requestOptions, $this->config); + $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); try { $options = $this->createHttpClientOption(); @@ -1170,11 +1177,10 @@ public function getCryptocurrencyPairQuoteWithHttpInfo($user_id, $user_secret, $ !empty($this->getConfig()->getAccessToken()) && $requestOptions->shouldRetryOAuth() ) { - return $this->getCryptocurrencyPairQuoteWithHttpInfo( + return $this->getOrderImpactWithHttpInfo( $user_id, $user_secret, - $account_id, - $instrument_symbol, + $manual_trade_form, $contentType, $requestOptions->setRetryOAuth(false) ); @@ -1212,17 +1218,17 @@ public function getCryptocurrencyPairQuoteWithHttpInfo($user_id, $user_secret, $ switch($statusCode) { case 200: - if ('\SnapTrade\Model\CryptocurrencyPairQuote' === '\SplFileObject') { + if ('\SnapTrade\Model\ManualTradeAndImpact' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); - if ('\SnapTrade\Model\CryptocurrencyPairQuote' !== 'string') { + if ('\SnapTrade\Model\ManualTradeAndImpact' !== 'string') { $content = json_decode($content); } } return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\CryptocurrencyPairQuote', []), + ObjectSerializer::deserialize($content, '\SnapTrade\Model\ManualTradeAndImpact', []), $response->getStatusCode(), $response->getHeaders() ]; @@ -1241,9 +1247,24 @@ public function getCryptocurrencyPairQuoteWithHttpInfo($user_id, $user_secret, $ $response->getStatusCode(), $response->getHeaders() ]; + case 403: + if ('\SnapTrade\Model\Model403FailedRequestResponse' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\SnapTrade\Model\Model403FailedRequestResponse' !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model403FailedRequestResponse', []), + $response->getStatusCode(), + $response->getHeaders() + ]; } - $returnType = '\SnapTrade\Model\CryptocurrencyPairQuote'; + $returnType = '\SnapTrade\Model\ManualTradeAndImpact'; if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { @@ -1264,7 +1285,7 @@ public function getCryptocurrencyPairQuoteWithHttpInfo($user_id, $user_secret, $ case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), - '\SnapTrade\Model\CryptocurrencyPairQuote', + '\SnapTrade\Model\ManualTradeAndImpact', $e->getResponseHeaders() ); $e->setResponseObject($data); @@ -1277,38 +1298,63 @@ public function getCryptocurrencyPairQuoteWithHttpInfo($user_id, $user_secret, $ ); $e->setResponseObject($data); break; + case 403: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SnapTrade\Model\Model403FailedRequestResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; } throw $e; } } /** - * Operation getCryptocurrencyPairQuoteAsync + * Operation getOrderImpactAsync * - * Get cryptocurrency pair quote + * Check order impact * - * Gets a quote for the specified account. + * Simulates an order and its impact on the account. This endpoint does not place the order with the brokerage. If successful, it returns a `Trade` object and the ID of the object can be used to place the order with the brokerage using the [place checked order endpoint](/reference/Trading/Trading_placeOrder). Please note that the `Trade` object returned expires after 5 minutes. Any order placed using an expired `Trade` will be rejected. * * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param string $instrument_symbol (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getCryptocurrencyPairQuote'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeForm $manual_trade_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderImpact'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getCryptocurrencyPairQuoteAsync( + public function getOrderImpactAsync( + + $account_id, + $action, + $universal_symbol_id, + $order_type, + $time_in_force, $user_id, $user_secret, - $account_id, - $instrument_symbol, - - string $contentType = self::contentTypes['getCryptocurrencyPairQuote'][0] + $price = SENTINEL_VALUE, + $stop = SENTINEL_VALUE, + $units = SENTINEL_VALUE, + $notional_value = SENTINEL_VALUE, + string $contentType = self::contentTypes['getOrderImpact'][0] ) { + $_body = []; + $this->setRequestBodyProperty($_body, "account_id", $account_id); + $this->setRequestBodyProperty($_body, "action", $action); + $this->setRequestBodyProperty($_body, "universal_symbol_id", $universal_symbol_id); + $this->setRequestBodyProperty($_body, "order_type", $order_type); + $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); + $this->setRequestBodyProperty($_body, "price", $price); + $this->setRequestBodyProperty($_body, "stop", $stop); + $this->setRequestBodyProperty($_body, "units", $units); + $this->setRequestBodyProperty($_body, "notional_value", $notional_value); + $manual_trade_form = $_body; - return $this->getCryptocurrencyPairQuoteAsyncWithHttpInfo($user_id, $user_secret, $account_id, $instrument_symbol, $contentType) + return $this->getOrderImpactAsyncWithHttpInfo($user_id, $user_secret, $manual_trade_form, $contentType) ->then( function ($response) { return $response[0]; @@ -1317,28 +1363,27 @@ function ($response) { } /** - * Operation getCryptocurrencyPairQuoteAsyncWithHttpInfo + * Operation getOrderImpactAsyncWithHttpInfo * - * Get cryptocurrency pair quote + * Check order impact * - * Gets a quote for the specified account. + * Simulates an order and its impact on the account. This endpoint does not place the order with the brokerage. If successful, it returns a `Trade` object and the ID of the object can be used to place the order with the brokerage using the [place checked order endpoint](/reference/Trading/Trading_placeOrder). Please note that the `Trade` object returned expires after 5 minutes. Any order placed using an expired `Trade` will be rejected. * * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param string $instrument_symbol (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getCryptocurrencyPairQuote'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeForm $manual_trade_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderImpact'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getCryptocurrencyPairQuoteAsyncWithHttpInfo($user_id, $user_secret, $account_id, $instrument_symbol, string $contentType = self::contentTypes['getCryptocurrencyPairQuote'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function getOrderImpactAsyncWithHttpInfo($user_id, $user_secret, $manual_trade_form, string $contentType = self::contentTypes['getOrderImpact'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { - $returnType = '\SnapTrade\Model\CryptocurrencyPairQuote'; - ["request" => $request, "serializedBody" => $serializedBody] = $this->getCryptocurrencyPairQuoteRequest($user_id, $user_secret, $account_id, $instrument_symbol, $contentType); + $returnType = '\SnapTrade\Model\ManualTradeAndImpact'; + ["request" => $request, "serializedBody" => $serializedBody] = $this->getOrderImpactRequest($user_id, $user_secret, $manual_trade_form, $contentType); // Customization hook - $this->beforeSendHook($request, $requestOptions, $this->config); + $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); return $this->client ->sendAsync($request, $this->createHttpClientOption()) @@ -1377,18 +1422,17 @@ function ($exception) { } /** - * Create request for operation 'getCryptocurrencyPairQuote' + * Create request for operation 'getOrderImpact' * * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param string $instrument_symbol (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getCryptocurrencyPairQuote'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeForm $manual_trade_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderImpact'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ - public function getCryptocurrencyPairQuoteRequest($user_id, $user_secret, $account_id, $instrument_symbol, string $contentType = self::contentTypes['getCryptocurrencyPairQuote'][0]) + public function getOrderImpactRequest($user_id, $user_secret, $manual_trade_form, string $contentType = self::contentTypes['getOrderImpact'][0]) { // Check if $user_id is a string @@ -1398,7 +1442,7 @@ public function getCryptocurrencyPairQuoteRequest($user_id, $user_secret, $accou // verify the required parameter 'user_id' is set if ($user_id === SENTINEL_VALUE || (is_array($user_id) && count($user_id) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter user_id when calling getCryptocurrencyPairQuote' + 'Missing the required parameter user_id when calling getOrderImpact' ); } // Check if $user_secret is a string @@ -1408,32 +1452,26 @@ public function getCryptocurrencyPairQuoteRequest($user_id, $user_secret, $accou // verify the required parameter 'user_secret' is set if ($user_secret === SENTINEL_VALUE || (is_array($user_secret) && count($user_secret) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter user_secret when calling getCryptocurrencyPairQuote' - ); - } - // Check if $account_id is a string - if ($account_id !== SENTINEL_VALUE && !is_string($account_id)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($account_id, true), gettype($account_id))); - } - // verify the required parameter 'account_id' is set - if ($account_id === SENTINEL_VALUE || (is_array($account_id) && count($account_id) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter account_id when calling getCryptocurrencyPairQuote' + 'Missing the required parameter user_secret when calling getOrderImpact' ); } - // Check if $instrument_symbol is a string - if ($instrument_symbol !== SENTINEL_VALUE && !is_string($instrument_symbol)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($instrument_symbol, true), gettype($instrument_symbol))); + if ($manual_trade_form !== SENTINEL_VALUE) { + if (!($manual_trade_form instanceof \SnapTrade\Model\ManualTradeForm)) { + if (!is_array($manual_trade_form)) + throw new \InvalidArgumentException('"manual_trade_form" must be associative array or an instance of \SnapTrade\Model\ManualTradeForm TradingApi.getOrderImpact.'); + else + $manual_trade_form = new \SnapTrade\Model\ManualTradeForm($manual_trade_form); + } } - // verify the required parameter 'instrument_symbol' is set - if ($instrument_symbol === SENTINEL_VALUE || (is_array($instrument_symbol) && count($instrument_symbol) === 0)) { + // verify the required parameter 'manual_trade_form' is set + if ($manual_trade_form === SENTINEL_VALUE || (is_array($manual_trade_form) && count($manual_trade_form) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter instrument_symbol when calling getCryptocurrencyPairQuote' + 'Missing the required parameter manual_trade_form when calling getOrderImpact' ); } - $resourcePath = '/accounts/{accountId}/trading/instruments/cryptocurrencyPairs/{instrumentSymbol}/quote'; + $resourcePath = '/trade/impact'; $formParams = []; $queryParams = []; $headerParams = []; @@ -1464,22 +1502,6 @@ public function getCryptocurrencyPairQuoteRequest($user_id, $user_secret, $accou } - // path params - if ($account_id !== SENTINEL_VALUE) { - $resourcePath = str_replace( - '{' . 'accountId' . '}', - ObjectSerializer::toPathValue($account_id), - $resourcePath - ); - } - // path params - if ($instrument_symbol !== SENTINEL_VALUE) { - $resourcePath = str_replace( - '{' . 'instrumentSymbol' . '}', - ObjectSerializer::toPathValue($instrument_symbol), - $resourcePath - ); - } $headers = $this->headerSelector->selectHeaders( @@ -1489,7 +1511,14 @@ public function getCryptocurrencyPairQuoteRequest($user_id, $user_secret, $accou ); // for model (json/xml) - if (count($formParams) > 0) { + if (isset($manual_trade_form)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($manual_trade_form)); + } else { + $httpBody = $manual_trade_form; + } + } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { @@ -1540,7 +1569,7 @@ public function getCryptocurrencyPairQuoteRequest($user_id, $user_secret, $accou $headers ); - $method = 'GET'; + $method = 'POST'; $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody); $operationHost = $this->config->getHost(); @@ -1557,75 +1586,62 @@ public function getCryptocurrencyPairQuoteRequest($user_id, $user_secret, $accou } /** - * Operation getOrderImpact + * Operation getUserAccountQuotes * - * Check order impact + * Get symbol quotes * - * Simulates an order and its impact on the account. This endpoint does not place the order with the brokerage. If successful, it returns a `Trade` object and the ID of the object can be used to place the order with the brokerage using the [place checked order endpoint](/reference/Trading/Trading_placeOrder). Please note that the `Trade` object returned expires after 5 minutes. Any order placed using an expired `Trade` will be rejected. + * Returns quotes from the brokerage for the specified symbols and account. The quotes returned can be delayed depending on the brokerage the account belongs to. It is highly recommended that you use your own market data provider for real-time quotes instead of relying on this endpoint. This endpoint does not work for options quotes. * * @param string $user_id user_id (required) * @param string $user_secret user_secret (required) - * @param \SnapTrade\Model\ManualTradeForm $manual_trade_form manual_trade_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderImpact'] to see the possible values for this operation + * @param string $symbols List of Universal Symbol IDs or tickers to get quotes for. When providing multiple values, use a comma as separator (required) + * @param string $account_id account_id (required) + * @param bool $use_ticker Should be set to `True` if `symbols` are comprised of tickers. Defaults to `False` if not provided. (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserAccountQuotes'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return \SnapTrade\Model\ManualTradeAndImpact|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse + * @return \SnapTrade\Model\SymbolsQuotesInner[]|\SnapTrade\Model\Model500UnexpectedExceptionResponse */ - public function getOrderImpact( - - $account_id, - $action, - $universal_symbol_id, - $order_type, - $time_in_force, + public function getUserAccountQuotes( $user_id, $user_secret, - $price = SENTINEL_VALUE, - $stop = SENTINEL_VALUE, - $units = SENTINEL_VALUE, - $notional_value = SENTINEL_VALUE, - string $contentType = self::contentTypes['getOrderImpact'][0] + $symbols, + $account_id, + $use_ticker = SENTINEL_VALUE, + + string $contentType = self::contentTypes['getUserAccountQuotes'][0] ) { - $_body = []; - $this->setRequestBodyProperty($_body, "account_id", $account_id); - $this->setRequestBodyProperty($_body, "action", $action); - $this->setRequestBodyProperty($_body, "universal_symbol_id", $universal_symbol_id); - $this->setRequestBodyProperty($_body, "order_type", $order_type); - $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); - $this->setRequestBodyProperty($_body, "price", $price); - $this->setRequestBodyProperty($_body, "stop", $stop); - $this->setRequestBodyProperty($_body, "units", $units); - $this->setRequestBodyProperty($_body, "notional_value", $notional_value); - $manual_trade_form = $_body; - list($response) = $this->getOrderImpactWithHttpInfo($user_id, $user_secret, $manual_trade_form, $contentType); + list($response) = $this->getUserAccountQuotesWithHttpInfo($user_id, $user_secret, $symbols, $account_id, $use_ticker, $contentType); return $response; } /** - * Operation getOrderImpactWithHttpInfo + * Operation getUserAccountQuotesWithHttpInfo * - * Check order impact + * Get symbol quotes * - * Simulates an order and its impact on the account. This endpoint does not place the order with the brokerage. If successful, it returns a `Trade` object and the ID of the object can be used to place the order with the brokerage using the [place checked order endpoint](/reference/Trading/Trading_placeOrder). Please note that the `Trade` object returned expires after 5 minutes. Any order placed using an expired `Trade` will be rejected. + * Returns quotes from the brokerage for the specified symbols and account. The quotes returned can be delayed depending on the brokerage the account belongs to. It is highly recommended that you use your own market data provider for real-time quotes instead of relying on this endpoint. This endpoint does not work for options quotes. * * @param string $user_id (required) * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeForm $manual_trade_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderImpact'] to see the possible values for this operation + * @param string $symbols List of Universal Symbol IDs or tickers to get quotes for. When providing multiple values, use a comma as separator (required) + * @param string $account_id (required) + * @param bool $use_ticker Should be set to `True` if `symbols` are comprised of tickers. Defaults to `False` if not provided. (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserAccountQuotes'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return array of \SnapTrade\Model\ManualTradeAndImpact|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) + * @return array of \SnapTrade\Model\SymbolsQuotesInner[]|\SnapTrade\Model\Model500UnexpectedExceptionResponse, HTTP status code, HTTP response headers (array of strings) */ - public function getOrderImpactWithHttpInfo($user_id, $user_secret, $manual_trade_form, string $contentType = self::contentTypes['getOrderImpact'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function getUserAccountQuotesWithHttpInfo($user_id, $user_secret, $symbols, $account_id, $use_ticker = null, string $contentType = self::contentTypes['getUserAccountQuotes'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { - ["request" => $request, "serializedBody" => $serializedBody] = $this->getOrderImpactRequest($user_id, $user_secret, $manual_trade_form, $contentType); + ["request" => $request, "serializedBody" => $serializedBody] = $this->getUserAccountQuotesRequest($user_id, $user_secret, $symbols, $account_id, $use_ticker, $contentType); // Customization hook - $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); + $this->beforeSendHook($request, $requestOptions, $this->config); try { $options = $this->createHttpClientOption(); @@ -1637,10 +1653,12 @@ public function getOrderImpactWithHttpInfo($user_id, $user_secret, $manual_trade !empty($this->getConfig()->getAccessToken()) && $requestOptions->shouldRetryOAuth() ) { - return $this->getOrderImpactWithHttpInfo( + return $this->getUserAccountQuotesWithHttpInfo( $user_id, $user_secret, - $manual_trade_form, + $symbols, + $account_id, + $use_ticker, $contentType, $requestOptions->setRetryOAuth(false) ); @@ -1678,53 +1696,38 @@ public function getOrderImpactWithHttpInfo($user_id, $user_secret, $manual_trade switch($statusCode) { case 200: - if ('\SnapTrade\Model\ManualTradeAndImpact' === '\SplFileObject') { + if ('\SnapTrade\Model\SymbolsQuotesInner[]' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); - if ('\SnapTrade\Model\ManualTradeAndImpact' !== 'string') { + if ('\SnapTrade\Model\SymbolsQuotesInner[]' !== 'string') { $content = json_decode($content); } } return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\ManualTradeAndImpact', []), + ObjectSerializer::deserialize($content, '\SnapTrade\Model\SymbolsQuotesInner[]', []), $response->getStatusCode(), $response->getHeaders() ]; - case 400: - if ('\SnapTrade\Model\Model400FailedRequestResponse' === '\SplFileObject') { + case 500: + if ('\SnapTrade\Model\Model500UnexpectedExceptionResponse' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); - if ('\SnapTrade\Model\Model400FailedRequestResponse' !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model400FailedRequestResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; - case 403: - if ('\SnapTrade\Model\Model403FailedRequestResponse' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\SnapTrade\Model\Model403FailedRequestResponse' !== 'string') { + if ('\SnapTrade\Model\Model500UnexpectedExceptionResponse' !== 'string') { $content = json_decode($content); } } return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model403FailedRequestResponse', []), + ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model500UnexpectedExceptionResponse', []), $response->getStatusCode(), $response->getHeaders() ]; } - $returnType = '\SnapTrade\Model\ManualTradeAndImpact'; + $returnType = '\SnapTrade\Model\SymbolsQuotesInner[]'; if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { @@ -1745,23 +1748,15 @@ public function getOrderImpactWithHttpInfo($user_id, $user_secret, $manual_trade case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), - '\SnapTrade\Model\ManualTradeAndImpact', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - case 400: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\SnapTrade\Model\Model400FailedRequestResponse', + '\SnapTrade\Model\SymbolsQuotesInner[]', $e->getResponseHeaders() ); $e->setResponseObject($data); break; - case 403: + case 500: $data = ObjectSerializer::deserialize( $e->getResponseBody(), - '\SnapTrade\Model\Model403FailedRequestResponse', + '\SnapTrade\Model\Model500UnexpectedExceptionResponse', $e->getResponseHeaders() ); $e->setResponseObject($data); @@ -1772,49 +1767,34 @@ public function getOrderImpactWithHttpInfo($user_id, $user_secret, $manual_trade } /** - * Operation getOrderImpactAsync + * Operation getUserAccountQuotesAsync * - * Check order impact + * Get symbol quotes * - * Simulates an order and its impact on the account. This endpoint does not place the order with the brokerage. If successful, it returns a `Trade` object and the ID of the object can be used to place the order with the brokerage using the [place checked order endpoint](/reference/Trading/Trading_placeOrder). Please note that the `Trade` object returned expires after 5 minutes. Any order placed using an expired `Trade` will be rejected. + * Returns quotes from the brokerage for the specified symbols and account. The quotes returned can be delayed depending on the brokerage the account belongs to. It is highly recommended that you use your own market data provider for real-time quotes instead of relying on this endpoint. This endpoint does not work for options quotes. * * @param string $user_id (required) * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeForm $manual_trade_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderImpact'] to see the possible values for this operation + * @param string $symbols List of Universal Symbol IDs or tickers to get quotes for. When providing multiple values, use a comma as separator (required) + * @param string $account_id (required) + * @param bool $use_ticker Should be set to `True` if `symbols` are comprised of tickers. Defaults to `False` if not provided. (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserAccountQuotes'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getOrderImpactAsync( - - $account_id, - $action, - $universal_symbol_id, - $order_type, - $time_in_force, + public function getUserAccountQuotesAsync( $user_id, $user_secret, - $price = SENTINEL_VALUE, - $stop = SENTINEL_VALUE, - $units = SENTINEL_VALUE, - $notional_value = SENTINEL_VALUE, - string $contentType = self::contentTypes['getOrderImpact'][0] + $symbols, + $account_id, + $use_ticker = SENTINEL_VALUE, + + string $contentType = self::contentTypes['getUserAccountQuotes'][0] ) { - $_body = []; - $this->setRequestBodyProperty($_body, "account_id", $account_id); - $this->setRequestBodyProperty($_body, "action", $action); - $this->setRequestBodyProperty($_body, "universal_symbol_id", $universal_symbol_id); - $this->setRequestBodyProperty($_body, "order_type", $order_type); - $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); - $this->setRequestBodyProperty($_body, "price", $price); - $this->setRequestBodyProperty($_body, "stop", $stop); - $this->setRequestBodyProperty($_body, "units", $units); - $this->setRequestBodyProperty($_body, "notional_value", $notional_value); - $manual_trade_form = $_body; - return $this->getOrderImpactAsyncWithHttpInfo($user_id, $user_secret, $manual_trade_form, $contentType) + return $this->getUserAccountQuotesAsyncWithHttpInfo($user_id, $user_secret, $symbols, $account_id, $use_ticker, $contentType) ->then( function ($response) { return $response[0]; @@ -1823,27 +1803,29 @@ function ($response) { } /** - * Operation getOrderImpactAsyncWithHttpInfo + * Operation getUserAccountQuotesAsyncWithHttpInfo * - * Check order impact + * Get symbol quotes * - * Simulates an order and its impact on the account. This endpoint does not place the order with the brokerage. If successful, it returns a `Trade` object and the ID of the object can be used to place the order with the brokerage using the [place checked order endpoint](/reference/Trading/Trading_placeOrder). Please note that the `Trade` object returned expires after 5 minutes. Any order placed using an expired `Trade` will be rejected. + * Returns quotes from the brokerage for the specified symbols and account. The quotes returned can be delayed depending on the brokerage the account belongs to. It is highly recommended that you use your own market data provider for real-time quotes instead of relying on this endpoint. This endpoint does not work for options quotes. * * @param string $user_id (required) * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeForm $manual_trade_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderImpact'] to see the possible values for this operation + * @param string $symbols List of Universal Symbol IDs or tickers to get quotes for. When providing multiple values, use a comma as separator (required) + * @param string $account_id (required) + * @param bool $use_ticker Should be set to `True` if `symbols` are comprised of tickers. Defaults to `False` if not provided. (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserAccountQuotes'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getOrderImpactAsyncWithHttpInfo($user_id, $user_secret, $manual_trade_form, string $contentType = self::contentTypes['getOrderImpact'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function getUserAccountQuotesAsyncWithHttpInfo($user_id, $user_secret, $symbols, $account_id, $use_ticker = null, string $contentType = self::contentTypes['getUserAccountQuotes'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { - $returnType = '\SnapTrade\Model\ManualTradeAndImpact'; - ["request" => $request, "serializedBody" => $serializedBody] = $this->getOrderImpactRequest($user_id, $user_secret, $manual_trade_form, $contentType); + $returnType = '\SnapTrade\Model\SymbolsQuotesInner[]'; + ["request" => $request, "serializedBody" => $serializedBody] = $this->getUserAccountQuotesRequest($user_id, $user_secret, $symbols, $account_id, $use_ticker, $contentType); // Customization hook - $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); + $this->beforeSendHook($request, $requestOptions, $this->config); return $this->client ->sendAsync($request, $this->createHttpClientOption()) @@ -1882,17 +1864,19 @@ function ($exception) { } /** - * Create request for operation 'getOrderImpact' + * Create request for operation 'getUserAccountQuotes' * * @param string $user_id (required) * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeForm $manual_trade_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getOrderImpact'] to see the possible values for this operation + * @param string $symbols List of Universal Symbol IDs or tickers to get quotes for. When providing multiple values, use a comma as separator (required) + * @param string $account_id (required) + * @param bool $use_ticker Should be set to `True` if `symbols` are comprised of tickers. Defaults to `False` if not provided. (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserAccountQuotes'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ - public function getOrderImpactRequest($user_id, $user_secret, $manual_trade_form, string $contentType = self::contentTypes['getOrderImpact'][0]) + public function getUserAccountQuotesRequest($user_id, $user_secret, $symbols, $account_id, $use_ticker = SENTINEL_VALUE, string $contentType = self::contentTypes['getUserAccountQuotes'][0]) { // Check if $user_id is a string @@ -1902,7 +1886,7 @@ public function getOrderImpactRequest($user_id, $user_secret, $manual_trade_form // verify the required parameter 'user_id' is set if ($user_id === SENTINEL_VALUE || (is_array($user_id) && count($user_id) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter user_id when calling getOrderImpact' + 'Missing the required parameter user_id when calling getUserAccountQuotes' ); } // Check if $user_secret is a string @@ -1912,26 +1896,32 @@ public function getOrderImpactRequest($user_id, $user_secret, $manual_trade_form // verify the required parameter 'user_secret' is set if ($user_secret === SENTINEL_VALUE || (is_array($user_secret) && count($user_secret) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter user_secret when calling getOrderImpact' + 'Missing the required parameter user_secret when calling getUserAccountQuotes' ); } - if ($manual_trade_form !== SENTINEL_VALUE) { - if (!($manual_trade_form instanceof \SnapTrade\Model\ManualTradeForm)) { - if (!is_array($manual_trade_form)) - throw new \InvalidArgumentException('"manual_trade_form" must be associative array or an instance of \SnapTrade\Model\ManualTradeForm TradingApi.getOrderImpact.'); - else - $manual_trade_form = new \SnapTrade\Model\ManualTradeForm($manual_trade_form); - } + // Check if $symbols is a string + if ($symbols !== SENTINEL_VALUE && !is_string($symbols)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($symbols, true), gettype($symbols))); } - // verify the required parameter 'manual_trade_form' is set - if ($manual_trade_form === SENTINEL_VALUE || (is_array($manual_trade_form) && count($manual_trade_form) === 0)) { + // verify the required parameter 'symbols' is set + if ($symbols === SENTINEL_VALUE || (is_array($symbols) && count($symbols) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter manual_trade_form when calling getOrderImpact' + 'Missing the required parameter symbols when calling getUserAccountQuotes' + ); + } + // Check if $account_id is a string + if ($account_id !== SENTINEL_VALUE && !is_string($account_id)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($account_id, true), gettype($account_id))); + } + // verify the required parameter 'account_id' is set + if ($account_id === SENTINEL_VALUE || (is_array($account_id) && count($account_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter account_id when calling getUserAccountQuotes' ); } - $resourcePath = '/trade/impact'; + $resourcePath = '/accounts/{accountId}/quotes'; $formParams = []; $queryParams = []; $headerParams = []; @@ -1960,1493 +1950,38 @@ public function getOrderImpactRequest($user_id, $user_secret, $manual_trade_form true // required ) ?? []); } - - - - - $headers = $this->headerSelector->selectHeaders( - ['application/json', ], - $contentType, - $multipart - ); - - // for model (json/xml) - if (isset($manual_trade_form)) { - if (stripos($headers['Content-Type'], 'application/json') !== false) { - # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($manual_trade_form)); - } else { - $httpBody = $manual_trade_form; - } - } elseif (count($formParams) > 0) { - if ($multipart) { - $multipartContents = []; - foreach ($formParams as $formParamName => $formParamValue) { - $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; - foreach ($formParamValueItems as $formParamValueItem) { - $multipartContents[] = [ - 'name' => $formParamName, - 'contents' => $formParamValueItem - ]; - } - } - // for HTTP post (form) - $httpBody = new MultipartStream($multipartContents); - - } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { - # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\json_encode($formParams); - } else { - // for HTTP post (form) - $httpBody = ObjectSerializer::buildQuery($formParams); - } - } - - // this endpoint requires API key authentication - $apiKey = $this->config->getApiKeyWithPrefix('clientId'); - if ($apiKey !== null) { - $queryParams['clientId'] = $apiKey; - } - // this endpoint requires API key authentication - $apiKey = $this->config->getApiKeyWithPrefix('Signature'); - if ($apiKey !== null) { - $headers['Signature'] = $apiKey; - } - // this endpoint requires API key authentication - $apiKey = $this->config->getApiKeyWithPrefix('timestamp'); - if ($apiKey !== null) { - $queryParams['timestamp'] = $apiKey; - } - - $defaultHeaders = []; - if ($this->config->getUserAgent()) { - $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + if ($symbols !== SENTINEL_VALUE) { + // query params + $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( + $symbols, + 'symbols', // param base name + 'string', // openApiType + 'form', // style + true, // explode + true // required + ) ?? []); } - - $headers = array_merge( - $defaultHeaders, - $headerParams, - $headers - ); - - $method = 'POST'; - $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody); - - $operationHost = $this->config->getHost(); - $query = ObjectSerializer::buildQuery($queryParams); - return [ - "request" => new Request( - $method, - $operationHost . $resourcePath . ($query ? "?{$query}" : ''), - $headers, - $httpBody - ), - "serializedBody" => $httpBody - ]; - } - - /** - * Operation getUserAccountQuotes - * - * Get symbol quotes - * - * Returns quotes from the brokerage for the specified symbols and account. The quotes returned can be delayed depending on the brokerage the account belongs to. It is highly recommended that you use your own market data provider for real-time quotes instead of relying on this endpoint. This endpoint does not work for options quotes. - * - * @param string $user_id user_id (required) - * @param string $user_secret user_secret (required) - * @param string $symbols List of Universal Symbol IDs or tickers to get quotes for. When providing multiple values, use a comma as separator (required) - * @param string $account_id account_id (required) - * @param bool $use_ticker Should be set to `True` if `symbols` are comprised of tickers. Defaults to `False` if not provided. (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserAccountQuotes'] to see the possible values for this operation - * - * @throws \SnapTrade\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \SnapTrade\Model\SymbolsQuotesInner[]|\SnapTrade\Model\Model500UnexpectedExceptionResponse - */ - public function getUserAccountQuotes( - $user_id, - $user_secret, - $symbols, - $account_id, - $use_ticker = SENTINEL_VALUE, - - string $contentType = self::contentTypes['getUserAccountQuotes'][0] - ) - { - - list($response) = $this->getUserAccountQuotesWithHttpInfo($user_id, $user_secret, $symbols, $account_id, $use_ticker, $contentType); - return $response; - } - - /** - * Operation getUserAccountQuotesWithHttpInfo - * - * Get symbol quotes - * - * Returns quotes from the brokerage for the specified symbols and account. The quotes returned can be delayed depending on the brokerage the account belongs to. It is highly recommended that you use your own market data provider for real-time quotes instead of relying on this endpoint. This endpoint does not work for options quotes. - * - * @param string $user_id (required) - * @param string $user_secret (required) - * @param string $symbols List of Universal Symbol IDs or tickers to get quotes for. When providing multiple values, use a comma as separator (required) - * @param string $account_id (required) - * @param bool $use_ticker Should be set to `True` if `symbols` are comprised of tickers. Defaults to `False` if not provided. (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserAccountQuotes'] to see the possible values for this operation - * - * @throws \SnapTrade\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return array of \SnapTrade\Model\SymbolsQuotesInner[]|\SnapTrade\Model\Model500UnexpectedExceptionResponse, HTTP status code, HTTP response headers (array of strings) - */ - public function getUserAccountQuotesWithHttpInfo($user_id, $user_secret, $symbols, $account_id, $use_ticker = null, string $contentType = self::contentTypes['getUserAccountQuotes'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) - { - ["request" => $request, "serializedBody" => $serializedBody] = $this->getUserAccountQuotesRequest($user_id, $user_secret, $symbols, $account_id, $use_ticker, $contentType); - - // Customization hook - $this->beforeSendHook($request, $requestOptions, $this->config); - - try { - $options = $this->createHttpClientOption(); - try { - $response = $this->client->send($request, $options); - } catch (RequestException $e) { - if ( - ($e->getCode() == 401 || $e->getCode() == 403) && - !empty($this->getConfig()->getAccessToken()) && - $requestOptions->shouldRetryOAuth() - ) { - return $this->getUserAccountQuotesWithHttpInfo( - $user_id, - $user_secret, - $symbols, - $account_id, - $use_ticker, - $contentType, - $requestOptions->setRetryOAuth(false) - ); - } - - throw new ApiException( - "[{$e->getCode()}] {$e->getMessage()}", - (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null - ); - } catch (ConnectException $e) { - throw new ApiException( - "[{$e->getCode()}] {$e->getMessage()}", - (int) $e->getCode(), - null, - null - ); - } - - $statusCode = $response->getStatusCode(); - - if ($statusCode < 200 || $statusCode > 299) { - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - (string) $request->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } - - switch($statusCode) { - case 200: - if ('\SnapTrade\Model\SymbolsQuotesInner[]' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\SnapTrade\Model\SymbolsQuotesInner[]' !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\SymbolsQuotesInner[]', []), - $response->getStatusCode(), - $response->getHeaders() - ]; - case 500: - if ('\SnapTrade\Model\Model500UnexpectedExceptionResponse' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\SnapTrade\Model\Model500UnexpectedExceptionResponse' !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model500UnexpectedExceptionResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; - } - - $returnType = '\SnapTrade\Model\SymbolsQuotesInner[]'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\SnapTrade\Model\SymbolsQuotesInner[]', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - case 500: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\SnapTrade\Model\Model500UnexpectedExceptionResponse', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - } - throw $e; - } - } - - /** - * Operation getUserAccountQuotesAsync - * - * Get symbol quotes - * - * Returns quotes from the brokerage for the specified symbols and account. The quotes returned can be delayed depending on the brokerage the account belongs to. It is highly recommended that you use your own market data provider for real-time quotes instead of relying on this endpoint. This endpoint does not work for options quotes. - * - * @param string $user_id (required) - * @param string $user_secret (required) - * @param string $symbols List of Universal Symbol IDs or tickers to get quotes for. When providing multiple values, use a comma as separator (required) - * @param string $account_id (required) - * @param bool $use_ticker Should be set to `True` if `symbols` are comprised of tickers. Defaults to `False` if not provided. (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserAccountQuotes'] to see the possible values for this operation - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - public function getUserAccountQuotesAsync( - $user_id, - $user_secret, - $symbols, - $account_id, - $use_ticker = SENTINEL_VALUE, - - string $contentType = self::contentTypes['getUserAccountQuotes'][0] - ) - { - - return $this->getUserAccountQuotesAsyncWithHttpInfo($user_id, $user_secret, $symbols, $account_id, $use_ticker, $contentType) - ->then( - function ($response) { - return $response[0]; - } - ); - } - - /** - * Operation getUserAccountQuotesAsyncWithHttpInfo - * - * Get symbol quotes - * - * Returns quotes from the brokerage for the specified symbols and account. The quotes returned can be delayed depending on the brokerage the account belongs to. It is highly recommended that you use your own market data provider for real-time quotes instead of relying on this endpoint. This endpoint does not work for options quotes. - * - * @param string $user_id (required) - * @param string $user_secret (required) - * @param string $symbols List of Universal Symbol IDs or tickers to get quotes for. When providing multiple values, use a comma as separator (required) - * @param string $account_id (required) - * @param bool $use_ticker Should be set to `True` if `symbols` are comprised of tickers. Defaults to `False` if not provided. (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserAccountQuotes'] to see the possible values for this operation - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - public function getUserAccountQuotesAsyncWithHttpInfo($user_id, $user_secret, $symbols, $account_id, $use_ticker = null, string $contentType = self::contentTypes['getUserAccountQuotes'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) - { - $returnType = '\SnapTrade\Model\SymbolsQuotesInner[]'; - ["request" => $request, "serializedBody" => $serializedBody] = $this->getUserAccountQuotesRequest($user_id, $user_secret, $symbols, $account_id, $use_ticker, $contentType); - - // Customization hook - $this->beforeSendHook($request, $requestOptions, $this->config); - - return $this->client - ->sendAsync($request, $this->createHttpClientOption()) - ->then( - function ($response) use ($returnType) { - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - }, - function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } - ); - } - - /** - * Create request for operation 'getUserAccountQuotes' - * - * @param string $user_id (required) - * @param string $user_secret (required) - * @param string $symbols List of Universal Symbol IDs or tickers to get quotes for. When providing multiple values, use a comma as separator (required) - * @param string $account_id (required) - * @param bool $use_ticker Should be set to `True` if `symbols` are comprised of tickers. Defaults to `False` if not provided. (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getUserAccountQuotes'] to see the possible values for this operation - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Psr7\Request - */ - public function getUserAccountQuotesRequest($user_id, $user_secret, $symbols, $account_id, $use_ticker = SENTINEL_VALUE, string $contentType = self::contentTypes['getUserAccountQuotes'][0]) - { - - // Check if $user_id is a string - if ($user_id !== SENTINEL_VALUE && !is_string($user_id)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_id, true), gettype($user_id))); - } - // verify the required parameter 'user_id' is set - if ($user_id === SENTINEL_VALUE || (is_array($user_id) && count($user_id) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter user_id when calling getUserAccountQuotes' - ); - } - // Check if $user_secret is a string - if ($user_secret !== SENTINEL_VALUE && !is_string($user_secret)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_secret, true), gettype($user_secret))); - } - // verify the required parameter 'user_secret' is set - if ($user_secret === SENTINEL_VALUE || (is_array($user_secret) && count($user_secret) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter user_secret when calling getUserAccountQuotes' - ); - } - // Check if $symbols is a string - if ($symbols !== SENTINEL_VALUE && !is_string($symbols)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($symbols, true), gettype($symbols))); - } - // verify the required parameter 'symbols' is set - if ($symbols === SENTINEL_VALUE || (is_array($symbols) && count($symbols) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter symbols when calling getUserAccountQuotes' - ); - } - // Check if $account_id is a string - if ($account_id !== SENTINEL_VALUE && !is_string($account_id)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($account_id, true), gettype($account_id))); - } - // verify the required parameter 'account_id' is set - if ($account_id === SENTINEL_VALUE || (is_array($account_id) && count($account_id) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter account_id when calling getUserAccountQuotes' - ); - } - - - $resourcePath = '/accounts/{accountId}/quotes'; - $formParams = []; - $queryParams = []; - $headerParams = []; - $httpBody = ''; - $multipart = false; - - if ($user_id !== SENTINEL_VALUE) { - // query params - $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( - $user_id, - 'userId', // param base name - 'string', // openApiType - 'form', // style - true, // explode - true // required - ) ?? []); - } - if ($user_secret !== SENTINEL_VALUE) { - // query params - $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( - $user_secret, - 'userSecret', // param base name - 'string', // openApiType - 'form', // style - true, // explode - true // required - ) ?? []); - } - if ($symbols !== SENTINEL_VALUE) { - // query params - $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( - $symbols, - 'symbols', // param base name - 'string', // openApiType - 'form', // style - true, // explode - true // required - ) ?? []); - } - if ($use_ticker !== SENTINEL_VALUE) { - // query params - $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( - $use_ticker, - 'use_ticker', // param base name - 'boolean', // openApiType - 'form', // style - true, // explode - false // required - ) ?? []); - } - - - // path params - if ($account_id !== SENTINEL_VALUE) { - $resourcePath = str_replace( - '{' . 'accountId' . '}', - ObjectSerializer::toPathValue($account_id), - $resourcePath - ); - } - - - $headers = $this->headerSelector->selectHeaders( - ['application/json', ], - $contentType, - $multipart - ); - - // for model (json/xml) - if (count($formParams) > 0) { - if ($multipart) { - $multipartContents = []; - foreach ($formParams as $formParamName => $formParamValue) { - $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; - foreach ($formParamValueItems as $formParamValueItem) { - $multipartContents[] = [ - 'name' => $formParamName, - 'contents' => $formParamValueItem - ]; - } - } - // for HTTP post (form) - $httpBody = new MultipartStream($multipartContents); - - } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { - # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\json_encode($formParams); - } else { - // for HTTP post (form) - $httpBody = ObjectSerializer::buildQuery($formParams); - } - } - - // this endpoint requires API key authentication - $apiKey = $this->config->getApiKeyWithPrefix('clientId'); - if ($apiKey !== null) { - $queryParams['clientId'] = $apiKey; - } - // this endpoint requires API key authentication - $apiKey = $this->config->getApiKeyWithPrefix('Signature'); - if ($apiKey !== null) { - $headers['Signature'] = $apiKey; - } - // this endpoint requires API key authentication - $apiKey = $this->config->getApiKeyWithPrefix('timestamp'); - if ($apiKey !== null) { - $queryParams['timestamp'] = $apiKey; - } - - $defaultHeaders = []; - if ($this->config->getUserAgent()) { - $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); - } - - $headers = array_merge( - $defaultHeaders, - $headerParams, - $headers - ); - - $method = 'GET'; - $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody); - - $operationHost = $this->config->getHost(); - $query = ObjectSerializer::buildQuery($queryParams); - return [ - "request" => new Request( - $method, - $operationHost . $resourcePath . ($query ? "?{$query}" : ''), - $headers, - $httpBody - ), - "serializedBody" => $httpBody - ]; - } - - /** - * Operation placeBracketOrder - * - * Place a Bracket Order - * - * Places a bracket order (entry order + OCO of stop loss and take profit). Disabled by default please contact support for use. Only supported on certain brokerages - * - * @param string $account_id The ID of the account to execute the trade on. (required) - * @param string $user_id user_id (required) - * @param string $user_secret user_secret (required) - * @param \SnapTrade\Model\ManualTradeFormBracket $manual_trade_form_bracket manual_trade_form_bracket (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeBracketOrder'] to see the possible values for this operation - * - * @throws \SnapTrade\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse - */ - public function placeBracketOrder( - - $action, - $instrument, - $order_type, - $time_in_force, - $stop_loss, - $take_profit, - $account_id, - $user_id, - $user_secret, - $symbol = SENTINEL_VALUE, - $price = SENTINEL_VALUE, - $stop = SENTINEL_VALUE, - $units = SENTINEL_VALUE, - string $contentType = self::contentTypes['placeBracketOrder'][0] - ) - { - $_body = []; - $this->setRequestBodyProperty($_body, "action", $action); - $this->setRequestBodyProperty($_body, "symbol", $symbol); - $this->setRequestBodyProperty($_body, "instrument", $instrument); - $this->setRequestBodyProperty($_body, "order_type", $order_type); - $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); - $this->setRequestBodyProperty($_body, "price", $price); - $this->setRequestBodyProperty($_body, "stop", $stop); - $this->setRequestBodyProperty($_body, "units", $units); - $this->setRequestBodyProperty($_body, "stop_loss", $stop_loss); - $this->setRequestBodyProperty($_body, "take_profit", $take_profit); - $manual_trade_form_bracket = $_body; - - list($response) = $this->placeBracketOrderWithHttpInfo($account_id, $user_id, $user_secret, $manual_trade_form_bracket, $contentType); - return $response; - } - - /** - * Operation placeBracketOrderWithHttpInfo - * - * Place a Bracket Order - * - * Places a bracket order (entry order + OCO of stop loss and take profit). Disabled by default please contact support for use. Only supported on certain brokerages - * - * @param string $account_id The ID of the account to execute the trade on. (required) - * @param string $user_id (required) - * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeFormBracket $manual_trade_form_bracket (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeBracketOrder'] to see the possible values for this operation - * - * @throws \SnapTrade\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return array of \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) - */ - public function placeBracketOrderWithHttpInfo($account_id, $user_id, $user_secret, $manual_trade_form_bracket, string $contentType = self::contentTypes['placeBracketOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) - { - ["request" => $request, "serializedBody" => $serializedBody] = $this->placeBracketOrderRequest($account_id, $user_id, $user_secret, $manual_trade_form_bracket, $contentType); - - // Customization hook - $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); - - try { - $options = $this->createHttpClientOption(); - try { - $response = $this->client->send($request, $options); - } catch (RequestException $e) { - if ( - ($e->getCode() == 401 || $e->getCode() == 403) && - !empty($this->getConfig()->getAccessToken()) && - $requestOptions->shouldRetryOAuth() - ) { - return $this->placeBracketOrderWithHttpInfo( - $account_id, - $user_id, - $user_secret, - $manual_trade_form_bracket, - $contentType, - $requestOptions->setRetryOAuth(false) - ); - } - - throw new ApiException( - "[{$e->getCode()}] {$e->getMessage()}", - (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null - ); - } catch (ConnectException $e) { - throw new ApiException( - "[{$e->getCode()}] {$e->getMessage()}", - (int) $e->getCode(), - null, - null - ); - } - - $statusCode = $response->getStatusCode(); - - if ($statusCode < 200 || $statusCode > 299) { - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - (string) $request->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } - - switch($statusCode) { - case 200: - if ('\SnapTrade\Model\AccountOrderRecord' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\SnapTrade\Model\AccountOrderRecord' !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\AccountOrderRecord', []), - $response->getStatusCode(), - $response->getHeaders() - ]; - case 400: - if ('\SnapTrade\Model\Model400FailedRequestResponse' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\SnapTrade\Model\Model400FailedRequestResponse' !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model400FailedRequestResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; - case 403: - if ('\SnapTrade\Model\Model403FailedRequestResponse' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\SnapTrade\Model\Model403FailedRequestResponse' !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model403FailedRequestResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; - } - - $returnType = '\SnapTrade\Model\AccountOrderRecord'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\SnapTrade\Model\AccountOrderRecord', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - case 400: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\SnapTrade\Model\Model400FailedRequestResponse', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - case 403: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\SnapTrade\Model\Model403FailedRequestResponse', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - } - throw $e; - } - } - - /** - * Operation placeBracketOrderAsync - * - * Place a Bracket Order - * - * Places a bracket order (entry order + OCO of stop loss and take profit). Disabled by default please contact support for use. Only supported on certain brokerages - * - * @param string $account_id The ID of the account to execute the trade on. (required) - * @param string $user_id (required) - * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeFormBracket $manual_trade_form_bracket (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeBracketOrder'] to see the possible values for this operation - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - public function placeBracketOrderAsync( - - $action, - $instrument, - $order_type, - $time_in_force, - $stop_loss, - $take_profit, - $account_id, - $user_id, - $user_secret, - $symbol = SENTINEL_VALUE, - $price = SENTINEL_VALUE, - $stop = SENTINEL_VALUE, - $units = SENTINEL_VALUE, - string $contentType = self::contentTypes['placeBracketOrder'][0] - ) - { - $_body = []; - $this->setRequestBodyProperty($_body, "action", $action); - $this->setRequestBodyProperty($_body, "symbol", $symbol); - $this->setRequestBodyProperty($_body, "instrument", $instrument); - $this->setRequestBodyProperty($_body, "order_type", $order_type); - $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); - $this->setRequestBodyProperty($_body, "price", $price); - $this->setRequestBodyProperty($_body, "stop", $stop); - $this->setRequestBodyProperty($_body, "units", $units); - $this->setRequestBodyProperty($_body, "stop_loss", $stop_loss); - $this->setRequestBodyProperty($_body, "take_profit", $take_profit); - $manual_trade_form_bracket = $_body; - - return $this->placeBracketOrderAsyncWithHttpInfo($account_id, $user_id, $user_secret, $manual_trade_form_bracket, $contentType) - ->then( - function ($response) { - return $response[0]; - } - ); - } - - /** - * Operation placeBracketOrderAsyncWithHttpInfo - * - * Place a Bracket Order - * - * Places a bracket order (entry order + OCO of stop loss and take profit). Disabled by default please contact support for use. Only supported on certain brokerages - * - * @param string $account_id The ID of the account to execute the trade on. (required) - * @param string $user_id (required) - * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeFormBracket $manual_trade_form_bracket (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeBracketOrder'] to see the possible values for this operation - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - public function placeBracketOrderAsyncWithHttpInfo($account_id, $user_id, $user_secret, $manual_trade_form_bracket, string $contentType = self::contentTypes['placeBracketOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) - { - $returnType = '\SnapTrade\Model\AccountOrderRecord'; - ["request" => $request, "serializedBody" => $serializedBody] = $this->placeBracketOrderRequest($account_id, $user_id, $user_secret, $manual_trade_form_bracket, $contentType); - - // Customization hook - $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); - - return $this->client - ->sendAsync($request, $this->createHttpClientOption()) - ->then( - function ($response) use ($returnType) { - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - }, - function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } - ); - } - - /** - * Create request for operation 'placeBracketOrder' - * - * @param string $account_id The ID of the account to execute the trade on. (required) - * @param string $user_id (required) - * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeFormBracket $manual_trade_form_bracket (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeBracketOrder'] to see the possible values for this operation - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Psr7\Request - */ - public function placeBracketOrderRequest($account_id, $user_id, $user_secret, $manual_trade_form_bracket, string $contentType = self::contentTypes['placeBracketOrder'][0]) - { - - // Check if $account_id is a string - if ($account_id !== SENTINEL_VALUE && !is_string($account_id)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($account_id, true), gettype($account_id))); - } - // verify the required parameter 'account_id' is set - if ($account_id === SENTINEL_VALUE || (is_array($account_id) && count($account_id) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter account_id when calling placeBracketOrder' - ); - } - // Check if $user_id is a string - if ($user_id !== SENTINEL_VALUE && !is_string($user_id)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_id, true), gettype($user_id))); - } - // verify the required parameter 'user_id' is set - if ($user_id === SENTINEL_VALUE || (is_array($user_id) && count($user_id) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter user_id when calling placeBracketOrder' - ); - } - // Check if $user_secret is a string - if ($user_secret !== SENTINEL_VALUE && !is_string($user_secret)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_secret, true), gettype($user_secret))); - } - // verify the required parameter 'user_secret' is set - if ($user_secret === SENTINEL_VALUE || (is_array($user_secret) && count($user_secret) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter user_secret when calling placeBracketOrder' - ); - } - if ($manual_trade_form_bracket !== SENTINEL_VALUE) { - if (!($manual_trade_form_bracket instanceof \SnapTrade\Model\ManualTradeFormBracket)) { - if (!is_array($manual_trade_form_bracket)) - throw new \InvalidArgumentException('"manual_trade_form_bracket" must be associative array or an instance of \SnapTrade\Model\ManualTradeFormBracket TradingApi.placeBracketOrder.'); - else - $manual_trade_form_bracket = new \SnapTrade\Model\ManualTradeFormBracket($manual_trade_form_bracket); - } - } - // verify the required parameter 'manual_trade_form_bracket' is set - if ($manual_trade_form_bracket === SENTINEL_VALUE || (is_array($manual_trade_form_bracket) && count($manual_trade_form_bracket) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter manual_trade_form_bracket when calling placeBracketOrder' - ); - } - - - $resourcePath = '/accounts/{accountId}/trading/bracket'; - $formParams = []; - $queryParams = []; - $headerParams = []; - $httpBody = ''; - $multipart = false; - - if ($user_id !== SENTINEL_VALUE) { - // query params - $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( - $user_id, - 'userId', // param base name - 'string', // openApiType - 'form', // style - true, // explode - true // required - ) ?? []); - } - if ($user_secret !== SENTINEL_VALUE) { - // query params - $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( - $user_secret, - 'userSecret', // param base name - 'string', // openApiType - 'form', // style - true, // explode - true // required - ) ?? []); - } - - - // path params - if ($account_id !== SENTINEL_VALUE) { - $resourcePath = str_replace( - '{' . 'accountId' . '}', - ObjectSerializer::toPathValue($account_id), - $resourcePath - ); - } - - - $headers = $this->headerSelector->selectHeaders( - ['application/json', ], - $contentType, - $multipart - ); - - // for model (json/xml) - if (isset($manual_trade_form_bracket)) { - if (stripos($headers['Content-Type'], 'application/json') !== false) { - # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($manual_trade_form_bracket)); - } else { - $httpBody = $manual_trade_form_bracket; - } - } elseif (count($formParams) > 0) { - if ($multipart) { - $multipartContents = []; - foreach ($formParams as $formParamName => $formParamValue) { - $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; - foreach ($formParamValueItems as $formParamValueItem) { - $multipartContents[] = [ - 'name' => $formParamName, - 'contents' => $formParamValueItem - ]; - } - } - // for HTTP post (form) - $httpBody = new MultipartStream($multipartContents); - - } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { - # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\json_encode($formParams); - } else { - // for HTTP post (form) - $httpBody = ObjectSerializer::buildQuery($formParams); - } - } - - // this endpoint requires API key authentication - $apiKey = $this->config->getApiKeyWithPrefix('clientId'); - if ($apiKey !== null) { - $queryParams['clientId'] = $apiKey; - } - // this endpoint requires API key authentication - $apiKey = $this->config->getApiKeyWithPrefix('Signature'); - if ($apiKey !== null) { - $headers['Signature'] = $apiKey; - } - // this endpoint requires API key authentication - $apiKey = $this->config->getApiKeyWithPrefix('timestamp'); - if ($apiKey !== null) { - $queryParams['timestamp'] = $apiKey; - } - - $defaultHeaders = []; - if ($this->config->getUserAgent()) { - $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); - } - - $headers = array_merge( - $defaultHeaders, - $headerParams, - $headers - ); - - $method = 'POST'; - $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody); - - $operationHost = $this->config->getHost(); - $query = ObjectSerializer::buildQuery($queryParams); - return [ - "request" => new Request( - $method, - $operationHost . $resourcePath . ($query ? "?{$query}" : ''), - $headers, - $httpBody - ), - "serializedBody" => $httpBody - ]; - } - - /** - * Operation placeForceOrder - * - * Place order - * - * Places a brokerage order in the specified account. The order could be rejected by the brokerage if it is invalid or if the account does not have sufficient funds. This endpoint does not compute the impact to the account balance from the order and any potential commissions before submitting the order to the brokerage. If that is desired, you can use the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. - * - * @param string $user_id user_id (required) - * @param string $user_secret user_secret (required) - * @param \SnapTrade\Model\ManualTradeFormWithOptions $manual_trade_form_with_options manual_trade_form_with_options (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeForceOrder'] to see the possible values for this operation - * - * @throws \SnapTrade\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse - */ - public function placeForceOrder( - - $account_id, - $action, - $order_type, - $time_in_force, - $user_id, - $user_secret, - $universal_symbol_id = SENTINEL_VALUE, - $symbol = SENTINEL_VALUE, - $price = SENTINEL_VALUE, - $stop = SENTINEL_VALUE, - $units = SENTINEL_VALUE, - $notional_value = SENTINEL_VALUE, - string $contentType = self::contentTypes['placeForceOrder'][0] - ) - { - $_body = []; - $this->setRequestBodyProperty($_body, "account_id", $account_id); - $this->setRequestBodyProperty($_body, "action", $action); - $this->setRequestBodyProperty($_body, "universal_symbol_id", $universal_symbol_id); - $this->setRequestBodyProperty($_body, "symbol", $symbol); - $this->setRequestBodyProperty($_body, "order_type", $order_type); - $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); - $this->setRequestBodyProperty($_body, "price", $price); - $this->setRequestBodyProperty($_body, "stop", $stop); - $this->setRequestBodyProperty($_body, "units", $units); - $this->setRequestBodyProperty($_body, "notional_value", $notional_value); - $manual_trade_form_with_options = $_body; - - list($response) = $this->placeForceOrderWithHttpInfo($user_id, $user_secret, $manual_trade_form_with_options, $contentType); - return $response; - } - - /** - * Operation placeForceOrderWithHttpInfo - * - * Place order - * - * Places a brokerage order in the specified account. The order could be rejected by the brokerage if it is invalid or if the account does not have sufficient funds. This endpoint does not compute the impact to the account balance from the order and any potential commissions before submitting the order to the brokerage. If that is desired, you can use the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. - * - * @param string $user_id (required) - * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeFormWithOptions $manual_trade_form_with_options (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeForceOrder'] to see the possible values for this operation - * - * @throws \SnapTrade\ApiException on non-2xx response - * @throws \InvalidArgumentException - * @return array of \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) - */ - public function placeForceOrderWithHttpInfo($user_id, $user_secret, $manual_trade_form_with_options, string $contentType = self::contentTypes['placeForceOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) - { - ["request" => $request, "serializedBody" => $serializedBody] = $this->placeForceOrderRequest($user_id, $user_secret, $manual_trade_form_with_options, $contentType); - - // Customization hook - $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); - - try { - $options = $this->createHttpClientOption(); - try { - $response = $this->client->send($request, $options); - } catch (RequestException $e) { - if ( - ($e->getCode() == 401 || $e->getCode() == 403) && - !empty($this->getConfig()->getAccessToken()) && - $requestOptions->shouldRetryOAuth() - ) { - return $this->placeForceOrderWithHttpInfo( - $user_id, - $user_secret, - $manual_trade_form_with_options, - $contentType, - $requestOptions->setRetryOAuth(false) - ); - } - - throw new ApiException( - "[{$e->getCode()}] {$e->getMessage()}", - (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null - ); - } catch (ConnectException $e) { - throw new ApiException( - "[{$e->getCode()}] {$e->getMessage()}", - (int) $e->getCode(), - null, - null - ); - } - - $statusCode = $response->getStatusCode(); - - if ($statusCode < 200 || $statusCode > 299) { - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - (string) $request->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } - - switch($statusCode) { - case 200: - if ('\SnapTrade\Model\AccountOrderRecord' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\SnapTrade\Model\AccountOrderRecord' !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\AccountOrderRecord', []), - $response->getStatusCode(), - $response->getHeaders() - ]; - case 400: - if ('\SnapTrade\Model\Model400FailedRequestResponse' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\SnapTrade\Model\Model400FailedRequestResponse' !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model400FailedRequestResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; - case 403: - if ('\SnapTrade\Model\Model403FailedRequestResponse' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\SnapTrade\Model\Model403FailedRequestResponse' !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model403FailedRequestResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; - } - - $returnType = '\SnapTrade\Model\AccountOrderRecord'; - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\SnapTrade\Model\AccountOrderRecord', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - case 400: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\SnapTrade\Model\Model400FailedRequestResponse', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - case 403: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\SnapTrade\Model\Model403FailedRequestResponse', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; - } - throw $e; - } - } - - /** - * Operation placeForceOrderAsync - * - * Place order - * - * Places a brokerage order in the specified account. The order could be rejected by the brokerage if it is invalid or if the account does not have sufficient funds. This endpoint does not compute the impact to the account balance from the order and any potential commissions before submitting the order to the brokerage. If that is desired, you can use the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. - * - * @param string $user_id (required) - * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeFormWithOptions $manual_trade_form_with_options (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeForceOrder'] to see the possible values for this operation - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - public function placeForceOrderAsync( - - $account_id, - $action, - $order_type, - $time_in_force, - $user_id, - $user_secret, - $universal_symbol_id = SENTINEL_VALUE, - $symbol = SENTINEL_VALUE, - $price = SENTINEL_VALUE, - $stop = SENTINEL_VALUE, - $units = SENTINEL_VALUE, - $notional_value = SENTINEL_VALUE, - string $contentType = self::contentTypes['placeForceOrder'][0] - ) - { - $_body = []; - $this->setRequestBodyProperty($_body, "account_id", $account_id); - $this->setRequestBodyProperty($_body, "action", $action); - $this->setRequestBodyProperty($_body, "universal_symbol_id", $universal_symbol_id); - $this->setRequestBodyProperty($_body, "symbol", $symbol); - $this->setRequestBodyProperty($_body, "order_type", $order_type); - $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); - $this->setRequestBodyProperty($_body, "price", $price); - $this->setRequestBodyProperty($_body, "stop", $stop); - $this->setRequestBodyProperty($_body, "units", $units); - $this->setRequestBodyProperty($_body, "notional_value", $notional_value); - $manual_trade_form_with_options = $_body; - - return $this->placeForceOrderAsyncWithHttpInfo($user_id, $user_secret, $manual_trade_form_with_options, $contentType) - ->then( - function ($response) { - return $response[0]; - } - ); - } - - /** - * Operation placeForceOrderAsyncWithHttpInfo - * - * Place order - * - * Places a brokerage order in the specified account. The order could be rejected by the brokerage if it is invalid or if the account does not have sufficient funds. This endpoint does not compute the impact to the account balance from the order and any potential commissions before submitting the order to the brokerage. If that is desired, you can use the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. - * - * @param string $user_id (required) - * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeFormWithOptions $manual_trade_form_with_options (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeForceOrder'] to see the possible values for this operation - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Promise\PromiseInterface - */ - public function placeForceOrderAsyncWithHttpInfo($user_id, $user_secret, $manual_trade_form_with_options, string $contentType = self::contentTypes['placeForceOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) - { - $returnType = '\SnapTrade\Model\AccountOrderRecord'; - ["request" => $request, "serializedBody" => $serializedBody] = $this->placeForceOrderRequest($user_id, $user_secret, $manual_trade_form_with_options, $contentType); - - // Customization hook - $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); - - return $this->client - ->sendAsync($request, $this->createHttpClientOption()) - ->then( - function ($response) use ($returnType) { - if ($returnType === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ($returnType !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, $returnType, []), - $response->getStatusCode(), - $response->getHeaders() - ]; - }, - function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } - ); - } - - /** - * Create request for operation 'placeForceOrder' - * - * @param string $user_id (required) - * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeFormWithOptions $manual_trade_form_with_options (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeForceOrder'] to see the possible values for this operation - * - * @throws \InvalidArgumentException - * @return \GuzzleHttp\Psr7\Request - */ - public function placeForceOrderRequest($user_id, $user_secret, $manual_trade_form_with_options, string $contentType = self::contentTypes['placeForceOrder'][0]) - { - - // Check if $user_id is a string - if ($user_id !== SENTINEL_VALUE && !is_string($user_id)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_id, true), gettype($user_id))); - } - // verify the required parameter 'user_id' is set - if ($user_id === SENTINEL_VALUE || (is_array($user_id) && count($user_id) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter user_id when calling placeForceOrder' - ); - } - // Check if $user_secret is a string - if ($user_secret !== SENTINEL_VALUE && !is_string($user_secret)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_secret, true), gettype($user_secret))); - } - // verify the required parameter 'user_secret' is set - if ($user_secret === SENTINEL_VALUE || (is_array($user_secret) && count($user_secret) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter user_secret when calling placeForceOrder' - ); - } - if ($manual_trade_form_with_options !== SENTINEL_VALUE) { - if (!($manual_trade_form_with_options instanceof \SnapTrade\Model\ManualTradeFormWithOptions)) { - if (!is_array($manual_trade_form_with_options)) - throw new \InvalidArgumentException('"manual_trade_form_with_options" must be associative array or an instance of \SnapTrade\Model\ManualTradeFormWithOptions TradingApi.placeForceOrder.'); - else - $manual_trade_form_with_options = new \SnapTrade\Model\ManualTradeFormWithOptions($manual_trade_form_with_options); - } - } - // verify the required parameter 'manual_trade_form_with_options' is set - if ($manual_trade_form_with_options === SENTINEL_VALUE || (is_array($manual_trade_form_with_options) && count($manual_trade_form_with_options) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter manual_trade_form_with_options when calling placeForceOrder' - ); - } - - - $resourcePath = '/trade/place'; - $formParams = []; - $queryParams = []; - $headerParams = []; - $httpBody = ''; - $multipart = false; - - if ($user_id !== SENTINEL_VALUE) { - // query params - $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( - $user_id, - 'userId', // param base name - 'string', // openApiType - 'form', // style - true, // explode - true // required - ) ?? []); - } - if ($user_secret !== SENTINEL_VALUE) { + if ($use_ticker !== SENTINEL_VALUE) { // query params - $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( - $user_secret, - 'userSecret', // param base name - 'string', // openApiType + $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( + $use_ticker, + 'use_ticker', // param base name + 'boolean', // openApiType 'form', // style true, // explode - true // required + false // required ) ?? []); } + // path params + if ($account_id !== SENTINEL_VALUE) { + $resourcePath = str_replace( + '{' . 'accountId' . '}', + ObjectSerializer::toPathValue($account_id), + $resourcePath + ); + } $headers = $this->headerSelector->selectHeaders( @@ -3456,14 +1991,7 @@ public function placeForceOrderRequest($user_id, $user_secret, $manual_trade_for ); // for model (json/xml) - if (isset($manual_trade_form_with_options)) { - if (stripos($headers['Content-Type'], 'application/json') !== false) { - # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($manual_trade_form_with_options)); - } else { - $httpBody = $manual_trade_form_with_options; - } - } elseif (count($formParams) > 0) { + if (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { @@ -3514,7 +2042,7 @@ public function placeForceOrderRequest($user_id, $user_secret, $manual_trade_for $headers ); - $method = 'POST'; + $method = 'GET'; $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody); $operationHost = $this->config->getHost(); @@ -3531,69 +2059,77 @@ public function placeForceOrderRequest($user_id, $user_secret, $manual_trade_for } /** - * Operation placeMlegOrder + * Operation placeBracketOrder * - * Place multi-leg option order + * Place a Bracket Order * - * Places a multi-leg option order. Only supported on certain option trading brokerages. https://snaptrade.notion.site/brokerages has information on brokerage trading support + * Places a bracket order (entry order + OCO of stop loss and take profit). Disabled by default please contact support for use. Only supported on certain brokerages * + * @param string $account_id The ID of the account to execute the trade on. (required) * @param string $user_id user_id (required) * @param string $user_secret user_secret (required) - * @param string $account_id account_id (required) - * @param \SnapTrade\Model\MlegTradeForm $mleg_trade_form mleg_trade_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeMlegOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeFormBracket $manual_trade_form_bracket manual_trade_form_bracket (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeBracketOrder'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return \SnapTrade\Model\MlegOrderResponse|\SnapTrade\Model\Model400FailedRequestResponse + * @return \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse */ - public function placeMlegOrder( + public function placeBracketOrder( + $action, + $instrument, $order_type, $time_in_force, - $legs, + $stop_loss, + $take_profit, + $account_id, $user_id, $user_secret, - $account_id, - $limit_price = SENTINEL_VALUE, - $stop_price = SENTINEL_VALUE, - $price_effect = SENTINEL_VALUE, - string $contentType = self::contentTypes['placeMlegOrder'][0] + $symbol = SENTINEL_VALUE, + $price = SENTINEL_VALUE, + $stop = SENTINEL_VALUE, + $units = SENTINEL_VALUE, + string $contentType = self::contentTypes['placeBracketOrder'][0] ) { $_body = []; + $this->setRequestBodyProperty($_body, "action", $action); + $this->setRequestBodyProperty($_body, "symbol", $symbol); + $this->setRequestBodyProperty($_body, "instrument", $instrument); $this->setRequestBodyProperty($_body, "order_type", $order_type); $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); - $this->setRequestBodyProperty($_body, "limit_price", $limit_price); - $this->setRequestBodyProperty($_body, "stop_price", $stop_price); - $this->setRequestBodyProperty($_body, "price_effect", $price_effect); - $this->setRequestBodyProperty($_body, "legs", $legs); - $mleg_trade_form = $_body; + $this->setRequestBodyProperty($_body, "price", $price); + $this->setRequestBodyProperty($_body, "stop", $stop); + $this->setRequestBodyProperty($_body, "units", $units); + $this->setRequestBodyProperty($_body, "stop_loss", $stop_loss); + $this->setRequestBodyProperty($_body, "take_profit", $take_profit); + $manual_trade_form_bracket = $_body; - list($response) = $this->placeMlegOrderWithHttpInfo($user_id, $user_secret, $account_id, $mleg_trade_form, $contentType); + list($response) = $this->placeBracketOrderWithHttpInfo($account_id, $user_id, $user_secret, $manual_trade_form_bracket, $contentType); return $response; } /** - * Operation placeMlegOrderWithHttpInfo + * Operation placeBracketOrderWithHttpInfo * - * Place multi-leg option order + * Place a Bracket Order * - * Places a multi-leg option order. Only supported on certain option trading brokerages. https://snaptrade.notion.site/brokerages has information on brokerage trading support + * Places a bracket order (entry order + OCO of stop loss and take profit). Disabled by default please contact support for use. Only supported on certain brokerages * + * @param string $account_id The ID of the account to execute the trade on. (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param \SnapTrade\Model\MlegTradeForm $mleg_trade_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeMlegOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeFormBracket $manual_trade_form_bracket (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeBracketOrder'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return array of \SnapTrade\Model\MlegOrderResponse|\SnapTrade\Model\Model400FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) + * @return array of \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) */ - public function placeMlegOrderWithHttpInfo($user_id, $user_secret, $account_id, $mleg_trade_form, string $contentType = self::contentTypes['placeMlegOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function placeBracketOrderWithHttpInfo($account_id, $user_id, $user_secret, $manual_trade_form_bracket, string $contentType = self::contentTypes['placeBracketOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { - ["request" => $request, "serializedBody" => $serializedBody] = $this->placeMlegOrderRequest($user_id, $user_secret, $account_id, $mleg_trade_form, $contentType); + ["request" => $request, "serializedBody" => $serializedBody] = $this->placeBracketOrderRequest($account_id, $user_id, $user_secret, $manual_trade_form_bracket, $contentType); // Customization hook $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); @@ -3608,11 +2144,11 @@ public function placeMlegOrderWithHttpInfo($user_id, $user_secret, $account_id, !empty($this->getConfig()->getAccessToken()) && $requestOptions->shouldRetryOAuth() ) { - return $this->placeMlegOrderWithHttpInfo( + return $this->placeBracketOrderWithHttpInfo( + $account_id, $user_id, $user_secret, - $account_id, - $mleg_trade_form, + $manual_trade_form_bracket, $contentType, $requestOptions->setRetryOAuth(false) ); @@ -3650,17 +2186,17 @@ public function placeMlegOrderWithHttpInfo($user_id, $user_secret, $account_id, switch($statusCode) { case 200: - if ('\SnapTrade\Model\MlegOrderResponse' === '\SplFileObject') { + if ('\SnapTrade\Model\AccountOrderRecord' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); - if ('\SnapTrade\Model\MlegOrderResponse' !== 'string') { + if ('\SnapTrade\Model\AccountOrderRecord' !== 'string') { $content = json_decode($content); } } return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\MlegOrderResponse', []), + ObjectSerializer::deserialize($content, '\SnapTrade\Model\AccountOrderRecord', []), $response->getStatusCode(), $response->getHeaders() ]; @@ -3679,9 +2215,24 @@ public function placeMlegOrderWithHttpInfo($user_id, $user_secret, $account_id, $response->getStatusCode(), $response->getHeaders() ]; + case 403: + if ('\SnapTrade\Model\Model403FailedRequestResponse' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\SnapTrade\Model\Model403FailedRequestResponse' !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model403FailedRequestResponse', []), + $response->getStatusCode(), + $response->getHeaders() + ]; } - $returnType = '\SnapTrade\Model\MlegOrderResponse'; + $returnType = '\SnapTrade\Model\AccountOrderRecord'; if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { @@ -3702,7 +2253,7 @@ public function placeMlegOrderWithHttpInfo($user_id, $user_secret, $account_id, case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), - '\SnapTrade\Model\MlegOrderResponse', + '\SnapTrade\Model\AccountOrderRecord', $e->getResponseHeaders() ); $e->setResponseObject($data); @@ -3715,51 +2266,67 @@ public function placeMlegOrderWithHttpInfo($user_id, $user_secret, $account_id, ); $e->setResponseObject($data); break; + case 403: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SnapTrade\Model\Model403FailedRequestResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; } throw $e; } } /** - * Operation placeMlegOrderAsync + * Operation placeBracketOrderAsync * - * Place multi-leg option order + * Place a Bracket Order * - * Places a multi-leg option order. Only supported on certain option trading brokerages. https://snaptrade.notion.site/brokerages has information on brokerage trading support + * Places a bracket order (entry order + OCO of stop loss and take profit). Disabled by default please contact support for use. Only supported on certain brokerages * + * @param string $account_id The ID of the account to execute the trade on. (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param \SnapTrade\Model\MlegTradeForm $mleg_trade_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeMlegOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeFormBracket $manual_trade_form_bracket (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeBracketOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function placeMlegOrderAsync( + public function placeBracketOrderAsync( + $action, + $instrument, $order_type, $time_in_force, - $legs, + $stop_loss, + $take_profit, + $account_id, $user_id, $user_secret, - $account_id, - $limit_price = SENTINEL_VALUE, - $stop_price = SENTINEL_VALUE, - $price_effect = SENTINEL_VALUE, - string $contentType = self::contentTypes['placeMlegOrder'][0] + $symbol = SENTINEL_VALUE, + $price = SENTINEL_VALUE, + $stop = SENTINEL_VALUE, + $units = SENTINEL_VALUE, + string $contentType = self::contentTypes['placeBracketOrder'][0] ) { $_body = []; + $this->setRequestBodyProperty($_body, "action", $action); + $this->setRequestBodyProperty($_body, "symbol", $symbol); + $this->setRequestBodyProperty($_body, "instrument", $instrument); $this->setRequestBodyProperty($_body, "order_type", $order_type); $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); - $this->setRequestBodyProperty($_body, "limit_price", $limit_price); - $this->setRequestBodyProperty($_body, "stop_price", $stop_price); - $this->setRequestBodyProperty($_body, "price_effect", $price_effect); - $this->setRequestBodyProperty($_body, "legs", $legs); - $mleg_trade_form = $_body; + $this->setRequestBodyProperty($_body, "price", $price); + $this->setRequestBodyProperty($_body, "stop", $stop); + $this->setRequestBodyProperty($_body, "units", $units); + $this->setRequestBodyProperty($_body, "stop_loss", $stop_loss); + $this->setRequestBodyProperty($_body, "take_profit", $take_profit); + $manual_trade_form_bracket = $_body; - return $this->placeMlegOrderAsyncWithHttpInfo($user_id, $user_secret, $account_id, $mleg_trade_form, $contentType) + return $this->placeBracketOrderAsyncWithHttpInfo($account_id, $user_id, $user_secret, $manual_trade_form_bracket, $contentType) ->then( function ($response) { return $response[0]; @@ -3768,25 +2335,25 @@ function ($response) { } /** - * Operation placeMlegOrderAsyncWithHttpInfo + * Operation placeBracketOrderAsyncWithHttpInfo * - * Place multi-leg option order + * Place a Bracket Order * - * Places a multi-leg option order. Only supported on certain option trading brokerages. https://snaptrade.notion.site/brokerages has information on brokerage trading support + * Places a bracket order (entry order + OCO of stop loss and take profit). Disabled by default please contact support for use. Only supported on certain brokerages * + * @param string $account_id The ID of the account to execute the trade on. (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param \SnapTrade\Model\MlegTradeForm $mleg_trade_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeMlegOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeFormBracket $manual_trade_form_bracket (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeBracketOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function placeMlegOrderAsyncWithHttpInfo($user_id, $user_secret, $account_id, $mleg_trade_form, string $contentType = self::contentTypes['placeMlegOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function placeBracketOrderAsyncWithHttpInfo($account_id, $user_id, $user_secret, $manual_trade_form_bracket, string $contentType = self::contentTypes['placeBracketOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { - $returnType = '\SnapTrade\Model\MlegOrderResponse'; - ["request" => $request, "serializedBody" => $serializedBody] = $this->placeMlegOrderRequest($user_id, $user_secret, $account_id, $mleg_trade_form, $contentType); + $returnType = '\SnapTrade\Model\AccountOrderRecord'; + ["request" => $request, "serializedBody" => $serializedBody] = $this->placeBracketOrderRequest($account_id, $user_id, $user_secret, $manual_trade_form_bracket, $contentType); // Customization hook $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); @@ -3828,20 +2395,30 @@ function ($exception) { } /** - * Create request for operation 'placeMlegOrder' + * Create request for operation 'placeBracketOrder' * + * @param string $account_id The ID of the account to execute the trade on. (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param \SnapTrade\Model\MlegTradeForm $mleg_trade_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeMlegOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeFormBracket $manual_trade_form_bracket (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeBracketOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ - public function placeMlegOrderRequest($user_id, $user_secret, $account_id, $mleg_trade_form, string $contentType = self::contentTypes['placeMlegOrder'][0]) + public function placeBracketOrderRequest($account_id, $user_id, $user_secret, $manual_trade_form_bracket, string $contentType = self::contentTypes['placeBracketOrder'][0]) { + // Check if $account_id is a string + if ($account_id !== SENTINEL_VALUE && !is_string($account_id)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($account_id, true), gettype($account_id))); + } + // verify the required parameter 'account_id' is set + if ($account_id === SENTINEL_VALUE || (is_array($account_id) && count($account_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter account_id when calling placeBracketOrder' + ); + } // Check if $user_id is a string if ($user_id !== SENTINEL_VALUE && !is_string($user_id)) { throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_id, true), gettype($user_id))); @@ -3849,7 +2426,7 @@ public function placeMlegOrderRequest($user_id, $user_secret, $account_id, $mleg // verify the required parameter 'user_id' is set if ($user_id === SENTINEL_VALUE || (is_array($user_id) && count($user_id) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter user_id when calling placeMlegOrder' + 'Missing the required parameter user_id when calling placeBracketOrder' ); } // Check if $user_secret is a string @@ -3859,36 +2436,26 @@ public function placeMlegOrderRequest($user_id, $user_secret, $account_id, $mleg // verify the required parameter 'user_secret' is set if ($user_secret === SENTINEL_VALUE || (is_array($user_secret) && count($user_secret) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter user_secret when calling placeMlegOrder' - ); - } - // Check if $account_id is a string - if ($account_id !== SENTINEL_VALUE && !is_string($account_id)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($account_id, true), gettype($account_id))); - } - // verify the required parameter 'account_id' is set - if ($account_id === SENTINEL_VALUE || (is_array($account_id) && count($account_id) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter account_id when calling placeMlegOrder' + 'Missing the required parameter user_secret when calling placeBracketOrder' ); } - if ($mleg_trade_form !== SENTINEL_VALUE) { - if (!($mleg_trade_form instanceof \SnapTrade\Model\MlegTradeForm)) { - if (!is_array($mleg_trade_form)) - throw new \InvalidArgumentException('"mleg_trade_form" must be associative array or an instance of \SnapTrade\Model\MlegTradeForm TradingApi.placeMlegOrder.'); + if ($manual_trade_form_bracket !== SENTINEL_VALUE) { + if (!($manual_trade_form_bracket instanceof \SnapTrade\Model\ManualTradeFormBracket)) { + if (!is_array($manual_trade_form_bracket)) + throw new \InvalidArgumentException('"manual_trade_form_bracket" must be associative array or an instance of \SnapTrade\Model\ManualTradeFormBracket TradingApi.placeBracketOrder.'); else - $mleg_trade_form = new \SnapTrade\Model\MlegTradeForm($mleg_trade_form); + $manual_trade_form_bracket = new \SnapTrade\Model\ManualTradeFormBracket($manual_trade_form_bracket); } } - // verify the required parameter 'mleg_trade_form' is set - if ($mleg_trade_form === SENTINEL_VALUE || (is_array($mleg_trade_form) && count($mleg_trade_form) === 0)) { + // verify the required parameter 'manual_trade_form_bracket' is set + if ($manual_trade_form_bracket === SENTINEL_VALUE || (is_array($manual_trade_form_bracket) && count($manual_trade_form_bracket) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter mleg_trade_form when calling placeMlegOrder' + 'Missing the required parameter manual_trade_form_bracket when calling placeBracketOrder' ); } - $resourcePath = '/accounts/{accountId}/trading/options'; + $resourcePath = '/accounts/{accountId}/trading/bracket'; $formParams = []; $queryParams = []; $headerParams = []; @@ -3936,12 +2503,12 @@ public function placeMlegOrderRequest($user_id, $user_secret, $account_id, $mleg ); // for model (json/xml) - if (isset($mleg_trade_form)) { + if (isset($manual_trade_form_bracket)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($mleg_trade_form)); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($manual_trade_form_bracket)); } else { - $httpBody = $mleg_trade_form; + $httpBody = $manual_trade_form_bracket; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -4011,59 +2578,74 @@ public function placeMlegOrderRequest($user_id, $user_secret, $account_id, $mleg } /** - * Operation placeOrder + * Operation placeForceOrder * - * Place checked order + * Place order * - * Places the previously checked order with the brokerage. The `tradeId` is obtained from the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). If you prefer to place the order without checking for impact first, you can use the [place order endpoint](/reference/Trading/Trading_placeForceOrder). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. + * Places a brokerage order in the specified account. The order could be rejected by the brokerage if it is invalid or if the account does not have sufficient funds. This endpoint does not compute the impact to the account balance from the order and any potential commissions before submitting the order to the brokerage. If that is desired, you can use the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. * - * @param string $trade_id Obtained from calling the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact) (required) * @param string $user_id user_id (required) * @param string $user_secret user_secret (required) - * @param \SnapTrade\Model\ValidatedTradeBody $validated_trade_body validated_trade_body (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeFormWithOptions $manual_trade_form_with_options manual_trade_form_with_options (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeForceOrder'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse + * @return \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse */ - public function placeOrder( - $trade_id, + public function placeForceOrder( + + $account_id, + $action, + $order_type, + $time_in_force, $user_id, $user_secret, - $wait_to_confirm = SENTINEL_VALUE, - - string $contentType = self::contentTypes['placeOrder'][0] + $universal_symbol_id = SENTINEL_VALUE, + $symbol = SENTINEL_VALUE, + $price = SENTINEL_VALUE, + $stop = SENTINEL_VALUE, + $units = SENTINEL_VALUE, + $notional_value = SENTINEL_VALUE, + string $contentType = self::contentTypes['placeForceOrder'][0] ) { - $_body = null; - $this->setRequestBodyProperty($_body, "wait_to_confirm", $wait_to_confirm); - $validated_trade_body = $_body; + $_body = []; + $this->setRequestBodyProperty($_body, "account_id", $account_id); + $this->setRequestBodyProperty($_body, "action", $action); + $this->setRequestBodyProperty($_body, "universal_symbol_id", $universal_symbol_id); + $this->setRequestBodyProperty($_body, "symbol", $symbol); + $this->setRequestBodyProperty($_body, "order_type", $order_type); + $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); + $this->setRequestBodyProperty($_body, "price", $price); + $this->setRequestBodyProperty($_body, "stop", $stop); + $this->setRequestBodyProperty($_body, "units", $units); + $this->setRequestBodyProperty($_body, "notional_value", $notional_value); + $manual_trade_form_with_options = $_body; - list($response) = $this->placeOrderWithHttpInfo($trade_id, $user_id, $user_secret, $validated_trade_body, $contentType); + list($response) = $this->placeForceOrderWithHttpInfo($user_id, $user_secret, $manual_trade_form_with_options, $contentType); return $response; } /** - * Operation placeOrderWithHttpInfo + * Operation placeForceOrderWithHttpInfo * - * Place checked order + * Place order * - * Places the previously checked order with the brokerage. The `tradeId` is obtained from the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). If you prefer to place the order without checking for impact first, you can use the [place order endpoint](/reference/Trading/Trading_placeForceOrder). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. + * Places a brokerage order in the specified account. The order could be rejected by the brokerage if it is invalid or if the account does not have sufficient funds. This endpoint does not compute the impact to the account balance from the order and any potential commissions before submitting the order to the brokerage. If that is desired, you can use the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. * - * @param string $trade_id Obtained from calling the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact) (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param \SnapTrade\Model\ValidatedTradeBody $validated_trade_body (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeFormWithOptions $manual_trade_form_with_options (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeForceOrder'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return array of \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) + * @return array of \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) */ - public function placeOrderWithHttpInfo($trade_id, $user_id, $user_secret, $validated_trade_body = null, string $contentType = self::contentTypes['placeOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function placeForceOrderWithHttpInfo($user_id, $user_secret, $manual_trade_form_with_options, string $contentType = self::contentTypes['placeForceOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { - ["request" => $request, "serializedBody" => $serializedBody] = $this->placeOrderRequest($trade_id, $user_id, $user_secret, $validated_trade_body, $contentType); + ["request" => $request, "serializedBody" => $serializedBody] = $this->placeForceOrderRequest($user_id, $user_secret, $manual_trade_form_with_options, $contentType); // Customization hook $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); @@ -4078,11 +2660,10 @@ public function placeOrderWithHttpInfo($trade_id, $user_id, $user_secret, $valid !empty($this->getConfig()->getAccessToken()) && $requestOptions->shouldRetryOAuth() ) { - return $this->placeOrderWithHttpInfo( - $trade_id, + return $this->placeForceOrderWithHttpInfo( $user_id, $user_secret, - $validated_trade_body, + $manual_trade_form_with_options, $contentType, $requestOptions->setRetryOAuth(false) ); @@ -4149,6 +2730,21 @@ public function placeOrderWithHttpInfo($trade_id, $user_id, $user_secret, $valid $response->getStatusCode(), $response->getHeaders() ]; + case 403: + if ('\SnapTrade\Model\Model403FailedRequestResponse' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\SnapTrade\Model\Model403FailedRequestResponse' !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model403FailedRequestResponse', []), + $response->getStatusCode(), + $response->getHeaders() + ]; } $returnType = '\SnapTrade\Model\AccountOrderRecord'; @@ -4185,41 +2781,65 @@ public function placeOrderWithHttpInfo($trade_id, $user_id, $user_secret, $valid ); $e->setResponseObject($data); break; + case 403: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SnapTrade\Model\Model403FailedRequestResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; } throw $e; } } /** - * Operation placeOrderAsync + * Operation placeForceOrderAsync * - * Place checked order + * Place order * - * Places the previously checked order with the brokerage. The `tradeId` is obtained from the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). If you prefer to place the order without checking for impact first, you can use the [place order endpoint](/reference/Trading/Trading_placeForceOrder). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. + * Places a brokerage order in the specified account. The order could be rejected by the brokerage if it is invalid or if the account does not have sufficient funds. This endpoint does not compute the impact to the account balance from the order and any potential commissions before submitting the order to the brokerage. If that is desired, you can use the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. * - * @param string $trade_id Obtained from calling the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact) (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param \SnapTrade\Model\ValidatedTradeBody $validated_trade_body (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeFormWithOptions $manual_trade_form_with_options (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeForceOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function placeOrderAsync( - $trade_id, + public function placeForceOrderAsync( + + $account_id, + $action, + $order_type, + $time_in_force, $user_id, $user_secret, - $wait_to_confirm = SENTINEL_VALUE, - - string $contentType = self::contentTypes['placeOrder'][0] + $universal_symbol_id = SENTINEL_VALUE, + $symbol = SENTINEL_VALUE, + $price = SENTINEL_VALUE, + $stop = SENTINEL_VALUE, + $units = SENTINEL_VALUE, + $notional_value = SENTINEL_VALUE, + string $contentType = self::contentTypes['placeForceOrder'][0] ) { - $_body = null; - $this->setRequestBodyProperty($_body, "wait_to_confirm", $wait_to_confirm); - $validated_trade_body = $_body; + $_body = []; + $this->setRequestBodyProperty($_body, "account_id", $account_id); + $this->setRequestBodyProperty($_body, "action", $action); + $this->setRequestBodyProperty($_body, "universal_symbol_id", $universal_symbol_id); + $this->setRequestBodyProperty($_body, "symbol", $symbol); + $this->setRequestBodyProperty($_body, "order_type", $order_type); + $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); + $this->setRequestBodyProperty($_body, "price", $price); + $this->setRequestBodyProperty($_body, "stop", $stop); + $this->setRequestBodyProperty($_body, "units", $units); + $this->setRequestBodyProperty($_body, "notional_value", $notional_value); + $manual_trade_form_with_options = $_body; - return $this->placeOrderAsyncWithHttpInfo($trade_id, $user_id, $user_secret, $validated_trade_body, $contentType) + return $this->placeForceOrderAsyncWithHttpInfo($user_id, $user_secret, $manual_trade_form_with_options, $contentType) ->then( function ($response) { return $response[0]; @@ -4228,25 +2848,24 @@ function ($response) { } /** - * Operation placeOrderAsyncWithHttpInfo + * Operation placeForceOrderAsyncWithHttpInfo * - * Place checked order + * Place order * - * Places the previously checked order with the brokerage. The `tradeId` is obtained from the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). If you prefer to place the order without checking for impact first, you can use the [place order endpoint](/reference/Trading/Trading_placeForceOrder). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. + * Places a brokerage order in the specified account. The order could be rejected by the brokerage if it is invalid or if the account does not have sufficient funds. This endpoint does not compute the impact to the account balance from the order and any potential commissions before submitting the order to the brokerage. If that is desired, you can use the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. * - * @param string $trade_id Obtained from calling the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact) (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param \SnapTrade\Model\ValidatedTradeBody $validated_trade_body (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeFormWithOptions $manual_trade_form_with_options (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeForceOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function placeOrderAsyncWithHttpInfo($trade_id, $user_id, $user_secret, $validated_trade_body = null, string $contentType = self::contentTypes['placeOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function placeForceOrderAsyncWithHttpInfo($user_id, $user_secret, $manual_trade_form_with_options, string $contentType = self::contentTypes['placeForceOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { $returnType = '\SnapTrade\Model\AccountOrderRecord'; - ["request" => $request, "serializedBody" => $serializedBody] = $this->placeOrderRequest($trade_id, $user_id, $user_secret, $validated_trade_body, $contentType); + ["request" => $request, "serializedBody" => $serializedBody] = $this->placeForceOrderRequest($user_id, $user_secret, $manual_trade_form_with_options, $contentType); // Customization hook $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); @@ -4288,30 +2907,19 @@ function ($exception) { } /** - * Create request for operation 'placeOrder' + * Create request for operation 'placeForceOrder' * - * @param string $trade_id Obtained from calling the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact) (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param \SnapTrade\Model\ValidatedTradeBody $validated_trade_body (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeFormWithOptions $manual_trade_form_with_options (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeForceOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ - public function placeOrderRequest($trade_id, $user_id, $user_secret, $validated_trade_body = SENTINEL_VALUE, string $contentType = self::contentTypes['placeOrder'][0]) + public function placeForceOrderRequest($user_id, $user_secret, $manual_trade_form_with_options, string $contentType = self::contentTypes['placeForceOrder'][0]) { - // Check if $trade_id is a string - if ($trade_id !== SENTINEL_VALUE && !is_string($trade_id)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($trade_id, true), gettype($trade_id))); - } - // verify the required parameter 'trade_id' is set - if ($trade_id === SENTINEL_VALUE || (is_array($trade_id) && count($trade_id) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter trade_id when calling placeOrder' - ); - } // Check if $user_id is a string if ($user_id !== SENTINEL_VALUE && !is_string($user_id)) { throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_id, true), gettype($user_id))); @@ -4319,7 +2927,7 @@ public function placeOrderRequest($trade_id, $user_id, $user_secret, $validated_ // verify the required parameter 'user_id' is set if ($user_id === SENTINEL_VALUE || (is_array($user_id) && count($user_id) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter user_id when calling placeOrder' + 'Missing the required parameter user_id when calling placeForceOrder' ); } // Check if $user_secret is a string @@ -4329,20 +2937,26 @@ public function placeOrderRequest($trade_id, $user_id, $user_secret, $validated_ // verify the required parameter 'user_secret' is set if ($user_secret === SENTINEL_VALUE || (is_array($user_secret) && count($user_secret) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter user_secret when calling placeOrder' + 'Missing the required parameter user_secret when calling placeForceOrder' ); } - if ($validated_trade_body !== SENTINEL_VALUE) { - if (!($validated_trade_body instanceof \SnapTrade\Model\ValidatedTradeBody)) { - if (!is_array($validated_trade_body)) - throw new \InvalidArgumentException('"validated_trade_body" must be associative array or an instance of \SnapTrade\Model\ValidatedTradeBody TradingApi.placeOrder.'); + if ($manual_trade_form_with_options !== SENTINEL_VALUE) { + if (!($manual_trade_form_with_options instanceof \SnapTrade\Model\ManualTradeFormWithOptions)) { + if (!is_array($manual_trade_form_with_options)) + throw new \InvalidArgumentException('"manual_trade_form_with_options" must be associative array or an instance of \SnapTrade\Model\ManualTradeFormWithOptions TradingApi.placeForceOrder.'); else - $validated_trade_body = new \SnapTrade\Model\ValidatedTradeBody($validated_trade_body); + $manual_trade_form_with_options = new \SnapTrade\Model\ManualTradeFormWithOptions($manual_trade_form_with_options); } } + // verify the required parameter 'manual_trade_form_with_options' is set + if ($manual_trade_form_with_options === SENTINEL_VALUE || (is_array($manual_trade_form_with_options) && count($manual_trade_form_with_options) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter manual_trade_form_with_options when calling placeForceOrder' + ); + } - $resourcePath = '/trade/{tradeId}'; + $resourcePath = '/trade/place'; $formParams = []; $queryParams = []; $headerParams = []; @@ -4373,14 +2987,6 @@ public function placeOrderRequest($trade_id, $user_id, $user_secret, $validated_ } - // path params - if ($trade_id !== SENTINEL_VALUE) { - $resourcePath = str_replace( - '{' . 'tradeId' . '}', - ObjectSerializer::toPathValue($trade_id), - $resourcePath - ); - } $headers = $this->headerSelector->selectHeaders( @@ -4390,12 +2996,12 @@ public function placeOrderRequest($trade_id, $user_id, $user_secret, $validated_ ); // for model (json/xml) - if (isset($validated_trade_body)) { + if (isset($manual_trade_form_with_options)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($validated_trade_body)); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($manual_trade_form_with_options)); } else { - $httpBody = $validated_trade_body; + $httpBody = $manual_trade_form_with_options; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -4465,75 +3071,69 @@ public function placeOrderRequest($trade_id, $user_id, $user_secret, $validated_ } /** - * Operation placeSimpleOrder + * Operation placeMlegOrder * - * Place order + * Place multi-leg option order * - * Places an order in the specified account. This endpoint does not compute the impact to the account balance from the order before submitting the order. + * Places a multi-leg option order. Only supported on certain option trading brokerages. https://snaptrade.notion.site/brokerages has information on brokerage trading support * * @param string $user_id user_id (required) * @param string $user_secret user_secret (required) * @param string $account_id account_id (required) - * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form simple_order_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeSimpleOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\MlegTradeForm $mleg_trade_form mleg_trade_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeMlegOrder'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return \SnapTrade\Model\OrderUpdatedResponse|\SnapTrade\Model\Model400FailedRequestResponse + * @return \SnapTrade\Model\MlegOrderResponse|\SnapTrade\Model\Model400FailedRequestResponse */ - public function placeSimpleOrder( + public function placeMlegOrder( - $instrument, - $side, - $type, + $order_type, $time_in_force, - $amount, + $legs, $user_id, $user_secret, $account_id, $limit_price = SENTINEL_VALUE, $stop_price = SENTINEL_VALUE, - $post_only = SENTINEL_VALUE, - $expiration_date = SENTINEL_VALUE, - string $contentType = self::contentTypes['placeSimpleOrder'][0] + $price_effect = SENTINEL_VALUE, + string $contentType = self::contentTypes['placeMlegOrder'][0] ) { $_body = []; - $this->setRequestBodyProperty($_body, "instrument", $instrument); - $this->setRequestBodyProperty($_body, "side", $side); - $this->setRequestBodyProperty($_body, "type", $type); + $this->setRequestBodyProperty($_body, "order_type", $order_type); $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); - $this->setRequestBodyProperty($_body, "amount", $amount); $this->setRequestBodyProperty($_body, "limit_price", $limit_price); $this->setRequestBodyProperty($_body, "stop_price", $stop_price); - $this->setRequestBodyProperty($_body, "post_only", $post_only); - $this->setRequestBodyProperty($_body, "expiration_date", $expiration_date); - $simple_order_form = $_body; + $this->setRequestBodyProperty($_body, "price_effect", $price_effect); + $this->setRequestBodyProperty($_body, "legs", $legs); + $mleg_trade_form = $_body; - list($response) = $this->placeSimpleOrderWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, $contentType); + list($response) = $this->placeMlegOrderWithHttpInfo($user_id, $user_secret, $account_id, $mleg_trade_form, $contentType); return $response; } /** - * Operation placeSimpleOrderWithHttpInfo + * Operation placeMlegOrderWithHttpInfo * - * Place order + * Place multi-leg option order * - * Places an order in the specified account. This endpoint does not compute the impact to the account balance from the order before submitting the order. + * Places a multi-leg option order. Only supported on certain option trading brokerages. https://snaptrade.notion.site/brokerages has information on brokerage trading support * * @param string $user_id (required) * @param string $user_secret (required) * @param string $account_id (required) - * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeSimpleOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\MlegTradeForm $mleg_trade_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeMlegOrder'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return array of \SnapTrade\Model\OrderUpdatedResponse|\SnapTrade\Model\Model400FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) + * @return array of \SnapTrade\Model\MlegOrderResponse|\SnapTrade\Model\Model400FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) */ - public function placeSimpleOrderWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, string $contentType = self::contentTypes['placeSimpleOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function placeMlegOrderWithHttpInfo($user_id, $user_secret, $account_id, $mleg_trade_form, string $contentType = self::contentTypes['placeMlegOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { - ["request" => $request, "serializedBody" => $serializedBody] = $this->placeSimpleOrderRequest($user_id, $user_secret, $account_id, $simple_order_form, $contentType); + ["request" => $request, "serializedBody" => $serializedBody] = $this->placeMlegOrderRequest($user_id, $user_secret, $account_id, $mleg_trade_form, $contentType); // Customization hook $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); @@ -4548,11 +3148,11 @@ public function placeSimpleOrderWithHttpInfo($user_id, $user_secret, $account_id !empty($this->getConfig()->getAccessToken()) && $requestOptions->shouldRetryOAuth() ) { - return $this->placeSimpleOrderWithHttpInfo( + return $this->placeMlegOrderWithHttpInfo( $user_id, $user_secret, $account_id, - $simple_order_form, + $mleg_trade_form, $contentType, $requestOptions->setRetryOAuth(false) ); @@ -4590,17 +3190,17 @@ public function placeSimpleOrderWithHttpInfo($user_id, $user_secret, $account_id switch($statusCode) { case 200: - if ('\SnapTrade\Model\OrderUpdatedResponse' === '\SplFileObject') { + if ('\SnapTrade\Model\MlegOrderResponse' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); - if ('\SnapTrade\Model\OrderUpdatedResponse' !== 'string') { + if ('\SnapTrade\Model\MlegOrderResponse' !== 'string') { $content = json_decode($content); } } return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\OrderUpdatedResponse', []), + ObjectSerializer::deserialize($content, '\SnapTrade\Model\MlegOrderResponse', []), $response->getStatusCode(), $response->getHeaders() ]; @@ -4621,7 +3221,7 @@ public function placeSimpleOrderWithHttpInfo($user_id, $user_secret, $account_id ]; } - $returnType = '\SnapTrade\Model\OrderUpdatedResponse'; + $returnType = '\SnapTrade\Model\MlegOrderResponse'; if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { @@ -4642,7 +3242,7 @@ public function placeSimpleOrderWithHttpInfo($user_id, $user_secret, $account_id case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), - '\SnapTrade\Model\OrderUpdatedResponse', + '\SnapTrade\Model\MlegOrderResponse', $e->getResponseHeaders() ); $e->setResponseObject($data); @@ -4661,51 +3261,45 @@ public function placeSimpleOrderWithHttpInfo($user_id, $user_secret, $account_id } /** - * Operation placeSimpleOrderAsync + * Operation placeMlegOrderAsync * - * Place order + * Place multi-leg option order * - * Places an order in the specified account. This endpoint does not compute the impact to the account balance from the order before submitting the order. + * Places a multi-leg option order. Only supported on certain option trading brokerages. https://snaptrade.notion.site/brokerages has information on brokerage trading support * * @param string $user_id (required) * @param string $user_secret (required) * @param string $account_id (required) - * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeSimpleOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\MlegTradeForm $mleg_trade_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeMlegOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function placeSimpleOrderAsync( + public function placeMlegOrderAsync( - $instrument, - $side, - $type, + $order_type, $time_in_force, - $amount, + $legs, $user_id, $user_secret, $account_id, $limit_price = SENTINEL_VALUE, $stop_price = SENTINEL_VALUE, - $post_only = SENTINEL_VALUE, - $expiration_date = SENTINEL_VALUE, - string $contentType = self::contentTypes['placeSimpleOrder'][0] + $price_effect = SENTINEL_VALUE, + string $contentType = self::contentTypes['placeMlegOrder'][0] ) { $_body = []; - $this->setRequestBodyProperty($_body, "instrument", $instrument); - $this->setRequestBodyProperty($_body, "side", $side); - $this->setRequestBodyProperty($_body, "type", $type); + $this->setRequestBodyProperty($_body, "order_type", $order_type); $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); - $this->setRequestBodyProperty($_body, "amount", $amount); $this->setRequestBodyProperty($_body, "limit_price", $limit_price); $this->setRequestBodyProperty($_body, "stop_price", $stop_price); - $this->setRequestBodyProperty($_body, "post_only", $post_only); - $this->setRequestBodyProperty($_body, "expiration_date", $expiration_date); - $simple_order_form = $_body; + $this->setRequestBodyProperty($_body, "price_effect", $price_effect); + $this->setRequestBodyProperty($_body, "legs", $legs); + $mleg_trade_form = $_body; - return $this->placeSimpleOrderAsyncWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, $contentType) + return $this->placeMlegOrderAsyncWithHttpInfo($user_id, $user_secret, $account_id, $mleg_trade_form, $contentType) ->then( function ($response) { return $response[0]; @@ -4714,25 +3308,25 @@ function ($response) { } /** - * Operation placeSimpleOrderAsyncWithHttpInfo + * Operation placeMlegOrderAsyncWithHttpInfo * - * Place order + * Place multi-leg option order * - * Places an order in the specified account. This endpoint does not compute the impact to the account balance from the order before submitting the order. + * Places a multi-leg option order. Only supported on certain option trading brokerages. https://snaptrade.notion.site/brokerages has information on brokerage trading support * * @param string $user_id (required) * @param string $user_secret (required) * @param string $account_id (required) - * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeSimpleOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\MlegTradeForm $mleg_trade_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeMlegOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function placeSimpleOrderAsyncWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, string $contentType = self::contentTypes['placeSimpleOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function placeMlegOrderAsyncWithHttpInfo($user_id, $user_secret, $account_id, $mleg_trade_form, string $contentType = self::contentTypes['placeMlegOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { - $returnType = '\SnapTrade\Model\OrderUpdatedResponse'; - ["request" => $request, "serializedBody" => $serializedBody] = $this->placeSimpleOrderRequest($user_id, $user_secret, $account_id, $simple_order_form, $contentType); + $returnType = '\SnapTrade\Model\MlegOrderResponse'; + ["request" => $request, "serializedBody" => $serializedBody] = $this->placeMlegOrderRequest($user_id, $user_secret, $account_id, $mleg_trade_form, $contentType); // Customization hook $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); @@ -4774,18 +3368,18 @@ function ($exception) { } /** - * Create request for operation 'placeSimpleOrder' + * Create request for operation 'placeMlegOrder' * * @param string $user_id (required) * @param string $user_secret (required) * @param string $account_id (required) - * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeSimpleOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\MlegTradeForm $mleg_trade_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeMlegOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ - public function placeSimpleOrderRequest($user_id, $user_secret, $account_id, $simple_order_form, string $contentType = self::contentTypes['placeSimpleOrder'][0]) + public function placeMlegOrderRequest($user_id, $user_secret, $account_id, $mleg_trade_form, string $contentType = self::contentTypes['placeMlegOrder'][0]) { // Check if $user_id is a string @@ -4795,7 +3389,7 @@ public function placeSimpleOrderRequest($user_id, $user_secret, $account_id, $si // verify the required parameter 'user_id' is set if ($user_id === SENTINEL_VALUE || (is_array($user_id) && count($user_id) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter user_id when calling placeSimpleOrder' + 'Missing the required parameter user_id when calling placeMlegOrder' ); } // Check if $user_secret is a string @@ -4805,7 +3399,7 @@ public function placeSimpleOrderRequest($user_id, $user_secret, $account_id, $si // verify the required parameter 'user_secret' is set if ($user_secret === SENTINEL_VALUE || (is_array($user_secret) && count($user_secret) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter user_secret when calling placeSimpleOrder' + 'Missing the required parameter user_secret when calling placeMlegOrder' ); } // Check if $account_id is a string @@ -4815,26 +3409,26 @@ public function placeSimpleOrderRequest($user_id, $user_secret, $account_id, $si // verify the required parameter 'account_id' is set if ($account_id === SENTINEL_VALUE || (is_array($account_id) && count($account_id) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter account_id when calling placeSimpleOrder' + 'Missing the required parameter account_id when calling placeMlegOrder' ); } - if ($simple_order_form !== SENTINEL_VALUE) { - if (!($simple_order_form instanceof \SnapTrade\Model\SimpleOrderForm)) { - if (!is_array($simple_order_form)) - throw new \InvalidArgumentException('"simple_order_form" must be associative array or an instance of \SnapTrade\Model\SimpleOrderForm TradingApi.placeSimpleOrder.'); + if ($mleg_trade_form !== SENTINEL_VALUE) { + if (!($mleg_trade_form instanceof \SnapTrade\Model\MlegTradeForm)) { + if (!is_array($mleg_trade_form)) + throw new \InvalidArgumentException('"mleg_trade_form" must be associative array or an instance of \SnapTrade\Model\MlegTradeForm TradingApi.placeMlegOrder.'); else - $simple_order_form = new \SnapTrade\Model\SimpleOrderForm($simple_order_form); + $mleg_trade_form = new \SnapTrade\Model\MlegTradeForm($mleg_trade_form); } } - // verify the required parameter 'simple_order_form' is set - if ($simple_order_form === SENTINEL_VALUE || (is_array($simple_order_form) && count($simple_order_form) === 0)) { + // verify the required parameter 'mleg_trade_form' is set + if ($mleg_trade_form === SENTINEL_VALUE || (is_array($mleg_trade_form) && count($mleg_trade_form) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter simple_order_form when calling placeSimpleOrder' + 'Missing the required parameter mleg_trade_form when calling placeMlegOrder' ); } - $resourcePath = '/accounts/{accountId}/trading/simple'; + $resourcePath = '/accounts/{accountId}/trading/options'; $formParams = []; $queryParams = []; $headerParams = []; @@ -4882,12 +3476,12 @@ public function placeSimpleOrderRequest($user_id, $user_secret, $account_id, $si ); // for model (json/xml) - if (isset($simple_order_form)) { + if (isset($mleg_trade_form)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($simple_order_form)); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($mleg_trade_form)); } else { - $httpBody = $simple_order_form; + $httpBody = $mleg_trade_form; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -4957,75 +3551,59 @@ public function placeSimpleOrderRequest($user_id, $user_secret, $account_id, $si } /** - * Operation previewSimpleOrder + * Operation placeOrder * - * Preview order + * Place checked order * - * Previews an order using the specified account. + * Places the previously checked order with the brokerage. The `tradeId` is obtained from the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). If you prefer to place the order without checking for impact first, you can use the [place order endpoint](/reference/Trading/Trading_placeForceOrder). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. * + * @param string $trade_id Obtained from calling the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact) (required) * @param string $user_id user_id (required) * @param string $user_secret user_secret (required) - * @param string $account_id account_id (required) - * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form simple_order_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['previewSimpleOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\ValidatedTradeBody $validated_trade_body validated_trade_body (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return \SnapTrade\Model\SimpleOrderPreview|\SnapTrade\Model\Model400FailedRequestResponse + * @return \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse */ - public function previewSimpleOrder( - - $instrument, - $side, - $type, - $time_in_force, - $amount, + public function placeOrder( + $trade_id, $user_id, $user_secret, - $account_id, - $limit_price = SENTINEL_VALUE, - $stop_price = SENTINEL_VALUE, - $post_only = SENTINEL_VALUE, - $expiration_date = SENTINEL_VALUE, - string $contentType = self::contentTypes['previewSimpleOrder'][0] + $wait_to_confirm = SENTINEL_VALUE, + + string $contentType = self::contentTypes['placeOrder'][0] ) { - $_body = []; - $this->setRequestBodyProperty($_body, "instrument", $instrument); - $this->setRequestBodyProperty($_body, "side", $side); - $this->setRequestBodyProperty($_body, "type", $type); - $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); - $this->setRequestBodyProperty($_body, "amount", $amount); - $this->setRequestBodyProperty($_body, "limit_price", $limit_price); - $this->setRequestBodyProperty($_body, "stop_price", $stop_price); - $this->setRequestBodyProperty($_body, "post_only", $post_only); - $this->setRequestBodyProperty($_body, "expiration_date", $expiration_date); - $simple_order_form = $_body; + $_body = null; + $this->setRequestBodyProperty($_body, "wait_to_confirm", $wait_to_confirm); + $validated_trade_body = $_body; - list($response) = $this->previewSimpleOrderWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, $contentType); + list($response) = $this->placeOrderWithHttpInfo($trade_id, $user_id, $user_secret, $validated_trade_body, $contentType); return $response; } /** - * Operation previewSimpleOrderWithHttpInfo + * Operation placeOrderWithHttpInfo * - * Preview order + * Place checked order * - * Previews an order using the specified account. + * Places the previously checked order with the brokerage. The `tradeId` is obtained from the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). If you prefer to place the order without checking for impact first, you can use the [place order endpoint](/reference/Trading/Trading_placeForceOrder). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. * + * @param string $trade_id Obtained from calling the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact) (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['previewSimpleOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\ValidatedTradeBody $validated_trade_body (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return array of \SnapTrade\Model\SimpleOrderPreview|\SnapTrade\Model\Model400FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) + * @return array of \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) */ - public function previewSimpleOrderWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, string $contentType = self::contentTypes['previewSimpleOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function placeOrderWithHttpInfo($trade_id, $user_id, $user_secret, $validated_trade_body = null, string $contentType = self::contentTypes['placeOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { - ["request" => $request, "serializedBody" => $serializedBody] = $this->previewSimpleOrderRequest($user_id, $user_secret, $account_id, $simple_order_form, $contentType); + ["request" => $request, "serializedBody" => $serializedBody] = $this->placeOrderRequest($trade_id, $user_id, $user_secret, $validated_trade_body, $contentType); // Customization hook $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); @@ -5040,11 +3618,11 @@ public function previewSimpleOrderWithHttpInfo($user_id, $user_secret, $account_ !empty($this->getConfig()->getAccessToken()) && $requestOptions->shouldRetryOAuth() ) { - return $this->previewSimpleOrderWithHttpInfo( + return $this->placeOrderWithHttpInfo( + $trade_id, $user_id, $user_secret, - $account_id, - $simple_order_form, + $validated_trade_body, $contentType, $requestOptions->setRetryOAuth(false) ); @@ -5082,17 +3660,17 @@ public function previewSimpleOrderWithHttpInfo($user_id, $user_secret, $account_ switch($statusCode) { case 200: - if ('\SnapTrade\Model\SimpleOrderPreview' === '\SplFileObject') { + if ('\SnapTrade\Model\AccountOrderRecord' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); - if ('\SnapTrade\Model\SimpleOrderPreview' !== 'string') { + if ('\SnapTrade\Model\AccountOrderRecord' !== 'string') { $content = json_decode($content); } } return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\SimpleOrderPreview', []), + ObjectSerializer::deserialize($content, '\SnapTrade\Model\AccountOrderRecord', []), $response->getStatusCode(), $response->getHeaders() ]; @@ -5113,7 +3691,7 @@ public function previewSimpleOrderWithHttpInfo($user_id, $user_secret, $account_ ]; } - $returnType = '\SnapTrade\Model\SimpleOrderPreview'; + $returnType = '\SnapTrade\Model\AccountOrderRecord'; if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { @@ -5134,7 +3712,7 @@ public function previewSimpleOrderWithHttpInfo($user_id, $user_secret, $account_ case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), - '\SnapTrade\Model\SimpleOrderPreview', + '\SnapTrade\Model\AccountOrderRecord', $e->getResponseHeaders() ); $e->setResponseObject($data); @@ -5153,51 +3731,35 @@ public function previewSimpleOrderWithHttpInfo($user_id, $user_secret, $account_ } /** - * Operation previewSimpleOrderAsync + * Operation placeOrderAsync * - * Preview order + * Place checked order * - * Previews an order using the specified account. + * Places the previously checked order with the brokerage. The `tradeId` is obtained from the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). If you prefer to place the order without checking for impact first, you can use the [place order endpoint](/reference/Trading/Trading_placeForceOrder). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. * + * @param string $trade_id Obtained from calling the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact) (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['previewSimpleOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\ValidatedTradeBody $validated_trade_body (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function previewSimpleOrderAsync( - - $instrument, - $side, - $type, - $time_in_force, - $amount, + public function placeOrderAsync( + $trade_id, $user_id, $user_secret, - $account_id, - $limit_price = SENTINEL_VALUE, - $stop_price = SENTINEL_VALUE, - $post_only = SENTINEL_VALUE, - $expiration_date = SENTINEL_VALUE, - string $contentType = self::contentTypes['previewSimpleOrder'][0] + $wait_to_confirm = SENTINEL_VALUE, + + string $contentType = self::contentTypes['placeOrder'][0] ) { - $_body = []; - $this->setRequestBodyProperty($_body, "instrument", $instrument); - $this->setRequestBodyProperty($_body, "side", $side); - $this->setRequestBodyProperty($_body, "type", $type); - $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); - $this->setRequestBodyProperty($_body, "amount", $amount); - $this->setRequestBodyProperty($_body, "limit_price", $limit_price); - $this->setRequestBodyProperty($_body, "stop_price", $stop_price); - $this->setRequestBodyProperty($_body, "post_only", $post_only); - $this->setRequestBodyProperty($_body, "expiration_date", $expiration_date); - $simple_order_form = $_body; + $_body = null; + $this->setRequestBodyProperty($_body, "wait_to_confirm", $wait_to_confirm); + $validated_trade_body = $_body; - return $this->previewSimpleOrderAsyncWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, $contentType) + return $this->placeOrderAsyncWithHttpInfo($trade_id, $user_id, $user_secret, $validated_trade_body, $contentType) ->then( function ($response) { return $response[0]; @@ -5206,25 +3768,25 @@ function ($response) { } /** - * Operation previewSimpleOrderAsyncWithHttpInfo + * Operation placeOrderAsyncWithHttpInfo * - * Preview order + * Place checked order * - * Previews an order using the specified account. + * Places the previously checked order with the brokerage. The `tradeId` is obtained from the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact). If you prefer to place the order without checking for impact first, you can use the [place order endpoint](/reference/Trading/Trading_placeForceOrder). It's recommended to trigger a manual refresh of the account after placing an order to ensure the account is up to date. You can use the [manual refresh](/reference/Connections/Connections_refreshBrokerageAuthorization) endpoint for this. * + * @param string $trade_id Obtained from calling the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact) (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['previewSimpleOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\ValidatedTradeBody $validated_trade_body (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function previewSimpleOrderAsyncWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, string $contentType = self::contentTypes['previewSimpleOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function placeOrderAsyncWithHttpInfo($trade_id, $user_id, $user_secret, $validated_trade_body = null, string $contentType = self::contentTypes['placeOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { - $returnType = '\SnapTrade\Model\SimpleOrderPreview'; - ["request" => $request, "serializedBody" => $serializedBody] = $this->previewSimpleOrderRequest($user_id, $user_secret, $account_id, $simple_order_form, $contentType); + $returnType = '\SnapTrade\Model\AccountOrderRecord'; + ["request" => $request, "serializedBody" => $serializedBody] = $this->placeOrderRequest($trade_id, $user_id, $user_secret, $validated_trade_body, $contentType); // Customization hook $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); @@ -5266,20 +3828,30 @@ function ($exception) { } /** - * Create request for operation 'previewSimpleOrder' + * Create request for operation 'placeOrder' * + * @param string $trade_id Obtained from calling the [check order impact endpoint](/reference/Trading/Trading_getOrderImpact) (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['previewSimpleOrder'] to see the possible values for this operation + * @param \SnapTrade\Model\ValidatedTradeBody $validated_trade_body (optional) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['placeOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ - public function previewSimpleOrderRequest($user_id, $user_secret, $account_id, $simple_order_form, string $contentType = self::contentTypes['previewSimpleOrder'][0]) + public function placeOrderRequest($trade_id, $user_id, $user_secret, $validated_trade_body = SENTINEL_VALUE, string $contentType = self::contentTypes['placeOrder'][0]) { + // Check if $trade_id is a string + if ($trade_id !== SENTINEL_VALUE && !is_string($trade_id)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($trade_id, true), gettype($trade_id))); + } + // verify the required parameter 'trade_id' is set + if ($trade_id === SENTINEL_VALUE || (is_array($trade_id) && count($trade_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter trade_id when calling placeOrder' + ); + } // Check if $user_id is a string if ($user_id !== SENTINEL_VALUE && !is_string($user_id)) { throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_id, true), gettype($user_id))); @@ -5287,46 +3859,30 @@ public function previewSimpleOrderRequest($user_id, $user_secret, $account_id, $ // verify the required parameter 'user_id' is set if ($user_id === SENTINEL_VALUE || (is_array($user_id) && count($user_id) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter user_id when calling previewSimpleOrder' - ); - } - // Check if $user_secret is a string - if ($user_secret !== SENTINEL_VALUE && !is_string($user_secret)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_secret, true), gettype($user_secret))); - } - // verify the required parameter 'user_secret' is set - if ($user_secret === SENTINEL_VALUE || (is_array($user_secret) && count($user_secret) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter user_secret when calling previewSimpleOrder' + 'Missing the required parameter user_id when calling placeOrder' ); } - // Check if $account_id is a string - if ($account_id !== SENTINEL_VALUE && !is_string($account_id)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($account_id, true), gettype($account_id))); + // Check if $user_secret is a string + if ($user_secret !== SENTINEL_VALUE && !is_string($user_secret)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_secret, true), gettype($user_secret))); } - // verify the required parameter 'account_id' is set - if ($account_id === SENTINEL_VALUE || (is_array($account_id) && count($account_id) === 0)) { + // verify the required parameter 'user_secret' is set + if ($user_secret === SENTINEL_VALUE || (is_array($user_secret) && count($user_secret) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter account_id when calling previewSimpleOrder' + 'Missing the required parameter user_secret when calling placeOrder' ); } - if ($simple_order_form !== SENTINEL_VALUE) { - if (!($simple_order_form instanceof \SnapTrade\Model\SimpleOrderForm)) { - if (!is_array($simple_order_form)) - throw new \InvalidArgumentException('"simple_order_form" must be associative array or an instance of \SnapTrade\Model\SimpleOrderForm TradingApi.previewSimpleOrder.'); + if ($validated_trade_body !== SENTINEL_VALUE) { + if (!($validated_trade_body instanceof \SnapTrade\Model\ValidatedTradeBody)) { + if (!is_array($validated_trade_body)) + throw new \InvalidArgumentException('"validated_trade_body" must be associative array or an instance of \SnapTrade\Model\ValidatedTradeBody TradingApi.placeOrder.'); else - $simple_order_form = new \SnapTrade\Model\SimpleOrderForm($simple_order_form); + $validated_trade_body = new \SnapTrade\Model\ValidatedTradeBody($validated_trade_body); } } - // verify the required parameter 'simple_order_form' is set - if ($simple_order_form === SENTINEL_VALUE || (is_array($simple_order_form) && count($simple_order_form) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter simple_order_form when calling previewSimpleOrder' - ); - } - $resourcePath = '/accounts/{accountId}/trading/simple/preview'; + $resourcePath = '/trade/{tradeId}'; $formParams = []; $queryParams = []; $headerParams = []; @@ -5358,10 +3914,10 @@ public function previewSimpleOrderRequest($user_id, $user_secret, $account_id, $ // path params - if ($account_id !== SENTINEL_VALUE) { + if ($trade_id !== SENTINEL_VALUE) { $resourcePath = str_replace( - '{' . 'accountId' . '}', - ObjectSerializer::toPathValue($account_id), + '{' . 'tradeId' . '}', + ObjectSerializer::toPathValue($trade_id), $resourcePath ); } @@ -5374,12 +3930,12 @@ public function previewSimpleOrderRequest($user_id, $user_secret, $account_id, $ ); // for model (json/xml) - if (isset($simple_order_form)) { + if (isset($validated_trade_body)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($simple_order_form)); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($validated_trade_body)); } else { - $httpBody = $simple_order_form; + $httpBody = $validated_trade_body; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -5449,74 +4005,75 @@ public function previewSimpleOrderRequest($user_id, $user_secret, $account_id, $ } /** - * Operation replaceOrder + * Operation previewSimpleOrder * - * Replaces an order with a new one + * Preview order * - * Replaces an existing pending order with a new one. The way this works is brokerage dependent, but usually involves cancelling the existing order and placing a new one. The order's brokerage_order_id may or may not change, be sure to use the one returned in the response going forward. Only supported on some brokerages + * Previews an order using the specified account. * - * @param string $account_id The ID of the account to execute the trade on. (required) - * @param string $brokerage_order_id The Brokerage Order ID of the order to replace. (required) * @param string $user_id user_id (required) * @param string $user_secret user_secret (required) - * @param \SnapTrade\Model\ManualTradeReplaceForm $manual_trade_replace_form manual_trade_replace_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['replaceOrder'] to see the possible values for this operation + * @param string $account_id account_id (required) + * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form simple_order_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['previewSimpleOrder'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse + * @return \SnapTrade\Model\SimpleOrderPreview|\SnapTrade\Model\Model400FailedRequestResponse */ - public function replaceOrder( + public function previewSimpleOrder( - $action, - $order_type, + $instrument, + $side, + $type, $time_in_force, - $account_id, - $brokerage_order_id, + $amount, $user_id, $user_secret, - $price = SENTINEL_VALUE, - $symbol = SENTINEL_VALUE, - $stop = SENTINEL_VALUE, - $units = SENTINEL_VALUE, - string $contentType = self::contentTypes['replaceOrder'][0] + $account_id, + $limit_price = SENTINEL_VALUE, + $stop_price = SENTINEL_VALUE, + $post_only = SENTINEL_VALUE, + $expiration_date = SENTINEL_VALUE, + string $contentType = self::contentTypes['previewSimpleOrder'][0] ) { $_body = []; - $this->setRequestBodyProperty($_body, "action", $action); - $this->setRequestBodyProperty($_body, "order_type", $order_type); + $this->setRequestBodyProperty($_body, "instrument", $instrument); + $this->setRequestBodyProperty($_body, "side", $side); + $this->setRequestBodyProperty($_body, "type", $type); $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); - $this->setRequestBodyProperty($_body, "price", $price); - $this->setRequestBodyProperty($_body, "symbol", $symbol); - $this->setRequestBodyProperty($_body, "stop", $stop); - $this->setRequestBodyProperty($_body, "units", $units); - $manual_trade_replace_form = $_body; + $this->setRequestBodyProperty($_body, "amount", $amount); + $this->setRequestBodyProperty($_body, "limit_price", $limit_price); + $this->setRequestBodyProperty($_body, "stop_price", $stop_price); + $this->setRequestBodyProperty($_body, "post_only", $post_only); + $this->setRequestBodyProperty($_body, "expiration_date", $expiration_date); + $simple_order_form = $_body; - list($response) = $this->replaceOrderWithHttpInfo($account_id, $brokerage_order_id, $user_id, $user_secret, $manual_trade_replace_form, $contentType); + list($response) = $this->previewSimpleOrderWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, $contentType); return $response; } /** - * Operation replaceOrderWithHttpInfo + * Operation previewSimpleOrderWithHttpInfo * - * Replaces an order with a new one + * Preview order * - * Replaces an existing pending order with a new one. The way this works is brokerage dependent, but usually involves cancelling the existing order and placing a new one. The order's brokerage_order_id may or may not change, be sure to use the one returned in the response going forward. Only supported on some brokerages + * Previews an order using the specified account. * - * @param string $account_id The ID of the account to execute the trade on. (required) - * @param string $brokerage_order_id The Brokerage Order ID of the order to replace. (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeReplaceForm $manual_trade_replace_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['replaceOrder'] to see the possible values for this operation + * @param string $account_id (required) + * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['previewSimpleOrder'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return array of \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) + * @return array of \SnapTrade\Model\SimpleOrderPreview|\SnapTrade\Model\Model400FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) */ - public function replaceOrderWithHttpInfo($account_id, $brokerage_order_id, $user_id, $user_secret, $manual_trade_replace_form, string $contentType = self::contentTypes['replaceOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function previewSimpleOrderWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, string $contentType = self::contentTypes['previewSimpleOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { - ["request" => $request, "serializedBody" => $serializedBody] = $this->replaceOrderRequest($account_id, $brokerage_order_id, $user_id, $user_secret, $manual_trade_replace_form, $contentType); + ["request" => $request, "serializedBody" => $serializedBody] = $this->previewSimpleOrderRequest($user_id, $user_secret, $account_id, $simple_order_form, $contentType); // Customization hook $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); @@ -5531,12 +4088,11 @@ public function replaceOrderWithHttpInfo($account_id, $brokerage_order_id, $user !empty($this->getConfig()->getAccessToken()) && $requestOptions->shouldRetryOAuth() ) { - return $this->replaceOrderWithHttpInfo( - $account_id, - $brokerage_order_id, + return $this->previewSimpleOrderWithHttpInfo( $user_id, $user_secret, - $manual_trade_replace_form, + $account_id, + $simple_order_form, $contentType, $requestOptions->setRetryOAuth(false) ); @@ -5574,17 +4130,17 @@ public function replaceOrderWithHttpInfo($account_id, $brokerage_order_id, $user switch($statusCode) { case 200: - if ('\SnapTrade\Model\AccountOrderRecord' === '\SplFileObject') { + if ('\SnapTrade\Model\SimpleOrderPreview' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); - if ('\SnapTrade\Model\AccountOrderRecord' !== 'string') { + if ('\SnapTrade\Model\SimpleOrderPreview' !== 'string') { $content = json_decode($content); } } return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\AccountOrderRecord', []), + ObjectSerializer::deserialize($content, '\SnapTrade\Model\SimpleOrderPreview', []), $response->getStatusCode(), $response->getHeaders() ]; @@ -5603,24 +4159,9 @@ public function replaceOrderWithHttpInfo($account_id, $brokerage_order_id, $user $response->getStatusCode(), $response->getHeaders() ]; - case 403: - if ('\SnapTrade\Model\Model403FailedRequestResponse' === '\SplFileObject') { - $content = $response->getBody(); //stream goes to serializer - } else { - $content = (string) $response->getBody(); - if ('\SnapTrade\Model\Model403FailedRequestResponse' !== 'string') { - $content = json_decode($content); - } - } - - return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model403FailedRequestResponse', []), - $response->getStatusCode(), - $response->getHeaders() - ]; } - $returnType = '\SnapTrade\Model\AccountOrderRecord'; + $returnType = '\SnapTrade\Model\SimpleOrderPreview'; if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { @@ -5641,7 +4182,7 @@ public function replaceOrderWithHttpInfo($account_id, $brokerage_order_id, $user case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), - '\SnapTrade\Model\AccountOrderRecord', + '\SnapTrade\Model\SimpleOrderPreview', $e->getResponseHeaders() ); $e->setResponseObject($data); @@ -5654,63 +4195,57 @@ public function replaceOrderWithHttpInfo($account_id, $brokerage_order_id, $user ); $e->setResponseObject($data); break; - case 403: - $data = ObjectSerializer::deserialize( - $e->getResponseBody(), - '\SnapTrade\Model\Model403FailedRequestResponse', - $e->getResponseHeaders() - ); - $e->setResponseObject($data); - break; } throw $e; } } /** - * Operation replaceOrderAsync + * Operation previewSimpleOrderAsync * - * Replaces an order with a new one + * Preview order * - * Replaces an existing pending order with a new one. The way this works is brokerage dependent, but usually involves cancelling the existing order and placing a new one. The order's brokerage_order_id may or may not change, be sure to use the one returned in the response going forward. Only supported on some brokerages + * Previews an order using the specified account. * - * @param string $account_id The ID of the account to execute the trade on. (required) - * @param string $brokerage_order_id The Brokerage Order ID of the order to replace. (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeReplaceForm $manual_trade_replace_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['replaceOrder'] to see the possible values for this operation + * @param string $account_id (required) + * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['previewSimpleOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function replaceOrderAsync( + public function previewSimpleOrderAsync( - $action, - $order_type, + $instrument, + $side, + $type, $time_in_force, - $account_id, - $brokerage_order_id, + $amount, $user_id, $user_secret, - $price = SENTINEL_VALUE, - $symbol = SENTINEL_VALUE, - $stop = SENTINEL_VALUE, - $units = SENTINEL_VALUE, - string $contentType = self::contentTypes['replaceOrder'][0] + $account_id, + $limit_price = SENTINEL_VALUE, + $stop_price = SENTINEL_VALUE, + $post_only = SENTINEL_VALUE, + $expiration_date = SENTINEL_VALUE, + string $contentType = self::contentTypes['previewSimpleOrder'][0] ) { $_body = []; - $this->setRequestBodyProperty($_body, "action", $action); - $this->setRequestBodyProperty($_body, "order_type", $order_type); + $this->setRequestBodyProperty($_body, "instrument", $instrument); + $this->setRequestBodyProperty($_body, "side", $side); + $this->setRequestBodyProperty($_body, "type", $type); $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); - $this->setRequestBodyProperty($_body, "price", $price); - $this->setRequestBodyProperty($_body, "symbol", $symbol); - $this->setRequestBodyProperty($_body, "stop", $stop); - $this->setRequestBodyProperty($_body, "units", $units); - $manual_trade_replace_form = $_body; + $this->setRequestBodyProperty($_body, "amount", $amount); + $this->setRequestBodyProperty($_body, "limit_price", $limit_price); + $this->setRequestBodyProperty($_body, "stop_price", $stop_price); + $this->setRequestBodyProperty($_body, "post_only", $post_only); + $this->setRequestBodyProperty($_body, "expiration_date", $expiration_date); + $simple_order_form = $_body; - return $this->replaceOrderAsyncWithHttpInfo($account_id, $brokerage_order_id, $user_id, $user_secret, $manual_trade_replace_form, $contentType) + return $this->previewSimpleOrderAsyncWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, $contentType) ->then( function ($response) { return $response[0]; @@ -5719,26 +4254,25 @@ function ($response) { } /** - * Operation replaceOrderAsyncWithHttpInfo + * Operation previewSimpleOrderAsyncWithHttpInfo * - * Replaces an order with a new one + * Preview order * - * Replaces an existing pending order with a new one. The way this works is brokerage dependent, but usually involves cancelling the existing order and placing a new one. The order's brokerage_order_id may or may not change, be sure to use the one returned in the response going forward. Only supported on some brokerages + * Previews an order using the specified account. * - * @param string $account_id The ID of the account to execute the trade on. (required) - * @param string $brokerage_order_id The Brokerage Order ID of the order to replace. (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeReplaceForm $manual_trade_replace_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['replaceOrder'] to see the possible values for this operation + * @param string $account_id (required) + * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['previewSimpleOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function replaceOrderAsyncWithHttpInfo($account_id, $brokerage_order_id, $user_id, $user_secret, $manual_trade_replace_form, string $contentType = self::contentTypes['replaceOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function previewSimpleOrderAsyncWithHttpInfo($user_id, $user_secret, $account_id, $simple_order_form, string $contentType = self::contentTypes['previewSimpleOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { - $returnType = '\SnapTrade\Model\AccountOrderRecord'; - ["request" => $request, "serializedBody" => $serializedBody] = $this->replaceOrderRequest($account_id, $brokerage_order_id, $user_id, $user_secret, $manual_trade_replace_form, $contentType); + $returnType = '\SnapTrade\Model\SimpleOrderPreview'; + ["request" => $request, "serializedBody" => $serializedBody] = $this->previewSimpleOrderRequest($user_id, $user_secret, $account_id, $simple_order_form, $contentType); // Customization hook $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); @@ -5780,41 +4314,20 @@ function ($exception) { } /** - * Create request for operation 'replaceOrder' + * Create request for operation 'previewSimpleOrder' * - * @param string $account_id The ID of the account to execute the trade on. (required) - * @param string $brokerage_order_id The Brokerage Order ID of the order to replace. (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param \SnapTrade\Model\ManualTradeReplaceForm $manual_trade_replace_form (required) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['replaceOrder'] to see the possible values for this operation + * @param string $account_id (required) + * @param \SnapTrade\Model\SimpleOrderForm $simple_order_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['previewSimpleOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ - public function replaceOrderRequest($account_id, $brokerage_order_id, $user_id, $user_secret, $manual_trade_replace_form, string $contentType = self::contentTypes['replaceOrder'][0]) - { - - // Check if $account_id is a string - if ($account_id !== SENTINEL_VALUE && !is_string($account_id)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($account_id, true), gettype($account_id))); - } - // verify the required parameter 'account_id' is set - if ($account_id === SENTINEL_VALUE || (is_array($account_id) && count($account_id) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter account_id when calling replaceOrder' - ); - } - // Check if $brokerage_order_id is a string - if ($brokerage_order_id !== SENTINEL_VALUE && !is_string($brokerage_order_id)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($brokerage_order_id, true), gettype($brokerage_order_id))); - } - // verify the required parameter 'brokerage_order_id' is set - if ($brokerage_order_id === SENTINEL_VALUE || (is_array($brokerage_order_id) && count($brokerage_order_id) === 0)) { - throw new \InvalidArgumentException( - 'Missing the required parameter brokerage_order_id when calling replaceOrder' - ); - } + public function previewSimpleOrderRequest($user_id, $user_secret, $account_id, $simple_order_form, string $contentType = self::contentTypes['previewSimpleOrder'][0]) + { + // Check if $user_id is a string if ($user_id !== SENTINEL_VALUE && !is_string($user_id)) { throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_id, true), gettype($user_id))); @@ -5822,7 +4335,7 @@ public function replaceOrderRequest($account_id, $brokerage_order_id, $user_id, // verify the required parameter 'user_id' is set if ($user_id === SENTINEL_VALUE || (is_array($user_id) && count($user_id) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter user_id when calling replaceOrder' + 'Missing the required parameter user_id when calling previewSimpleOrder' ); } // Check if $user_secret is a string @@ -5832,26 +4345,36 @@ public function replaceOrderRequest($account_id, $brokerage_order_id, $user_id, // verify the required parameter 'user_secret' is set if ($user_secret === SENTINEL_VALUE || (is_array($user_secret) && count($user_secret) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter user_secret when calling replaceOrder' + 'Missing the required parameter user_secret when calling previewSimpleOrder' ); } - if ($manual_trade_replace_form !== SENTINEL_VALUE) { - if (!($manual_trade_replace_form instanceof \SnapTrade\Model\ManualTradeReplaceForm)) { - if (!is_array($manual_trade_replace_form)) - throw new \InvalidArgumentException('"manual_trade_replace_form" must be associative array or an instance of \SnapTrade\Model\ManualTradeReplaceForm TradingApi.replaceOrder.'); + // Check if $account_id is a string + if ($account_id !== SENTINEL_VALUE && !is_string($account_id)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($account_id, true), gettype($account_id))); + } + // verify the required parameter 'account_id' is set + if ($account_id === SENTINEL_VALUE || (is_array($account_id) && count($account_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter account_id when calling previewSimpleOrder' + ); + } + if ($simple_order_form !== SENTINEL_VALUE) { + if (!($simple_order_form instanceof \SnapTrade\Model\SimpleOrderForm)) { + if (!is_array($simple_order_form)) + throw new \InvalidArgumentException('"simple_order_form" must be associative array or an instance of \SnapTrade\Model\SimpleOrderForm TradingApi.previewSimpleOrder.'); else - $manual_trade_replace_form = new \SnapTrade\Model\ManualTradeReplaceForm($manual_trade_replace_form); + $simple_order_form = new \SnapTrade\Model\SimpleOrderForm($simple_order_form); } } - // verify the required parameter 'manual_trade_replace_form' is set - if ($manual_trade_replace_form === SENTINEL_VALUE || (is_array($manual_trade_replace_form) && count($manual_trade_replace_form) === 0)) { + // verify the required parameter 'simple_order_form' is set + if ($simple_order_form === SENTINEL_VALUE || (is_array($simple_order_form) && count($simple_order_form) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter manual_trade_replace_form when calling replaceOrder' + 'Missing the required parameter simple_order_form when calling previewSimpleOrder' ); } - $resourcePath = '/accounts/{accountId}/trading/simple/{brokerageOrderId}/replace'; + $resourcePath = '/accounts/{accountId}/trading/simple/preview'; $formParams = []; $queryParams = []; $headerParams = []; @@ -5890,14 +4413,6 @@ public function replaceOrderRequest($account_id, $brokerage_order_id, $user_id, $resourcePath ); } - // path params - if ($brokerage_order_id !== SENTINEL_VALUE) { - $resourcePath = str_replace( - '{' . 'brokerageOrderId' . '}', - ObjectSerializer::toPathValue($brokerage_order_id), - $resourcePath - ); - } $headers = $this->headerSelector->selectHeaders( @@ -5907,12 +4422,12 @@ public function replaceOrderRequest($account_id, $brokerage_order_id, $user_id, ); // for model (json/xml) - if (isset($manual_trade_replace_form)) { + if (isset($simple_order_form)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($manual_trade_replace_form)); + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($simple_order_form)); } else { - $httpBody = $manual_trade_replace_form; + $httpBody = $simple_order_form; } } elseif (count($formParams) > 0) { if ($multipart) { @@ -5965,7 +4480,7 @@ public function replaceOrderRequest($account_id, $brokerage_order_id, $user_id, $headers ); - $method = 'PATCH'; + $method = 'POST'; $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody); $operationHost = $this->config->getHost(); @@ -5982,62 +4497,77 @@ public function replaceOrderRequest($account_id, $brokerage_order_id, $user_id, } /** - * Operation searchCryptocurrencyPairInstruments + * Operation replaceOrder * - * Search cryptocurrency pairs instruments + * Replaces an order with a new one * - * Searches cryptocurrency pairs instruments accessible to the specified account. + * Replaces an existing pending order with a new one. The way this works is brokerage dependent, but usually involves cancelling the existing order and placing a new one. The order's brokerage_order_id may or may not change, be sure to use the one returned in the response going forward. Only supported on some brokerages * + * @param string $account_id The ID of the account to execute the trade on. (required) + * @param string $brokerage_order_id The Brokerage Order ID of the order to replace. (required) * @param string $user_id user_id (required) * @param string $user_secret user_secret (required) - * @param string $account_id account_id (required) - * @param string $base base (optional) - * @param string $quote quote (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['searchCryptocurrencyPairInstruments'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeReplaceForm $manual_trade_replace_form manual_trade_replace_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['replaceOrder'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return \SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response|\SnapTrade\Model\Model400FailedRequestResponse + * @return \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse */ - public function searchCryptocurrencyPairInstruments( + public function replaceOrder( + + $action, + $order_type, + $time_in_force, + $account_id, + $brokerage_order_id, $user_id, $user_secret, - $account_id, - $base = SENTINEL_VALUE, - $quote = SENTINEL_VALUE, - - string $contentType = self::contentTypes['searchCryptocurrencyPairInstruments'][0] + $price = SENTINEL_VALUE, + $symbol = SENTINEL_VALUE, + $stop = SENTINEL_VALUE, + $units = SENTINEL_VALUE, + string $contentType = self::contentTypes['replaceOrder'][0] ) { + $_body = []; + $this->setRequestBodyProperty($_body, "action", $action); + $this->setRequestBodyProperty($_body, "order_type", $order_type); + $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); + $this->setRequestBodyProperty($_body, "price", $price); + $this->setRequestBodyProperty($_body, "symbol", $symbol); + $this->setRequestBodyProperty($_body, "stop", $stop); + $this->setRequestBodyProperty($_body, "units", $units); + $manual_trade_replace_form = $_body; - list($response) = $this->searchCryptocurrencyPairInstrumentsWithHttpInfo($user_id, $user_secret, $account_id, $base, $quote, $contentType); + list($response) = $this->replaceOrderWithHttpInfo($account_id, $brokerage_order_id, $user_id, $user_secret, $manual_trade_replace_form, $contentType); return $response; } /** - * Operation searchCryptocurrencyPairInstrumentsWithHttpInfo + * Operation replaceOrderWithHttpInfo * - * Search cryptocurrency pairs instruments + * Replaces an order with a new one * - * Searches cryptocurrency pairs instruments accessible to the specified account. + * Replaces an existing pending order with a new one. The way this works is brokerage dependent, but usually involves cancelling the existing order and placing a new one. The order's brokerage_order_id may or may not change, be sure to use the one returned in the response going forward. Only supported on some brokerages * + * @param string $account_id The ID of the account to execute the trade on. (required) + * @param string $brokerage_order_id The Brokerage Order ID of the order to replace. (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param string $base (optional) - * @param string $quote (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['searchCryptocurrencyPairInstruments'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeReplaceForm $manual_trade_replace_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['replaceOrder'] to see the possible values for this operation * * @throws \SnapTrade\ApiException on non-2xx response * @throws \InvalidArgumentException - * @return array of \SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response|\SnapTrade\Model\Model400FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) + * @return array of \SnapTrade\Model\AccountOrderRecord|\SnapTrade\Model\Model400FailedRequestResponse|\SnapTrade\Model\Model403FailedRequestResponse, HTTP status code, HTTP response headers (array of strings) */ - public function searchCryptocurrencyPairInstrumentsWithHttpInfo($user_id, $user_secret, $account_id, $base = null, $quote = null, string $contentType = self::contentTypes['searchCryptocurrencyPairInstruments'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function replaceOrderWithHttpInfo($account_id, $brokerage_order_id, $user_id, $user_secret, $manual_trade_replace_form, string $contentType = self::contentTypes['replaceOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { - ["request" => $request, "serializedBody" => $serializedBody] = $this->searchCryptocurrencyPairInstrumentsRequest($user_id, $user_secret, $account_id, $base, $quote, $contentType); + ["request" => $request, "serializedBody" => $serializedBody] = $this->replaceOrderRequest($account_id, $brokerage_order_id, $user_id, $user_secret, $manual_trade_replace_form, $contentType); // Customization hook - $this->beforeSendHook($request, $requestOptions, $this->config); + $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); try { $options = $this->createHttpClientOption(); @@ -6049,12 +4579,12 @@ public function searchCryptocurrencyPairInstrumentsWithHttpInfo($user_id, $user_ !empty($this->getConfig()->getAccessToken()) && $requestOptions->shouldRetryOAuth() ) { - return $this->searchCryptocurrencyPairInstrumentsWithHttpInfo( + return $this->replaceOrderWithHttpInfo( + $account_id, + $brokerage_order_id, $user_id, $user_secret, - $account_id, - $base, - $quote, + $manual_trade_replace_form, $contentType, $requestOptions->setRetryOAuth(false) ); @@ -6092,17 +4622,17 @@ public function searchCryptocurrencyPairInstrumentsWithHttpInfo($user_id, $user_ switch($statusCode) { case 200: - if ('\SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response' === '\SplFileObject') { + if ('\SnapTrade\Model\AccountOrderRecord' === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); - if ('\SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response' !== 'string') { + if ('\SnapTrade\Model\AccountOrderRecord' !== 'string') { $content = json_decode($content); } } return [ - ObjectSerializer::deserialize($content, '\SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response', []), + ObjectSerializer::deserialize($content, '\SnapTrade\Model\AccountOrderRecord', []), $response->getStatusCode(), $response->getHeaders() ]; @@ -6121,9 +4651,24 @@ public function searchCryptocurrencyPairInstrumentsWithHttpInfo($user_id, $user_ $response->getStatusCode(), $response->getHeaders() ]; + case 403: + if ('\SnapTrade\Model\Model403FailedRequestResponse' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ('\SnapTrade\Model\Model403FailedRequestResponse' !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, '\SnapTrade\Model\Model403FailedRequestResponse', []), + $response->getStatusCode(), + $response->getHeaders() + ]; } - $returnType = '\SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response'; + $returnType = '\SnapTrade\Model\AccountOrderRecord'; if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { @@ -6144,7 +4689,7 @@ public function searchCryptocurrencyPairInstrumentsWithHttpInfo($user_id, $user_ case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), - '\SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response', + '\SnapTrade\Model\AccountOrderRecord', $e->getResponseHeaders() ); $e->setResponseObject($data); @@ -6157,40 +4702,63 @@ public function searchCryptocurrencyPairInstrumentsWithHttpInfo($user_id, $user_ ); $e->setResponseObject($data); break; + case 403: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\SnapTrade\Model\Model403FailedRequestResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; } throw $e; } } /** - * Operation searchCryptocurrencyPairInstrumentsAsync + * Operation replaceOrderAsync * - * Search cryptocurrency pairs instruments + * Replaces an order with a new one * - * Searches cryptocurrency pairs instruments accessible to the specified account. + * Replaces an existing pending order with a new one. The way this works is brokerage dependent, but usually involves cancelling the existing order and placing a new one. The order's brokerage_order_id may or may not change, be sure to use the one returned in the response going forward. Only supported on some brokerages * + * @param string $account_id The ID of the account to execute the trade on. (required) + * @param string $brokerage_order_id The Brokerage Order ID of the order to replace. (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param string $base (optional) - * @param string $quote (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['searchCryptocurrencyPairInstruments'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeReplaceForm $manual_trade_replace_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['replaceOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function searchCryptocurrencyPairInstrumentsAsync( + public function replaceOrderAsync( + + $action, + $order_type, + $time_in_force, + $account_id, + $brokerage_order_id, $user_id, $user_secret, - $account_id, - $base = SENTINEL_VALUE, - $quote = SENTINEL_VALUE, - - string $contentType = self::contentTypes['searchCryptocurrencyPairInstruments'][0] + $price = SENTINEL_VALUE, + $symbol = SENTINEL_VALUE, + $stop = SENTINEL_VALUE, + $units = SENTINEL_VALUE, + string $contentType = self::contentTypes['replaceOrder'][0] ) { + $_body = []; + $this->setRequestBodyProperty($_body, "action", $action); + $this->setRequestBodyProperty($_body, "order_type", $order_type); + $this->setRequestBodyProperty($_body, "time_in_force", $time_in_force); + $this->setRequestBodyProperty($_body, "price", $price); + $this->setRequestBodyProperty($_body, "symbol", $symbol); + $this->setRequestBodyProperty($_body, "stop", $stop); + $this->setRequestBodyProperty($_body, "units", $units); + $manual_trade_replace_form = $_body; - return $this->searchCryptocurrencyPairInstrumentsAsyncWithHttpInfo($user_id, $user_secret, $account_id, $base, $quote, $contentType) + return $this->replaceOrderAsyncWithHttpInfo($account_id, $brokerage_order_id, $user_id, $user_secret, $manual_trade_replace_form, $contentType) ->then( function ($response) { return $response[0]; @@ -6199,29 +4767,29 @@ function ($response) { } /** - * Operation searchCryptocurrencyPairInstrumentsAsyncWithHttpInfo + * Operation replaceOrderAsyncWithHttpInfo * - * Search cryptocurrency pairs instruments + * Replaces an order with a new one * - * Searches cryptocurrency pairs instruments accessible to the specified account. + * Replaces an existing pending order with a new one. The way this works is brokerage dependent, but usually involves cancelling the existing order and placing a new one. The order's brokerage_order_id may or may not change, be sure to use the one returned in the response going forward. Only supported on some brokerages * + * @param string $account_id The ID of the account to execute the trade on. (required) + * @param string $brokerage_order_id The Brokerage Order ID of the order to replace. (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param string $base (optional) - * @param string $quote (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['searchCryptocurrencyPairInstruments'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeReplaceForm $manual_trade_replace_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['replaceOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ - public function searchCryptocurrencyPairInstrumentsAsyncWithHttpInfo($user_id, $user_secret, $account_id, $base = null, $quote = null, string $contentType = self::contentTypes['searchCryptocurrencyPairInstruments'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) + public function replaceOrderAsyncWithHttpInfo($account_id, $brokerage_order_id, $user_id, $user_secret, $manual_trade_replace_form, string $contentType = self::contentTypes['replaceOrder'][0], \SnapTrade\RequestOptions $requestOptions = new \SnapTrade\RequestOptions()) { - $returnType = '\SnapTrade\Model\TradingSearchCryptocurrencyPairInstruments200Response'; - ["request" => $request, "serializedBody" => $serializedBody] = $this->searchCryptocurrencyPairInstrumentsRequest($user_id, $user_secret, $account_id, $base, $quote, $contentType); + $returnType = '\SnapTrade\Model\AccountOrderRecord'; + ["request" => $request, "serializedBody" => $serializedBody] = $this->replaceOrderRequest($account_id, $brokerage_order_id, $user_id, $user_secret, $manual_trade_replace_form, $contentType); // Customization hook - $this->beforeSendHook($request, $requestOptions, $this->config); + $this->beforeSendHook($request, $requestOptions, $this->config, $serializedBody); return $this->client ->sendAsync($request, $this->createHttpClientOption()) @@ -6260,21 +4828,41 @@ function ($exception) { } /** - * Create request for operation 'searchCryptocurrencyPairInstruments' + * Create request for operation 'replaceOrder' * + * @param string $account_id The ID of the account to execute the trade on. (required) + * @param string $brokerage_order_id The Brokerage Order ID of the order to replace. (required) * @param string $user_id (required) * @param string $user_secret (required) - * @param string $account_id (required) - * @param string $base (optional) - * @param string $quote (optional) - * @param string $contentType The value for the Content-Type header. Check self::contentTypes['searchCryptocurrencyPairInstruments'] to see the possible values for this operation + * @param \SnapTrade\Model\ManualTradeReplaceForm $manual_trade_replace_form (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['replaceOrder'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ - public function searchCryptocurrencyPairInstrumentsRequest($user_id, $user_secret, $account_id, $base = SENTINEL_VALUE, $quote = SENTINEL_VALUE, string $contentType = self::contentTypes['searchCryptocurrencyPairInstruments'][0]) + public function replaceOrderRequest($account_id, $brokerage_order_id, $user_id, $user_secret, $manual_trade_replace_form, string $contentType = self::contentTypes['replaceOrder'][0]) { + // Check if $account_id is a string + if ($account_id !== SENTINEL_VALUE && !is_string($account_id)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($account_id, true), gettype($account_id))); + } + // verify the required parameter 'account_id' is set + if ($account_id === SENTINEL_VALUE || (is_array($account_id) && count($account_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter account_id when calling replaceOrder' + ); + } + // Check if $brokerage_order_id is a string + if ($brokerage_order_id !== SENTINEL_VALUE && !is_string($brokerage_order_id)) { + throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($brokerage_order_id, true), gettype($brokerage_order_id))); + } + // verify the required parameter 'brokerage_order_id' is set + if ($brokerage_order_id === SENTINEL_VALUE || (is_array($brokerage_order_id) && count($brokerage_order_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter brokerage_order_id when calling replaceOrder' + ); + } // Check if $user_id is a string if ($user_id !== SENTINEL_VALUE && !is_string($user_id)) { throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($user_id, true), gettype($user_id))); @@ -6282,7 +4870,7 @@ public function searchCryptocurrencyPairInstrumentsRequest($user_id, $user_secre // verify the required parameter 'user_id' is set if ($user_id === SENTINEL_VALUE || (is_array($user_id) && count($user_id) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter user_id when calling searchCryptocurrencyPairInstruments' + 'Missing the required parameter user_id when calling replaceOrder' ); } // Check if $user_secret is a string @@ -6292,30 +4880,26 @@ public function searchCryptocurrencyPairInstrumentsRequest($user_id, $user_secre // verify the required parameter 'user_secret' is set if ($user_secret === SENTINEL_VALUE || (is_array($user_secret) && count($user_secret) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter user_secret when calling searchCryptocurrencyPairInstruments' + 'Missing the required parameter user_secret when calling replaceOrder' ); } - // Check if $account_id is a string - if ($account_id !== SENTINEL_VALUE && !is_string($account_id)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($account_id, true), gettype($account_id))); + if ($manual_trade_replace_form !== SENTINEL_VALUE) { + if (!($manual_trade_replace_form instanceof \SnapTrade\Model\ManualTradeReplaceForm)) { + if (!is_array($manual_trade_replace_form)) + throw new \InvalidArgumentException('"manual_trade_replace_form" must be associative array or an instance of \SnapTrade\Model\ManualTradeReplaceForm TradingApi.replaceOrder.'); + else + $manual_trade_replace_form = new \SnapTrade\Model\ManualTradeReplaceForm($manual_trade_replace_form); + } } - // verify the required parameter 'account_id' is set - if ($account_id === SENTINEL_VALUE || (is_array($account_id) && count($account_id) === 0)) { + // verify the required parameter 'manual_trade_replace_form' is set + if ($manual_trade_replace_form === SENTINEL_VALUE || (is_array($manual_trade_replace_form) && count($manual_trade_replace_form) === 0)) { throw new \InvalidArgumentException( - 'Missing the required parameter account_id when calling searchCryptocurrencyPairInstruments' + 'Missing the required parameter manual_trade_replace_form when calling replaceOrder' ); } - // Check if $base is a string - if ($base !== SENTINEL_VALUE && !is_string($base)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($base, true), gettype($base))); - } - // Check if $quote is a string - if ($quote !== SENTINEL_VALUE && !is_string($quote)) { - throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($quote, true), gettype($quote))); - } - $resourcePath = '/accounts/{accountId}/trading/instruments/cryptocurrencyPairs'; + $resourcePath = '/accounts/{accountId}/trading/simple/{brokerageOrderId}/replace'; $formParams = []; $queryParams = []; $headerParams = []; @@ -6344,28 +4928,6 @@ public function searchCryptocurrencyPairInstrumentsRequest($user_id, $user_secre true // required ) ?? []); } - if ($base !== SENTINEL_VALUE) { - // query params - $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( - $base, - 'base', // param base name - 'string', // openApiType - 'form', // style - true, // explode - false // required - ) ?? []); - } - if ($quote !== SENTINEL_VALUE) { - // query params - $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue( - $quote, - 'quote', // param base name - 'string', // openApiType - 'form', // style - true, // explode - false // required - ) ?? []); - } // path params @@ -6376,6 +4938,14 @@ public function searchCryptocurrencyPairInstrumentsRequest($user_id, $user_secre $resourcePath ); } + // path params + if ($brokerage_order_id !== SENTINEL_VALUE) { + $resourcePath = str_replace( + '{' . 'brokerageOrderId' . '}', + ObjectSerializer::toPathValue($brokerage_order_id), + $resourcePath + ); + } $headers = $this->headerSelector->selectHeaders( @@ -6385,7 +4955,14 @@ public function searchCryptocurrencyPairInstrumentsRequest($user_id, $user_secre ); // for model (json/xml) - if (count($formParams) > 0) { + if (isset($manual_trade_replace_form)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($manual_trade_replace_form)); + } else { + $httpBody = $manual_trade_replace_form; + } + } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { @@ -6436,7 +5013,7 @@ public function searchCryptocurrencyPairInstrumentsRequest($user_id, $user_secre $headers ); - $method = 'GET'; + $method = 'PATCH'; $this->beforeCreateRequestHook($method, $resourcePath, $queryParams, $headers, $httpBody); $operationHost = $this->config->getHost(); diff --git a/lib/Client.php b/lib/Client.php index b8de060..bf70220 100644 --- a/lib/Client.php +++ b/lib/Client.php @@ -13,6 +13,8 @@ class Client public readonly \SnapTrade\Api\ConnectionsApi $connections; + public readonly \SnapTrade\Api\CryptoTradingApi $cryptoTrading; + public readonly \SnapTrade\Api\OptionsApi $options; public readonly \SnapTrade\Api\ReferenceDataApi $referenceData; @@ -48,6 +50,7 @@ public function __construct( $this->apiStatus = new \SnapTrade\Api\ApiStatusApi($config); $this->authentication = new \SnapTrade\Api\AuthenticationApi($config); $this->connections = new \SnapTrade\Api\ConnectionsApi($config); + $this->cryptoTrading = new \SnapTrade\Api\CryptoTradingApi($config); $this->options = new \SnapTrade\Api\OptionsApi($config); $this->referenceData = new \SnapTrade\Api\ReferenceDataApi($config); $this->trading = new \SnapTrade\Api\TradingApi($config); diff --git a/test/Api/CryptoTradingApiTest.php b/test/Api/CryptoTradingApiTest.php new file mode 100644 index 0000000..84de60b --- /dev/null +++ b/test/Api/CryptoTradingApiTest.php @@ -0,0 +1,96 @@ +markTestIncomplete('Not implemented'); + } + + /** + * Test case for placeSimpleOrder + * + * Place order v2. + * + */ + public function testPlaceSimpleOrder() + { + // TODO: implement + $this->markTestIncomplete('Not implemented'); + } + + /** + * Test case for searchCryptocurrencyPairInstruments + * + * Search cryptocurrency pairs instruments. + * + */ + public function testSearchCryptocurrencyPairInstruments() + { + // TODO: implement + $this->markTestIncomplete('Not implemented'); + } +} diff --git a/test/Api/TradingApiTest.php b/test/Api/TradingApiTest.php index add1d24..1444f5c 100644 --- a/test/Api/TradingApiTest.php +++ b/test/Api/TradingApiTest.php @@ -82,18 +82,6 @@ public function testCancelUserAccountOrder() $this->markTestIncomplete('Not implemented'); } - /** - * Test case for getCryptocurrencyPairQuote - * - * Get cryptocurrency pair quote. - * - */ - public function testGetCryptocurrencyPairQuote() - { - // TODO: implement - $this->markTestIncomplete('Not implemented'); - } - /** * Test case for getOrderImpact * @@ -166,18 +154,6 @@ public function testPlaceOrder() $this->markTestIncomplete('Not implemented'); } - /** - * Test case for placeSimpleOrder - * - * Place order. - * - */ - public function testPlaceSimpleOrder() - { - // TODO: implement - $this->markTestIncomplete('Not implemented'); - } - /** * Test case for previewSimpleOrder * @@ -201,16 +177,4 @@ public function testReplaceOrder() // TODO: implement $this->markTestIncomplete('Not implemented'); } - - /** - * Test case for searchCryptocurrencyPairInstruments - * - * Search cryptocurrency pairs instruments. - * - */ - public function testSearchCryptocurrencyPairInstruments() - { - // TODO: implement - $this->markTestIncomplete('Not implemented'); - } } From ce235c94bc102471a825f0bb8b21733822100a4e Mon Sep 17 00:00:00 2001 From: Passiv Ops Date: Fri, 20 Jun 2025 20:03:07 +0000 Subject: [PATCH 2/5] Regenerate SDKs --- .konfig/generate-id.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.konfig/generate-id.txt b/.konfig/generate-id.txt index dfbccd3..355cf3e 100644 --- a/.konfig/generate-id.txt +++ b/.konfig/generate-id.txt @@ -1 +1 @@ -1dc41628-32db-4ae6-8a20-5b80ee3d317e \ No newline at end of file +d2b8c1f0-d342-4f18-ab56-0b7c526f84cc \ No newline at end of file From 954e8cdbeff5ef5734721f2e1deb08e66f37b3bb Mon Sep 17 00:00:00 2001 From: Passiv Ops Date: Mon, 23 Jun 2025 18:40:13 +0000 Subject: [PATCH 3/5] Regenerate SDKs --- .konfig/generate-id.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.konfig/generate-id.txt b/.konfig/generate-id.txt index 355cf3e..7836f89 100644 --- a/.konfig/generate-id.txt +++ b/.konfig/generate-id.txt @@ -1 +1 @@ -d2b8c1f0-d342-4f18-ab56-0b7c526f84cc \ No newline at end of file +d62d8d5b-4692-4cd7-aa3e-038c7a279e8d \ No newline at end of file From b76387e833aec118dafb1e8ebeed2e08e3c38215 Mon Sep 17 00:00:00 2001 From: Passiv Ops Date: Mon, 23 Jun 2025 19:32:11 +0000 Subject: [PATCH 4/5] Regenerate SDKs --- .konfig/generate-id.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.konfig/generate-id.txt b/.konfig/generate-id.txt index 7836f89..f5bb96b 100644 --- a/.konfig/generate-id.txt +++ b/.konfig/generate-id.txt @@ -1 +1 @@ -d62d8d5b-4692-4cd7-aa3e-038c7a279e8d \ No newline at end of file +08a23feb-95ed-4cd8-81fb-fb2f268faf4c \ No newline at end of file From 5001cb83810da905065edc179c3a26c740752e22 Mon Sep 17 00:00:00 2001 From: Passiv Ops Date: Wed, 25 Jun 2025 13:52:53 +0000 Subject: [PATCH 5/5] Regenerate SDKs --- .konfig/generate-id.txt | 2 +- README.md | 12 ++++++------ lib/Model/SimpleOrderForm.php | 24 ++++++++++++------------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.konfig/generate-id.txt b/.konfig/generate-id.txt index f5bb96b..36f1aaf 100644 --- a/.konfig/generate-id.txt +++ b/.konfig/generate-id.txt @@ -1 +1 @@ -08a23feb-95ed-4cd8-81fb-fb2f268faf4c \ No newline at end of file +6e32098e-3a8d-48e3-9b1c-7f68f5569ebd \ No newline at end of file diff --git a/README.md b/README.md index 9e528d2..7344d38 100644 --- a/README.md +++ b/README.md @@ -1205,7 +1205,7 @@ The type of order to place. The Time in Force type for the order. This field indicates how long the order will remain active before it is executed or expires. - `GTC` - Good Til Canceled. The order is valid until it is executed or canceled. - `FOK` - Fill Or Kill. The order must be executed in its entirety immediately or be canceled completely. - `IOC` - Immediate Or Cancel. The order must be executed immediately. Any portion of the order that cannot be filled immediately will be canceled. - `GTD` - Good Til Date. The order is valid until the specified date. -##### amount: `float` +##### amount: `string` The amount of the base currency to buy or sell. @@ -1215,11 +1215,11 @@ The amount of the base currency to buy or sell. ##### account_id: `string` -##### limit_price: `float` +##### limit_price: `string` The limit price. Required if the order type is LIMIT, STOP_LOSS_LIMIT or TAKE_PROFIT_LIMIT. -##### stop_price: `float` +##### stop_price: `string` The stop price. Required if the order type is STOP_LOSS_MARKET, STOP_LOSS_LIMIT, TAKE_PROFIT_MARKET or TAKE_PROFIT_LIMIT. @@ -2383,7 +2383,7 @@ The type of order to place. The Time in Force type for the order. This field indicates how long the order will remain active before it is executed or expires. - `GTC` - Good Til Canceled. The order is valid until it is executed or canceled. - `FOK` - Fill Or Kill. The order must be executed in its entirety immediately or be canceled completely. - `IOC` - Immediate Or Cancel. The order must be executed immediately. Any portion of the order that cannot be filled immediately will be canceled. - `GTD` - Good Til Date. The order is valid until the specified date. -##### amount: `float` +##### amount: `string` The amount of the base currency to buy or sell. @@ -2393,11 +2393,11 @@ The amount of the base currency to buy or sell. ##### account_id: `string` -##### limit_price: `float` +##### limit_price: `string` The limit price. Required if the order type is LIMIT, STOP_LOSS_LIMIT or TAKE_PROFIT_LIMIT. -##### stop_price: `float` +##### stop_price: `string` The stop price. Required if the order type is STOP_LOSS_MARKET, STOP_LOSS_LIMIT, TAKE_PROFIT_MARKET or TAKE_PROFIT_LIMIT. diff --git a/lib/Model/SimpleOrderForm.php b/lib/Model/SimpleOrderForm.php index ff62728..88884e3 100644 --- a/lib/Model/SimpleOrderForm.php +++ b/lib/Model/SimpleOrderForm.php @@ -54,9 +54,9 @@ class SimpleOrderForm implements ModelInterface, ArrayAccess, \JsonSerializable 'side' => '\SnapTrade\Model\ActionStrict', 'type' => 'string', 'time_in_force' => 'string', - 'amount' => 'float', - 'limit_price' => 'float', - 'stop_price' => 'float', + 'amount' => 'string', + 'limit_price' => 'string', + 'stop_price' => 'string', 'post_only' => 'bool', 'expiration_date' => '\DateTime' ]; @@ -73,9 +73,9 @@ class SimpleOrderForm implements ModelInterface, ArrayAccess, \JsonSerializable 'side' => null, 'type' => null, 'time_in_force' => null, - 'amount' => 'decimal', - 'limit_price' => 'decimal', - 'stop_price' => 'decimal', + 'amount' => null, + 'limit_price' => null, + 'stop_price' => null, 'post_only' => null, 'expiration_date' => 'date-time' ]; @@ -552,7 +552,7 @@ public function setTimeInForce($time_in_force) /** * Gets amount * - * @return float + * @return string */ public function getAmount() { @@ -562,7 +562,7 @@ public function getAmount() /** * Sets amount * - * @param float $amount The amount of the base currency to buy or sell. + * @param string $amount The amount of the base currency to buy or sell. * * @return self */ @@ -581,7 +581,7 @@ public function setAmount($amount) /** * Gets limit_price * - * @return float|null + * @return string|null */ public function getLimitPrice() { @@ -591,7 +591,7 @@ public function getLimitPrice() /** * Sets limit_price * - * @param float|null $limit_price The limit price. Required if the order type is LIMIT, STOP_LOSS_LIMIT or TAKE_PROFIT_LIMIT. + * @param string|null $limit_price The limit price. Required if the order type is LIMIT, STOP_LOSS_LIMIT or TAKE_PROFIT_LIMIT. * * @return self */ @@ -610,7 +610,7 @@ public function setLimitPrice($limit_price) /** * Gets stop_price * - * @return float|null + * @return string|null */ public function getStopPrice() { @@ -620,7 +620,7 @@ public function getStopPrice() /** * Sets stop_price * - * @param float|null $stop_price The stop price. Required if the order type is STOP_LOSS_MARKET, STOP_LOSS_LIMIT, TAKE_PROFIT_MARKET or TAKE_PROFIT_LIMIT. + * @param string|null $stop_price The stop price. Required if the order type is STOP_LOSS_MARKET, STOP_LOSS_LIMIT, TAKE_PROFIT_MARKET or TAKE_PROFIT_LIMIT. * * @return self */