Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have created an API. the purpose of the API is to recieve the different currency rates in the international market after each and every second. this currency rates changing feed comes from a website named http://forexfeed.net/.
now this website gives a piece of code to put it my API in order to recieve the feeds. But i m not understanding where to put this code and is there any need of change in it? please please help me. m very tens abt it. this is my first assignment of my job please help me. the code is given below.
this code is also available on http://forexfeed.net/developer/dot-net-forex-data-feed-api[^]
using System;
using System.Collections;

// Load the ForexFeed.net API
using forexfeed.net;

class ForexFeedExample {

  //  ------------------------------------------
  //  EDIT THE FOLLOWING VARIABLES
  // 
  private static string access_key = "YOUR_ACCESS_KEY";
  private static string symbol = "EURUSD,GBPUSD,USDCHF,USDCAD,AUDUSD";
  private static int interval = 3600;
  private static int periods = 1;
  private static string price = "mid";
 
  //  END VARIABLES
  //  ------------------------------------------
  // 

  //  ------------------------------------------
  //  Main
  // 
  static void Main() {
  //  Create the ForexFeed Object
  feedapi fxfeed = new feedapi(access_key, symbol, interval, periods, price);

  //  Display the Quotes
  printData(fxfeed);
  //  Display the available Intervals
  printIntervals(fxfeed);
  //  Display the available Symbols
  printSymbols(fxfeed);

  }


  // '' 
  // ''  Get the data and print it to System.out
  // '' 
  private static void printData(feedapi fxfeed) {
  // 
  //  Fetch the Data
  // 
  ArrayList quotes = fxfeed.getData();
  Console.WriteLine("-------- Quotes --------");
  if (fxfeed.getStatus().Equals("OK")) {
  Console.WriteLine(("Number of Quotes: " + fxfeed.getNumQuotes()));
  Console.WriteLine(("Copyright: " + fxfeed.getCopyright()));
  Console.WriteLine(("Website: " + fxfeed.getWebsite()));
  Console.WriteLine(("License: " + fxfeed.getLicense()));
  Console.WriteLine(("Redistribution: " + fxfeed.getRedistribution()));
  Console.WriteLine(("AccessPeriod: " + fxfeed.getAccessPeriod()));
  Console.WriteLine(("AccessPerPeriod: " + fxfeed.getAccessPerPeriod()));
  Console.WriteLine(("AccessThisPeriod: " + fxfeed.getAccessThisPeriod()));
  Console.WriteLine(("AccessRemainingThisPeriod: " + fxfeed.getAccessPeriodRemaining()));
  Console.WriteLine(("AccessPeriodBegan: " + fxfeed.getAccessPeriodBegan()));
  Console.WriteLine(("NextAccessPeriodStarts: " + fxfeed.getAccessPeriodStarts()));

  // 
  //  Get an Iterator object for the quotes ArrayList using iterator() method.
  // 
  IEnumerator itr = quotes.GetEnumerator();

  // 
  //  Iterate through the ArrayList iterator
  // 
  Console.WriteLine("----------------------------------------");
  Console.WriteLine("Iterating through Quotes...");
  Console.WriteLine("----------------------------------------");
  while (itr.MoveNext()){
  Hashtable quote = ((Hashtable)(itr.Current));
  Console.WriteLine(("Quote Symbol: " + quote["symbol"]));
  Console.WriteLine(("Title: " + quote["title"]));
  Console.WriteLine(("Time: " + quote["time"]));

  if ((fxfeed.getInterval() == 1)) {
  if (fxfeed.getPrice().Equals("bid,ask")) {
  Console.WriteLine(("Bid: " + quote["bid"]));
  Console.WriteLine(("Ask: " + quote["ask"]));
  }
  else {
  Console.WriteLine(("Price: " + quote["price"]));
  }
  }
  else {
  Console.WriteLine(("Open: " + quote["open"]));
  Console.WriteLine(("High: " + quote["high"]));
  Console.WriteLine(("Low: " + quote["low"]));
  Console.WriteLine(("Close: " + quote["close"]));
  }
  Console.WriteLine("");
  }
  }
  else {
  Console.WriteLine(("Status: " + fxfeed.getStatus()));
  Console.WriteLine(("ErrorCode: " + fxfeed.getErrorCode()));
  Console.WriteLine(("ErrorMessage: " + fxfeed.getErrorMessage()));
  }
  }

