<commit_before>/*
 * Copyright 2015 – 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package rx.oanda.trades

import akka.NotUsed
import akka.actor.ActorSystem
import akka.stream.Materializer
import akka.stream.scaladsl.Source
import rx.oanda.OandaEnvironment.ConnectionPool
import rx.oanda.trades.TradeClientRequests._
import rx.oanda.{ApiConnection, OandaEnvironment}

class TradeClient(env: OandaEnvironment)(implicit sys: ActorSystem, mat: Materializer, A: ConnectionPool)
  extends ApiConnection {

  private[oanda] val apiConnection = env.apiFlow[Long]

  /**
    * Get the last `count` trades from all instruments.
    *
    * @param accountId The account id to use.
    * @param count     The number of trades to receive.
    * @return A source which emits up to `count` trades.
    */
  def trades(accountId: Long, count: Int = 50, maxId: Option[Long] = None): Source[Trade, NotUsed] =
    makeRequest[Vector[Trade]](tradesRequest(accountId, maxId, Some(count), None, Nil).withHeaders(env.headers))
      .log("trades").mapConcat(identity).log("trade")

  /**
    * Get the last `count` trades from a specific instrument.
    *
    * @param accountId  The account id to use.
    * @param instrument The instrument code to fetch trades for.
    * @param count      The number of trades to receive.
    * @return A source which emits up to `count` trades of the specified instrument.
    */
  def trades(accountId: Long, instrument: String, count: Int = 50, maxId: Option[Long] = None): Source[Trade, NotUsed] =
    makeRequest[Vector[Trade]](tradesRequest(accountId, maxId, Some(count), Some(instrument), Nil).withHeaders(env.headers))
      .log("trades").mapConcat(identity).log("trade")

  /**
    * Get specific trades by their id.
    *
    * @param accountId The account id to use.
    * @param tradeIds  The ids of the trades to retrieve.
    * @return A source which emits the trades.
    */
  def tradesByIds(accountId: Long, tradeIds: Seq[Long]): Source[Trade, NotUsed] =
    makeRequest[Vector[Trade]](tradesRequest(accountId, None, None, None, tradeIds).withHeaders(env.headers))
      .log("trades").mapConcat(identity).log("trade")

  /**<commit_msg>Rename method in trade client<commit_after>/*
 * Copyright 2015 – 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package rx.oanda.trades

import akka.NotUsed
import akka.actor.ActorSystem
import akka.stream.Materializer
import akka.stream.scaladsl.Source
import rx.oanda.OandaEnvironment.ConnectionPool
import rx.oanda.trades.TradeClientRequests._
import rx.oanda.{ApiConnection, OandaEnvironment}

class TradeClient(env: OandaEnvironment)(implicit sys: ActorSystem, mat: Materializer, A: ConnectionPool)
  extends ApiConnection {

  private[oanda] val apiConnection = env.apiFlow[Long]

  /**
    * Get the last `count` trades from all instruments.
    *
    * @param accountId The account id to use.
    * @param count     The number of trades to receive.
    * @return A source which emits up to `count` trades.
    */
  def trades(accountId: Long, count: Int = 50, maxId: Option[Long] = None): Source[Trade, NotUsed] =
    makeRequest[Vector[Trade]](tradesRequest(accountId, maxId, Some(count), None, Nil).withHeaders(env.headers))
      .log("trades").mapConcat(identity).log("trade")

  /**
    * Get the last `count` trades from a specific instrument.
    *
    * @param accountId  The account id to use.
    * @param instrument The instrument code to fetch trades for.
    * @param count      The number of trades to receive.
    * @return A source which emits up to `count` trades of the specified instrument.
    */
  def tradesByInstrument(accountId: Long, instrument: String, count: Int = 50, maxId: Option[Long] = None): Source[Trade, NotUsed] =
    makeRequest[Vector[Trade]](tradesRequest(accountId, maxId, Some(count), Some(instrument), Nil).withHeaders(env.headers))
      .log("trades").mapConcat(identity).log("trade")

  /**
    * Get specific trades by their id.
    *
    * @param accountId The account id to use.
    * @param tradeIds  The ids of the trades to retrieve.
    * @return A source which emits the trades.
    */
  def tradesByIds(accountId: Long, tradeIds: Seq[Long]): Source[Trade, NotUsed] =
    makeRequest[Vector[Trade]](tradesRequest(accountId, None, None, None, tradeIds).withHeaders(env.headers))
      .log("trades").mapConcat(identity).log("trade")

  /**
{'fraction_non_alphanumeric': 0.10685335298452468, 'fraction_numerical': 0.0058953574060427415, 'mean_word_length': 3.9399454049135576, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2487888', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1572, 'n_words': 548}