package org.knowm.xchange.btcturk.service.marketdata;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.knowm.xchange.Exchange;
import org.knowm.xchange.ExchangeFactory;
import org.knowm.xchange.ExchangeSpecification;
import org.knowm.xchange.btcturk.BTCTurkExchange;
import org.knowm.xchange.btcturk.dto.marketdata.BTCTurkOHLC;
import org.knowm.xchange.btcturk.dto.marketdata.BTCTurkOrderBook;
import org.knowm.xchange.btcturk.service.BTCTurkDemoUtilsTest;
import org.knowm.xchange.btcturk.service.BTCTurkMarketDataService;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.dto.marketdata.Ticker;
import org.knowm.xchange.dto.marketdata.Trades;
import org.knowm.xchange.service.marketdata.MarketDataService;
import org.knowm.xchange.service.marketdata.params.Params;

/** @author semihunaldi 
 *  @author mertguner */
public class MarketDataFetchIntegrationTest {

	private Exchange btcTurk;
	private BTCTurkMarketDataService btcTurkMarketDataService;
	
	@Before
	public void InitExchange() throws IOException 
	{
		ExchangeSpecification exSpec = new BTCTurkExchange().getDefaultExchangeSpecification();
    	exSpec.setApiKey(BTCTurkDemoUtilsTest.BTCTURK_APIKEY);
    	exSpec.setSecretKey(BTCTurkDemoUtilsTest.BTCTURK_SECRETKEY);    	
    	btcTurk = ExchangeFactory.INSTANCE.createExchange(exSpec);
    	
    	MarketDataService marketDataService = btcTurk.getMarketDataService();
    	btcTurkMarketDataService = (BTCTurkMarketDataService)marketDataService;
	}
	
  @Test
  public void TickerTest() throws Exception {
    Ticker ticker = btcTurkMarketDataService.getTicker(new CurrencyPair("BTC", "TRY"));
    System.out.println(ticker.toString());
    assertThat(ticker).isNotNull();
    
    List<Ticker> tickers = btcTurkMarketDataService.getTickers(new Params() {});
    for(Ticker _ticker : tickers)
    {
    	System.out.println(_ticker.toString());
        assertThat(_ticker).isNotNull();
    }
    
  }
  
  @Test
  public void TradesTest() throws Exception {
	  Trades trades = btcTurkMarketDataService.getTrades(CurrencyPair.BTC_TRY);
		assertThat(trades.getTrades().size()).isEqualTo(50);
		 
		trades = btcTurkMarketDataService.getTrades(CurrencyPair.BTC_TRY, 5);
		assertThat(trades.getTrades().size()).isEqualTo(5);
  }
  
  @Test
	public void OHCLTest() throws IOException 
	{
		List<BTCTurkOHLC> btcTurkBTCTurkOHLC = btcTurkMarketDataService.getBTCTurkOHLC(CurrencyPair.BTC_TRY);
		assertThat(btcTurkBTCTurkOHLC.size()).isNotEqualTo(0); //Daily size is always changing
		
		List<BTCTurkOHLC> btcTurkBTCTurkOHLC2 = btcTurkMarketDataService.getBTCTurkOHLC(CurrencyPair.BTC_TRY, 2);
		assertThat(btcTurkBTCTurkOHLC2.size()).isEqualTo(2);
	}
  
  @Test
	public void OrderBookTest() throws IOException 
	{
		BTCTurkOrderBook btcTurkBTCTurkOrderBook = btcTurkMarketDataService.getBTCTurkOrderBook(CurrencyPair.BTC_TRY);
		assertThat(btcTurkBTCTurkOrderBook.getAsks().size()).isEqualTo(100); 
		assertThat(btcTurkBTCTurkOrderBook.getBids().size()).isEqualTo(100); 
	}
  
  
}

@@ -1152,16 +1152,167 @@
 ion %0A%09%7B%0A
+%09%09if(BTCTurkDemoUtilsTest.BTCTURK_APIKEY.isEmpty())%0A%09%09%09btcTurk = ExchangeFactory.INSTANCE.createExchange(BTCTurkExchange.class.getName());%0A%09%09else%0A%09%09%7B%0A%09
 %09%09Exchan
@@ -1390,32 +1390,34 @@
 ication();%0A    %09
+%09%09
 exSpec.setApiKey
@@ -1460,16 +1460,18 @@
 );%0A    %09
+%09%09
 exSpec.s
@@ -1523,26 +1523,24 @@
 ETKEY); 
-   %09
 %0A    %09
+%09%09
 btcTurk 
@@ -1590,16 +1590,20 @@
 xSpec);%0A
+%09%09%7D%0A
     %09%0A  

Update MarketDataFetchIntegrationTest.java