  // '' 
  // ''  Print the Intervals to System.out
  // '' 
  private static void printIntervals(feedapi fxfeed) {
  // 
  //  Fetch the Intervals
  // 
  Hashtable intervals = fxfeed.getAvailableIntervals(false);
  Console.WriteLine("-------- Intervals --------");
  if (fxfeed.getStatus().Equals("OK")) {
  // 
  //  Get a Collection of values contained in HashMap
  // 
  ICollection c = intervals.Values;

  // 
  //  Obtain an Iterator for Collection
  // 
  IEnumerator itr = c.GetEnumerator();

  // 
  //  Iterate through the HashMap values iterator
  // 
  while (itr.MoveNext()) {
  Hashtable value = ((Hashtable)(itr.Current));
  Console.WriteLine(("Interval: " + value["interval"]));
  Console.WriteLine(("Title: " + value["title"]));
  Console.WriteLine("");
  }
  }
  else {
  Console.WriteLine(("Status: " + fxfeed.getStatus()));
  Console.WriteLine(("ErrorCode: " + fxfeed.getErrorCode()));
  Console.WriteLine(("ErrorMessage: " + fxfeed.getErrorMessage()));
  }
  }

  // '' 
  // ''  Print the Symbols to System.out
  // '' 
  private static void printSymbols(feedapi fxfeed) {
  // 
  //  Fetch the Symbols
  // 
  Hashtable symbols = fxfeed.getAvailableSymbols(false);
  Console.WriteLine("-------- Symbols --------");
  if (fxfeed.getStatus().Equals("OK")) {
  // 
  //  Get a Collection of values contained in HashMap
  // 
  ICollection c = symbols.Values;

  // 
  //  Obtain an Iterator for Collection
  // 
  IEnumerator itr = c.GetEnumerator();

  // 
  //  Iterate through the HashMap values iterator
  // 
  while (itr.MoveNext()) {
  Hashtable value = ((Hashtable)(itr.Current));
  Console.WriteLine(("Symbol: " + value["symbol"]));
  Console.WriteLine(("Title: " + value["title"]));
  Console.WriteLine(("Decimals: " + value["decimals"]));
  Console.WriteLine("");
  }
  }
  else {
  Console.WriteLine(("Status: " + fxfeed.getStatus()));
  Console.WriteLine(("ErrorCode: " + fxfeed.getErrorCode()));
  Console.WriteLine(("ErrorMessage: " + fxfeed.getErrorMessage()));
  }
  }
Posted
Updated 10-Jul-11 20:00pm
v2
Comments
Prerak Patel 11-Jul-11 2:00am    
Add pre tags for your code.

It all looks pretty obvious: that is an example program rather thane a code fragment for you to insert.
Look at it, and it is pretty clear what does what. Just put the relevent bits into your code, once you have replaced the access key with the one they gave you.
 
Share this answer
 
Comments
saifullahiit 11-Jul-11 3:01am    
sir i have the key shuld i put it and run it?
Confusion indeed. The code you are showing us is a usage sample of the API. You are not supposed to put this anywhere in your API. Also, I happened to notice that you need an access key for the service in question. You better consult the person who delegated this job to you to fork over more information, if you are not able to research it yourself.

Cheers!

—MRB
 
Share this answer
 
v2
Comments
OriginalGriff 11-Jul-11 2:15am    
Sorry Manfred - you hadn't posted when I was reading the OP question!
saifullahiit 11-Jul-11 2:59am    
sir i have the key.should i put it and run it?
OriginalGriff 11-Jul-11 3:02am    
Don't give it to us! Don't publish it anywhere!
But it wouldn't hurt to put it into the code you posted, and try running it as a console app to see it if works as is, before you start ripping it apart to build your own "real" app.
Manfred Rudolf Bihy 11-Jul-11 3:20am    
Absolutely, agreed. Publishing the access key would probably get OP into trouble :)
saifullahiit 11-Jul-11 3:01am    
sir i have the key shud i put it and run it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900