Skip to content

Commit

Permalink
add haobtc exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
philsong committed Jun 2, 2016
1 parent 81d40a4 commit bc84f69
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ It requires OS X 10.7+ and a 64-bit processor.

## Changelog

### 2.8.0
* Add haobtc exchange price

### 2.7.0
* Add the Yunbi and Poloniex ETH price.

Expand Down Expand Up @@ -100,4 +103,4 @@ The source is provided for inspection, considering the nature of Bitcoin. You ar

If for some reason you feel like donating a few micro btc to future development, those should go here:

`1D3NtjVFpoXonqk3MZwsYD9iV5WA7MRXUj`
`1D3NtjVFpoXonqk3MZwsYD9iV5WA7MRXUj`
2 changes: 1 addition & 1 deletion btcbar/Fetchers/HaobtcCNYFetcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ - (id)init
self.ticker_menu = @"Haobtc";

// Website location
self.url = @"https://haobtc.com/exchange/main?from=1NDnnWCUu926z4wxA3sNBGYWNQD3mKyes8";
self.url = @"http://k.sosobtc.com/btc_haobtc.html?from=1NDnnWCUu926z4wxA3sNBGYWNQD3mKyes8?from=1NDnnWCUu926z4wxA3sNBGYWNQD3mKyes8";

// Immediately request first update
[self requestUpdate];
Expand Down
20 changes: 20 additions & 0 deletions btcbar/Fetchers/HaobtcInstantCNYFetcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// HuobiCNYFetcher.h
// btcbar
//
// Created by lwei on 2/13/14.
// Copyright (c) 2014 nearengine. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Fetcher.h"

@interface HaobtcInstantCNYFetcher : NSObject<Fetcher, NSURLConnectionDelegate>

@property (nonatomic) NSString* ticker;
@property (nonatomic) NSString* ticker_menu;
@property (nonatomic) NSString* url;
@property (nonatomic) NSError* error;
@property (nonatomic) NSMutableData *responseData;

@end
130 changes: 130 additions & 0 deletions btcbar/Fetchers/HaobtcInstantCNYFetcher.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
//
// HuobiCNYFetcher.m
// btcbar
//
// Created by lwei on 2/13/14.
// Copyright (c) 2014 nearengine. All rights reserved.
//

#import "HaobtcInstantCNYFetcher.h"

@implementation HaobtcInstantCNYFetcher

- (id)init
{
if (self = [super init])
{
// Menu Item Name
self.ticker_menu = @"Haobtc Benchmark";

// Website location
self.url = @"https://haobtc.com/?from=1NDnnWCUu926z4wxA3sNBGYWNQD3mKyes8";

// Immediately request first update
[self requestUpdate];
}

return self;
}

// Override Ticker setter to trigger status item update
- (void)setTicker:(NSString *)tickerString
{
// Update the ticker value
_ticker = tickerString;

// Trigger notification to update ticker
[[NSNotificationCenter defaultCenter] postNotificationName:@"btcbar_ticker_update" object:self];
}

// Initiates an asyncronous HTTP connection
- (void)requestUpdate
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://haobtc.com/api/v1/price/cny"]];

// Set the request's user agent
[request addValue:@"btcbar/2.0 (HaobtcCNYFetcher)" forHTTPHeaderField:@"User-Agent"];

// Initialize a connection from our request
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

// Go go go
[connection start];
}

// Initializes data storage on request response
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
self.responseData = [[NSMutableData alloc] init];
}

// Appends response data
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.responseData appendData:data];
}

// Indiciate no caching
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse
{
return nil;
}

// Parse data after load
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *responseStr = [[NSString alloc] initWithData:self.responseData encoding:NSUTF8StringEncoding];
if (!responseStr) {
return;
}

// Parse the JSON into results
NSError *jsonParsingError = nil;
id results = [NSJSONSerialization JSONObjectWithData:[responseStr dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:&jsonParsingError];

// Results parsed successfully from JSON
if (results)
{
NSString *sell_price = [results objectForKey:@"buy"];
NSString *buy_price = [results objectForKey:@"sell"];
if (sell_price && buy_price) {
// NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
// NSString *resultsStatus = [numberFormatter stringFromNumber:sell_price];
// resultsStatus = [NSString stringWithFormat:@"¥%@", resultsStatus];
//
// self.error = nil;
// self.ticker = resultsStatus;

NSString *sell_price_str = [NSString stringWithFormat:@"/%@",sell_price];
NSString *buy_price_str = [NSString stringWithFormat:@"¥%@",buy_price];

NSString *resultsStatus = [buy_price_str stringByAppendingString:sell_price_str];

NSLog(resultsStatus,nil);

self.ticker = resultsStatus;

}
// Otherwise log an error...
else
{
self.error = [NSError errorWithDomain:@"com.nearengine.btcbar" code:0 userInfo:[NSDictionary dictionaryWithObjectsAndKeys: @"API Error", NSLocalizedDescriptionKey, @"The JSON received did not contain a result or the API returned an error.", NSLocalizedFailureReasonErrorKey, nil]];
self.ticker = nil;
}
}
// JSON parsing failed
else
{
self.error = [NSError errorWithDomain:@"com.nearengine.btcbar" code:0 userInfo:[NSDictionary dictionaryWithObjectsAndKeys: @"JSON Error", NSLocalizedDescriptionKey, @"Could not parse the JSON returned.", NSLocalizedFailureReasonErrorKey, nil]];
self.ticker = nil;
}
}

// HTTP request failed
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
self.error = [NSError errorWithDomain:@"com.nearengine.btcbar" code:0 userInfo:[NSDictionary dictionaryWithObjectsAndKeys: @"Connection Error", NSLocalizedDescriptionKey, @"Could not connect to Haobtc.", NSLocalizedFailureReasonErrorKey, nil]];
self.ticker = nil;
}

@end
4 changes: 2 additions & 2 deletions btcbar/btcbar-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.7.0</string>
<string>2.8.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>8</string>
<string>9</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.finance</string>
<key>LSMinimumSystemVersion</key>
Expand Down

0 comments on commit bc84f69

Please sign in to comment.