text: /**
   * BitMEX API
   * ## REST API for the BitMEX Trading Platform  [View Changelog](/app/apiChangelog)    #### Getting Started  Base URI: [https://www.bitmex.com/api/v1](/api/v1)  ##### Fetching Data  All REST endpoints are documented below. You can try out any query right from this interface.  Most table queries accept `count`, `start`, and `reverse` params. Set `reverse=true` to get rows newest-first.  Additional documentation regarding filters, timestamps, and authentication is available in [the main API documentation](/app/restAPI).  *All* table data is available via the [Websocket](/app/wsAPI). We highly recommend using the socket if you want to have the quickest possible data without being subject to ratelimits.  ##### Return Types  By default, all data is returned as JSON. Send `?_format=csv` to get CSV data or `?_format=xml` to get XML data.  ##### Trade Data Queries  *This is only a small subset of what is available, to get you started.*  Fill in the parameters and click the `Try it out!` button to try any of these queries.  * [Pricing Data](#!/Quote/Quote_get)  * [Trade Data](#!/Trade/Trade_get)  * [OrderBook Data](#!/OrderBook/OrderBook_getL2)  * [Settlement Data](#!/Settlement/Settlement_get)  * [Exchange Statistics](#!/Stats/Stats_history)  Every function of the BitMEX.com platform is exposed here and documented. Many more functions are available.  ##### Swagger Specification  [⇩ Download Swagger JSON](swagger.json)    ## All API Endpoints  Click to expand a section. 
   *
   * OpenAPI spec version: 1.2.0
   * Contact: support@bitmex.com
   *
   * NOTE: This class is auto generated by the swagger code generator 2.4.0-SNAPSHOT.
   * https://github.com/swagger-api/swagger-codegen.git
   * Do not edit the class manually.
   */
  
  
  #include "OrderApi.h"
  #include "IHttpBody.h"
  #include "JsonBody.h"
  #include "MultipartFormData.h"
  
  #include <unordered_set>
  
  #include <boost/algorithm/string/replace.hpp>
  
  namespace io {
  namespace swagger {
  namespace client {
  namespace api {
  
  using namespace io::swagger::client::model;
  
  OrderApi::OrderApi( std::shared_ptr<ApiClient> apiClient )
      : m_ApiClient(apiClient)
  {
  }
  
  OrderApi::~OrderApi()
  {
  }
  
  pplx::task<std::shared_ptr<Order>> OrderApi::order_amend(boost::optional<utility::string_t> orderID, boost::optional<utility::string_t> origClOrdID, boost::optional<utility::string_t> clOrdID, boost::optional<double> simpleOrderQty, boost::optional<double> orderQty, boost::optional<double> simpleLeavesQty, boost::optional<double> leavesQty, boost::optional<double> price, boost::optional<double> stopPx, boost::optional<double> pegOffsetValue, boost::optional<utility::string_t> text)
  {
  
  
      std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
      utility::string_t path = utility::conversions::to_string_t("/order");
      
      std::map<utility::string_t, utility::string_t> queryParams;
      std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
      std::map<utility::string_t, utility::string_t> formParams;
      std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
  
      std::unordered_set<utility::string_t> responseHttpContentTypes;
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/javascript") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/javascript") );
  
      utility::string_t responseHttpContentType;
  
      // use JSON if possible
      if ( responseHttpContentTypes.size() == 0 )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // JSON
      else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(400, utility::conversions::to_string_t("OrderApi->order_amend does not produce any supported media type"));
      }
  
      headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
  
      std::unordered_set<utility::string_t> consumeHttpContentTypes;
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/x-www-form-urlencoded") );
  
      if (orderID)
      {
          formParams[ utility::conversions::to_string_t("orderID") ] = ApiClient::parameterToString(*orderID);
      }
      if (origClOrdID)
      {
          formParams[ utility::conversions::to_string_t("origClOrdID") ] = ApiClient::parameterToString(*origClOrdID);
      }
      if (clOrdID)
      {
          formParams[ utility::conversions::to_string_t("clOrdID") ] = ApiClient::parameterToString(*clOrdID);
      }
      if (simpleOrderQty)
      {
          formParams[ utility::conversions::to_string_t("simpleOrderQty") ] = ApiClient::parameterToString(*simpleOrderQty);
      }
      if (orderQty)
      {
          formParams[ utility::conversions::to_string_t("orderQty") ] = ApiClient::parameterToString(*orderQty);
      }
      if (simpleLeavesQty)
      {
          formParams[ utility::conversions::to_string_t("simpleLeavesQty") ] = ApiClient::parameterToString(*simpleLeavesQty);
      }
      if (leavesQty)
      {
          formParams[ utility::conversions::to_string_t("leavesQty") ] = ApiClient::parameterToString(*leavesQty);
      }
      if (price)
      {
          formParams[ utility::conversions::to_string_t("price") ] = ApiClient::parameterToString(*price);
      }
      if (stopPx)
      {
          formParams[ utility::conversions::to_string_t("stopPx") ] = ApiClient::parameterToString(*stopPx);
      }
      if (pegOffsetValue)
      {
          formParams[ utility::conversions::to_string_t("pegOffsetValue") ] = ApiClient::parameterToString(*pegOffsetValue);
      }
      if (text)
      {
          formParams[ utility::conversions::to_string_t("text") ] = ApiClient::parameterToString(*text);
      }
  
      std::shared_ptr<IHttpBody> httpBody;
      utility::string_t requestHttpContentType;
  
      // use JSON if possible
      if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(415, utility::conversions::to_string_t("OrderApi->order_amend does not consume any supported media type"));
      }
  
      // authentication (apiKey) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-key"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-key")] = apiKey;
          }
      }
      // authentication (apiNonce) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-nonce"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-nonce")] = apiKey;
          }
      }
      // authentication (apiSignature) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-signature"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-signature")] = apiKey;
          }
      }
  
      return m_ApiClient->callApi(path, utility::conversions::to_string_t("PUT"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
      .then([=](web::http::http_response response)
      {
          // 1xx - informational : OK
          // 2xx - successful       : OK
          // 3xx - redirection   : OK
          // 4xx - client error  : not OK
          // 5xx - client error  : not OK
          if (response.status_code() >= 400)
          {
              throw ApiException(response.status_code()
                  , utility::conversions::to_string_t("error calling order_amend: ") + response.reason_phrase()
                  , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
          }
  
          // check response content type
          if(response.headers().has(utility::conversions::to_string_t("Content-Type")))
          {
              utility::string_t contentType = response.headers()[utility::conversions::to_string_t("Content-Type")];
              if( contentType.find(responseHttpContentType) == std::string::npos )
              {
                  throw ApiException(500
                      , utility::conversions::to_string_t("error calling order_amend: unexpected response type: ") + contentType
                      , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
              }
          }
  
          return response.extract_string();
      })
      .then([=](utility::string_t response)
      {
          std::shared_ptr<Order> result(new Order());
  
          if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
          {
              web::json::value json = web::json::value::parse(response);
  
              result->fromJson(json);
          }
          // else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
          // {
          // TODO multipart response parsing
          // }
          else
          {
              throw ApiException(500
                  , utility::conversions::to_string_t("error calling order_amend: unsupported response type"));
          }
  
          return result;
      });
  }
  pplx::task<std::vector<std::shared_ptr<Order>>> OrderApi::order_amendBulk(boost::optional<utility::string_t> orders)
  {
  
  
      std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
      utility::string_t path = utility::conversions::to_string_t("/order/bulk");
      
      std::map<utility::string_t, utility::string_t> queryParams;
      std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
      std::map<utility::string_t, utility::string_t> formParams;
      std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
  
      std::unordered_set<utility::string_t> responseHttpContentTypes;
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/javascript") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/javascript") );
  
      utility::string_t responseHttpContentType;
  
      // use JSON if possible
      if ( responseHttpContentTypes.size() == 0 )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // JSON
      else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(400, utility::conversions::to_string_t("OrderApi->order_amendBulk does not produce any supported media type"));
      }
  
      headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
  
      std::unordered_set<utility::string_t> consumeHttpContentTypes;
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/x-www-form-urlencoded") );
  
      if (orders)
      {
          formParams[ utility::conversions::to_string_t("orders") ] = ApiClient::parameterToString(*orders);
      }
  
      std::shared_ptr<IHttpBody> httpBody;
      utility::string_t requestHttpContentType;
  
      // use JSON if possible
      if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(415, utility::conversions::to_string_t("OrderApi->order_amendBulk does not consume any supported media type"));
      }
  
      // authentication (apiKey) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-key"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-key")] = apiKey;
          }
      }
      // authentication (apiNonce) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-nonce"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-nonce")] = apiKey;
          }
      }
      // authentication (apiSignature) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-signature"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-signature")] = apiKey;
          }
      }
  
      return m_ApiClient->callApi(path, utility::conversions::to_string_t("PUT"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
      .then([=](web::http::http_response response)
      {
          // 1xx - informational : OK
          // 2xx - successful       : OK
          // 3xx - redirection   : OK
          // 4xx - client error  : not OK
          // 5xx - client error  : not OK
          if (response.status_code() >= 400)
          {
              throw ApiException(response.status_code()
                  , utility::conversions::to_string_t("error calling order_amendBulk: ") + response.reason_phrase()
                  , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
          }
  
          // check response content type
          if(response.headers().has(utility::conversions::to_string_t("Content-Type")))
          {
              utility::string_t contentType = response.headers()[utility::conversions::to_string_t("Content-Type")];
              if( contentType.find(responseHttpContentType) == std::string::npos )
              {
                  throw ApiException(500
                      , utility::conversions::to_string_t("error calling order_amendBulk: unexpected response type: ") + contentType
                      , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
              }
          }
  
          return response.extract_string();
      })
      .then([=](utility::string_t response)
      {
          std::vector<std::shared_ptr<Order>> result;
  
          if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
          {
              web::json::value json = web::json::value::parse(response);
  
              for( auto& item : json.as_array() )
              {
                  std::shared_ptr<Order> itemObj(new Order());
                  itemObj->fromJson(item);
                  result.push_back(itemObj);
                  
              }
              
          }
          // else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
          // {
          // TODO multipart response parsing
          // }
          else
          {
              throw ApiException(500
                  , utility::conversions::to_string_t("error calling order_amendBulk: unsupported response type"));
          }
  
          return result;
      });
  }
  pplx::task<std::vector<std::shared_ptr<Order>>> OrderApi::order_cancel(boost::optional<utility::string_t> orderID, boost::optional<utility::string_t> clOrdID, boost::optional<utility::string_t> text)
  {
  
  
      std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
      utility::string_t path = utility::conversions::to_string_t("/order");
      
      std::map<utility::string_t, utility::string_t> queryParams;
      std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
      std::map<utility::string_t, utility::string_t> formParams;
      std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
  
      std::unordered_set<utility::string_t> responseHttpContentTypes;
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/javascript") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/javascript") );
  
      utility::string_t responseHttpContentType;
  
      // use JSON if possible
      if ( responseHttpContentTypes.size() == 0 )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // JSON
      else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(400, utility::conversions::to_string_t("OrderApi->order_cancel does not produce any supported media type"));
      }
  
      headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
  
      std::unordered_set<utility::string_t> consumeHttpContentTypes;
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/x-www-form-urlencoded") );
  
      if (orderID)
      {
          formParams[ utility::conversions::to_string_t("orderID") ] = ApiClient::parameterToString(*orderID);
      }
      if (clOrdID)
      {
          formParams[ utility::conversions::to_string_t("clOrdID") ] = ApiClient::parameterToString(*clOrdID);
      }
      if (text)
      {
          formParams[ utility::conversions::to_string_t("text") ] = ApiClient::parameterToString(*text);
      }
  
      std::shared_ptr<IHttpBody> httpBody;
      utility::string_t requestHttpContentType;
  
      // use JSON if possible
      if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(415, utility::conversions::to_string_t("OrderApi->order_cancel does not consume any supported media type"));
      }
  
      // authentication (apiKey) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-key"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-key")] = apiKey;
          }
      }
      // authentication (apiNonce) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-nonce"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-nonce")] = apiKey;
          }
      }
      // authentication (apiSignature) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-signature"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-signature")] = apiKey;
          }
      }
  
      return m_ApiClient->callApi(path, utility::conversions::to_string_t("DELETE"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
      .then([=](web::http::http_response response)
      {
          // 1xx - informational : OK
          // 2xx - successful       : OK
          // 3xx - redirection   : OK
          // 4xx - client error  : not OK
          // 5xx - client error  : not OK
          if (response.status_code() >= 400)
          {
              throw ApiException(response.status_code()
                  , utility::conversions::to_string_t("error calling order_cancel: ") + response.reason_phrase()
                  , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
          }
  
          // check response content type
          if(response.headers().has(utility::conversions::to_string_t("Content-Type")))
          {
              utility::string_t contentType = response.headers()[utility::conversions::to_string_t("Content-Type")];
              if( contentType.find(responseHttpContentType) == std::string::npos )
              {
                  throw ApiException(500
                      , utility::conversions::to_string_t("error calling order_cancel: unexpected response type: ") + contentType
                      , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
              }
          }
  
          return response.extract_string();
      })
      .then([=](utility::string_t response)
      {
          std::vector<std::shared_ptr<Order>> result;
  
          if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
          {
              web::json::value json = web::json::value::parse(response);
  
              for( auto& item : json.as_array() )
              {
                  std::shared_ptr<Order> itemObj(new Order());
                  itemObj->fromJson(item);
                  result.push_back(itemObj);
                  
              }
              
          }
          // else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
          // {
          // TODO multipart response parsing
          // }
          else
          {
              throw ApiException(500
                  , utility::conversions::to_string_t("error calling order_cancel: unsupported response type"));
          }
  
          return result;
      });
  }
  pplx::task<std::vector<std::shared_ptr<Order>>> OrderApi::order_cancelAll(boost::optional<utility::string_t> symbol, boost::optional<utility::string_t> filter, boost::optional<utility::string_t> text)
  {
  
  
      std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
      utility::string_t path = utility::conversions::to_string_t("/order/all");
      
      std::map<utility::string_t, utility::string_t> queryParams;
      std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
      std::map<utility::string_t, utility::string_t> formParams;
      std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
  
      std::unordered_set<utility::string_t> responseHttpContentTypes;
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/javascript") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/javascript") );
  
      utility::string_t responseHttpContentType;
  
      // use JSON if possible
      if ( responseHttpContentTypes.size() == 0 )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // JSON
      else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(400, utility::conversions::to_string_t("OrderApi->order_cancelAll does not produce any supported media type"));
      }
  
      headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
  
      std::unordered_set<utility::string_t> consumeHttpContentTypes;
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/x-www-form-urlencoded") );
  
      if (symbol)
      {
          formParams[ utility::conversions::to_string_t("symbol") ] = ApiClient::parameterToString(*symbol);
      }
      if (filter)
      {
          formParams[ utility::conversions::to_string_t("filter") ] = ApiClient::parameterToString(*filter);
      }
      if (text)
      {
          formParams[ utility::conversions::to_string_t("text") ] = ApiClient::parameterToString(*text);
      }
  
      std::shared_ptr<IHttpBody> httpBody;
      utility::string_t requestHttpContentType;
  
      // use JSON if possible
      if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(415, utility::conversions::to_string_t("OrderApi->order_cancelAll does not consume any supported media type"));
      }
  
      // authentication (apiKey) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-key"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-key")] = apiKey;
          }
      }
      // authentication (apiNonce) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-nonce"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-nonce")] = apiKey;
          }
      }
      // authentication (apiSignature) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-signature"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-signature")] = apiKey;
          }
      }
  
      return m_ApiClient->callApi(path, utility::conversions::to_string_t("DELETE"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
      .then([=](web::http::http_response response)
      {
          // 1xx - informational : OK
          // 2xx - successful       : OK
          // 3xx - redirection   : OK
          // 4xx - client error  : not OK
          // 5xx - client error  : not OK
          if (response.status_code() >= 400)
          {
              throw ApiException(response.status_code()
                  , utility::conversions::to_string_t("error calling order_cancelAll: ") + response.reason_phrase()
                  , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
          }
  
          // check response content type
          if(response.headers().has(utility::conversions::to_string_t("Content-Type")))
          {
              utility::string_t contentType = response.headers()[utility::conversions::to_string_t("Content-Type")];
              if( contentType.find(responseHttpContentType) == std::string::npos )
              {
                  throw ApiException(500
                      , utility::conversions::to_string_t("error calling order_cancelAll: unexpected response type: ") + contentType
                      , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
              }
          }
  
          return response.extract_string();
      })
      .then([=](utility::string_t response)
      {
          std::vector<std::shared_ptr<Order>> result;
  
          if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
          {
              web::json::value json = web::json::value::parse(response);
  
              for( auto& item : json.as_array() )
              {
                  std::shared_ptr<Order> itemObj(new Order());
                  itemObj->fromJson(item);
                  result.push_back(itemObj);
                  
              }
              
          }
          // else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
          // {
          // TODO multipart response parsing
          // }
          else
          {
              throw ApiException(500
                  , utility::conversions::to_string_t("error calling order_cancelAll: unsupported response type"));
          }
  
          return result;
      });
  }
  pplx::task<std::shared_ptr<Object>> OrderApi::order_cancelAllAfter(double timeout)
  {
  
  
      std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
      utility::string_t path = utility::conversions::to_string_t("/order/cancelAllAfter");
      
      std::map<utility::string_t, utility::string_t> queryParams;
      std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
      std::map<utility::string_t, utility::string_t> formParams;
      std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
  
      std::unordered_set<utility::string_t> responseHttpContentTypes;
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/javascript") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/javascript") );
  
      utility::string_t responseHttpContentType;
  
      // use JSON if possible
      if ( responseHttpContentTypes.size() == 0 )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // JSON
      else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(400, utility::conversions::to_string_t("OrderApi->order_cancelAllAfter does not produce any supported media type"));
      }
  
      headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
  
      std::unordered_set<utility::string_t> consumeHttpContentTypes;
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/x-www-form-urlencoded") );
  
      {
          formParams[ utility::conversions::to_string_t("timeout") ] = ApiClient::parameterToString(timeout);
      }
  
      std::shared_ptr<IHttpBody> httpBody;
      utility::string_t requestHttpContentType;
  
      // use JSON if possible
      if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(415, utility::conversions::to_string_t("OrderApi->order_cancelAllAfter does not consume any supported media type"));
      }
  
      // authentication (apiKey) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-key"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-key")] = apiKey;
          }
      }
      // authentication (apiNonce) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-nonce"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-nonce")] = apiKey;
          }
      }
      // authentication (apiSignature) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-signature"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-signature")] = apiKey;
          }
      }
  
      return m_ApiClient->callApi(path, utility::conversions::to_string_t("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
      .then([=](web::http::http_response response)
      {
          // 1xx - informational : OK
          // 2xx - successful       : OK
          // 3xx - redirection   : OK
          // 4xx - client error  : not OK
          // 5xx - client error  : not OK
          if (response.status_code() >= 400)
          {
              throw ApiException(response.status_code()
                  , utility::conversions::to_string_t("error calling order_cancelAllAfter: ") + response.reason_phrase()
                  , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
          }
  
          // check response content type
          if(response.headers().has(utility::conversions::to_string_t("Content-Type")))
          {
              utility::string_t contentType = response.headers()[utility::conversions::to_string_t("Content-Type")];
              if( contentType.find(responseHttpContentType) == std::string::npos )
              {
                  throw ApiException(500
                      , utility::conversions::to_string_t("error calling order_cancelAllAfter: unexpected response type: ") + contentType
                      , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
              }
          }
  
          return response.extract_string();
      })
      .then([=](utility::string_t response)
      {
          std::shared_ptr<Object> result(nullptr);
  
          if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
          {
              web::json::value json = web::json::value::parse(response);
  
              result->fromJson(json);
          }
          // else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
          // {
          // TODO multipart response parsing
          // }
          else
          {
              throw ApiException(500
                  , utility::conversions::to_string_t("error calling order_cancelAllAfter: unsupported response type"));
          }
  
          return result;
      });
  }
  pplx::task<std::shared_ptr<Order>> OrderApi::order_closePosition(utility::string_t symbol, boost::optional<double> price)
  {
  
  
      std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
      utility::string_t path = utility::conversions::to_string_t("/order/closePosition");
      
      std::map<utility::string_t, utility::string_t> queryParams;
      std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
      std::map<utility::string_t, utility::string_t> formParams;
      std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
  
      std::unordered_set<utility::string_t> responseHttpContentTypes;
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/javascript") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/javascript") );
  
      utility::string_t responseHttpContentType;
  
      // use JSON if possible
      if ( responseHttpContentTypes.size() == 0 )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // JSON
      else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(400, utility::conversions::to_string_t("OrderApi->order_closePosition does not produce any supported media type"));
      }
  
      headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
  
      std::unordered_set<utility::string_t> consumeHttpContentTypes;
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/x-www-form-urlencoded") );
  
      {
          formParams[ utility::conversions::to_string_t("symbol") ] = ApiClient::parameterToString(symbol);
      }
      if (price)
      {
          formParams[ utility::conversions::to_string_t("price") ] = ApiClient::parameterToString(*price);
      }
  
      std::shared_ptr<IHttpBody> httpBody;
      utility::string_t requestHttpContentType;
  
      // use JSON if possible
      if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(415, utility::conversions::to_string_t("OrderApi->order_closePosition does not consume any supported media type"));
      }
  
      // authentication (apiKey) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-key"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-key")] = apiKey;
          }
      }
      // authentication (apiNonce) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-nonce"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-nonce")] = apiKey;
          }
      }
      // authentication (apiSignature) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-signature"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-signature")] = apiKey;
          }
      }
  
      return m_ApiClient->callApi(path, utility::conversions::to_string_t("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
      .then([=](web::http::http_response response)
      {
          // 1xx - informational : OK
          // 2xx - successful       : OK
          // 3xx - redirection   : OK
          // 4xx - client error  : not OK
          // 5xx - client error  : not OK
          if (response.status_code() >= 400)
          {
              throw ApiException(response.status_code()
                  , utility::conversions::to_string_t("error calling order_closePosition: ") + response.reason_phrase()
                  , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
          }
  
          // check response content type
          if(response.headers().has(utility::conversions::to_string_t("Content-Type")))
          {
              utility::string_t contentType = response.headers()[utility::conversions::to_string_t("Content-Type")];
              if( contentType.find(responseHttpContentType) == std::string::npos )
              {
                  throw ApiException(500
                      , utility::conversions::to_string_t("error calling order_closePosition: unexpected response type: ") + contentType
                      , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
              }
          }
  
          return response.extract_string();
      })
      .then([=](utility::string_t response)
      {
          std::shared_ptr<Order> result(new Order());
  
          if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
          {
              web::json::value json = web::json::value::parse(response);
  
              result->fromJson(json);
          }
          // else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
          // {
          // TODO multipart response parsing
          // }
          else
          {
              throw ApiException(500
                  , utility::conversions::to_string_t("error calling order_closePosition: unsupported response type"));
          }
  
          return result;
      });
  }
  pplx::task<std::vector<std::shared_ptr<Order>>> OrderApi::order_getOrders(boost::optional<utility::string_t> symbol, boost::optional<utility::string_t> filter, boost::optional<utility::string_t> columns, boost::optional<double> count, boost::optional<double> start, boost::optional<bool> reverse, boost::optional<utility::datetime> startTime, boost::optional<utility::datetime> endTime)
  {
  
  
      std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
      utility::string_t path = utility::conversions::to_string_t("/order");
      
      std::map<utility::string_t, utility::string_t> queryParams;
      std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
      std::map<utility::string_t, utility::string_t> formParams;
      std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
  
      std::unordered_set<utility::string_t> responseHttpContentTypes;
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/javascript") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/javascript") );
  
      utility::string_t responseHttpContentType;
  
      // use JSON if possible
      if ( responseHttpContentTypes.size() == 0 )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // JSON
      else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(400, utility::conversions::to_string_t("OrderApi->order_getOrders does not produce any supported media type"));
      }
  
      headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
  
      std::unordered_set<utility::string_t> consumeHttpContentTypes;
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/x-www-form-urlencoded") );
  
      if (symbol)
      {
          queryParams[utility::conversions::to_string_t("symbol")] = ApiClient::parameterToString(*symbol);
      }
      if (filter)
      {
          queryParams[utility::conversions::to_string_t("filter")] = ApiClient::parameterToString(*filter);
      }
      if (columns)
      {
          queryParams[utility::conversions::to_string_t("columns")] = ApiClient::parameterToString(*columns);
      }
      if (count)
      {
          queryParams[utility::conversions::to_string_t("count")] = ApiClient::parameterToString(*count);
      }
      if (start)
      {
          queryParams[utility::conversions::to_string_t("start")] = ApiClient::parameterToString(*start);
      }
      if (reverse)
      {
          queryParams[utility::conversions::to_string_t("reverse")] = ApiClient::parameterToString(*reverse);
      }
      if (startTime)
      {
          queryParams[utility::conversions::to_string_t("startTime")] = ApiClient::parameterToString(*startTime);
      }
      if (endTime)
      {
          queryParams[utility::conversions::to_string_t("endTime")] = ApiClient::parameterToString(*endTime);
      }
  
      std::shared_ptr<IHttpBody> httpBody;
      utility::string_t requestHttpContentType;
  
      // use JSON if possible
      if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(415, utility::conversions::to_string_t("OrderApi->order_getOrders does not consume any supported media type"));
      }
  
      // authentication (apiKey) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-key"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-key")] = apiKey;
          }
      }
      // authentication (apiNonce) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-nonce"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-nonce")] = apiKey;
          }
      }
      // authentication (apiSignature) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-signature"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-signature")] = apiKey;
          }
      }
  
      return m_ApiClient->callApi(path, utility::conversions::to_string_t("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
      .then([=](web::http::http_response response)
      {
          // 1xx - informational : OK
          // 2xx - successful       : OK
          // 3xx - redirection   : OK
          // 4xx - client error  : not OK
          // 5xx - client error  : not OK
          if (response.status_code() >= 400)
          {
              throw ApiException(response.status_code()
                  , utility::conversions::to_string_t("error calling order_getOrders: ") + response.reason_phrase()
                  , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
          }
  
          // check response content type
          if(response.headers().has(utility::conversions::to_string_t("Content-Type")))
          {
              utility::string_t contentType = response.headers()[utility::conversions::to_string_t("Content-Type")];
              if( contentType.find(responseHttpContentType) == std::string::npos )
              {
                  throw ApiException(500
                      , utility::conversions::to_string_t("error calling order_getOrders: unexpected response type: ") + contentType
                      , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
              }
          }
  
          return response.extract_string();
      })
      .then([=](utility::string_t response)
      {
          std::vector<std::shared_ptr<Order>> result;
  
          if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
          {
              web::json::value json = web::json::value::parse(response);
  
              for( auto& item : json.as_array() )
              {
                  std::shared_ptr<Order> itemObj(new Order());
                  itemObj->fromJson(item);
                  result.push_back(itemObj);
                  
              }
              
          }
          // else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
          // {
          // TODO multipart response parsing
          // }
          else
          {
              throw ApiException(500
                  , utility::conversions::to_string_t("error calling order_getOrders: unsupported response type"));
          }
  
          return result;
      });
  }
  pplx::task<std::shared_ptr<Order>> OrderApi::order_new(utility::string_t symbol, boost::optional<utility::string_t> side, boost::optional<double> simpleOrderQty, boost::optional<double> orderQty, boost::optional<double> price, boost::optional<double> displayQty, boost::optional<double> stopPx, boost::optional<utility::string_t> clOrdID, boost::optional<utility::string_t> clOrdLinkID, boost::optional<double> pegOffsetValue, boost::optional<utility::string_t> pegPriceType, boost::optional<utility::string_t> ordType, boost::optional<utility::string_t> timeInForce, boost::optional<utility::string_t> execInst, boost::optional<utility::string_t> contingencyType, boost::optional<utility::string_t> text)
  {
  
  
      std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
      utility::string_t path = utility::conversions::to_string_t("/order");
      
      std::map<utility::string_t, utility::string_t> queryParams;
      std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
      std::map<utility::string_t, utility::string_t> formParams;
      std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
  
      std::unordered_set<utility::string_t> responseHttpContentTypes;
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/javascript") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/javascript") );
  
      utility::string_t responseHttpContentType;
  
      // use JSON if possible
      if ( responseHttpContentTypes.size() == 0 )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // JSON
      else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(400, utility::conversions::to_string_t("OrderApi->order_new does not produce any supported media type"));
      }
  
      headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
  
      std::unordered_set<utility::string_t> consumeHttpContentTypes;
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/x-www-form-urlencoded") );
  
      {
          formParams[ utility::conversions::to_string_t("symbol") ] = ApiClient::parameterToString(symbol);
      }
      if (side)
      {
          formParams[ utility::conversions::to_string_t("side") ] = ApiClient::parameterToString(*side);
      }
      if (simpleOrderQty)
      {
          formParams[ utility::conversions::to_string_t("simpleOrderQty") ] = ApiClient::parameterToString(*simpleOrderQty);
      }
      if (orderQty)
      {
          formParams[ utility::conversions::to_string_t("orderQty") ] = ApiClient::parameterToString(*orderQty);
      }
      if (price)
      {
          formParams[ utility::conversions::to_string_t("price") ] = ApiClient::parameterToString(*price);
      }
      if (displayQty)
      {
          formParams[ utility::conversions::to_string_t("displayQty") ] = ApiClient::parameterToString(*displayQty);
      }
      if (stopPx)
      {
          formParams[ utility::conversions::to_string_t("stopPx") ] = ApiClient::parameterToString(*stopPx);
      }
      if (clOrdID)
      {
          formParams[ utility::conversions::to_string_t("clOrdID") ] = ApiClient::parameterToString(*clOrdID);
      }
      if (clOrdLinkID)
      {
          formParams[ utility::conversions::to_string_t("clOrdLinkID") ] = ApiClient::parameterToString(*clOrdLinkID);
      }
      if (pegOffsetValue)
      {
          formParams[ utility::conversions::to_string_t("pegOffsetValue") ] = ApiClient::parameterToString(*pegOffsetValue);
      }
      if (pegPriceType)
      {
          formParams[ utility::conversions::to_string_t("pegPriceType") ] = ApiClient::parameterToString(*pegPriceType);
      }
      if (ordType)
      {
          formParams[ utility::conversions::to_string_t("ordType") ] = ApiClient::parameterToString(*ordType);
      }
      if (timeInForce)
      {
          formParams[ utility::conversions::to_string_t("timeInForce") ] = ApiClient::parameterToString(*timeInForce);
      }
      if (execInst)
      {
          formParams[ utility::conversions::to_string_t("execInst") ] = ApiClient::parameterToString(*execInst);
      }
      if (contingencyType)
      {
          formParams[ utility::conversions::to_string_t("contingencyType") ] = ApiClient::parameterToString(*contingencyType);
      }
      if (text)
      {
          formParams[ utility::conversions::to_string_t("text") ] = ApiClient::parameterToString(*text);
      }
  
      std::shared_ptr<IHttpBody> httpBody;
      utility::string_t requestHttpContentType;
  
      // use JSON if possible
      if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(415, utility::conversions::to_string_t("OrderApi->order_new does not consume any supported media type"));
      }
  
      // authentication (apiKey) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-key"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-key")] = apiKey;
          }
      }
      // authentication (apiNonce) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-nonce"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-nonce")] = apiKey;
          }
      }
      // authentication (apiSignature) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-signature"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-signature")] = apiKey;
          }
      }
  
      return m_ApiClient->callApi(path, utility::conversions::to_string_t("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
      .then([=](web::http::http_response response)
      {
          // 1xx - informational : OK
          // 2xx - successful       : OK
          // 3xx - redirection   : OK
          // 4xx - client error  : not OK
          // 5xx - client error  : not OK
          if (response.status_code() >= 400)
          {
              throw ApiException(response.status_code()
                  , utility::conversions::to_string_t("error calling order_new: ") + response.reason_phrase()
                  , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
          }
  
          // check response content type
          if(response.headers().has(utility::conversions::to_string_t("Content-Type")))
          {
              utility::string_t contentType = response.headers()[utility::conversions::to_string_t("Content-Type")];
              if( contentType.find(responseHttpContentType) == std::string::npos )
              {
                  throw ApiException(500
                      , utility::conversions::to_string_t("error calling order_new: unexpected response type: ") + contentType
                      , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
              }
          }
  
          return response.extract_string();
      })
      .then([=](utility::string_t response)
      {
          std::shared_ptr<Order> result(new Order());
  
          if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
          {
              web::json::value json = web::json::value::parse(response);
  
              result->fromJson(json);
          }
          // else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
          // {
          // TODO multipart response parsing
          // }
          else
          {
              throw ApiException(500
                  , utility::conversions::to_string_t("error calling order_new: unsupported response type"));
          }
  
          return result;
      });
  }
  pplx::task<std::vector<std::shared_ptr<Order>>> OrderApi::order_newBulk(boost::optional<utility::string_t> orders)
  {
  
  
      std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
      utility::string_t path = utility::conversions::to_string_t("/order/bulk");
      
      std::map<utility::string_t, utility::string_t> queryParams;
      std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
      std::map<utility::string_t, utility::string_t> formParams;
      std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
  
      std::unordered_set<utility::string_t> responseHttpContentTypes;
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/xml") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("application/javascript") );
      responseHttpContentTypes.insert( utility::conversions::to_string_t("text/javascript") );
  
      utility::string_t responseHttpContentType;
  
      // use JSON if possible
      if ( responseHttpContentTypes.size() == 0 )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // JSON
      else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
      {
          responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(400, utility::conversions::to_string_t("OrderApi->order_newBulk does not produce any supported media type"));
      }
  
      headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
  
      std::unordered_set<utility::string_t> consumeHttpContentTypes;
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
      consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/x-www-form-urlencoded") );
  
      if (orders)
      {
          formParams[ utility::conversions::to_string_t("orders") ] = ApiClient::parameterToString(*orders);
      }
  
      std::shared_ptr<IHttpBody> httpBody;
      utility::string_t requestHttpContentType;
  
      // use JSON if possible
      if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("application/json");
      }
      // multipart formdata
      else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
      {
          requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
      }
      else
      {
          throw ApiException(415, utility::conversions::to_string_t("OrderApi->order_newBulk does not consume any supported media type"));
      }
  
      // authentication (apiKey) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-key"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-key")] = apiKey;
          }
      }
      // authentication (apiNonce) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-nonce"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-nonce")] = apiKey;
          }
      }
      // authentication (apiSignature) required
      {
          utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api-signature"));
          if ( apiKey.size() > 0 )
          {
              headerParams[utility::conversions::to_string_t("api-signature")] = apiKey;
          }
      }
  
      return m_ApiClient->callApi(path, utility::conversions::to_string_t("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
      .then([=](web::http::http_response response)
      {
          // 1xx - informational : OK
          // 2xx - successful       : OK
          // 3xx - redirection   : OK
          // 4xx - client error  : not OK
          // 5xx - client error  : not OK
          if (response.status_code() >= 400)
          {
              throw ApiException(response.status_code()
                  , utility::conversions::to_string_t("error calling order_newBulk: ") + response.reason_phrase()
                  , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
          }
  
          // check response content type
          if(response.headers().has(utility::conversions::to_string_t("Content-Type")))
          {
              utility::string_t contentType = response.headers()[utility::conversions::to_string_t("Content-Type")];
              if( contentType.find(responseHttpContentType) == std::string::npos )
              {
                  throw ApiException(500
                      , utility::conversions::to_string_t("error calling order_newBulk: unexpected response type: ") + contentType
                      , std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
              }
          }
  
          return response.extract_string();
      })
      .then([=](utility::string_t response)
      {
          std::vector<std::shared_ptr<Order>> result;
  
          if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
          {
              web::json::value json = web::json::value::parse(response);
  
              for( auto& item : json.as_array() )
              {
                  std::shared_ptr<Order> itemObj(new Order());
                  itemObj->fromJson(item);
                  result.push_back(itemObj);
                  
              }
              
          }
          // else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
          // {
          // TODO multipart response parsing
          // }
          else
          {
              throw ApiException(500
                  , utility::conversions::to_string_t("error calling order_newBulk: unsupported response type"));
          }
  
          return result;
      });
  }
  
  }
  }
  }
  }
  
  