Skip to content

Commit

Permalink
Disable all mutable tests by default and doc nits.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpyro committed Sep 4, 2018
1 parent 80a7226 commit 100da74
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 126 deletions.
104 changes: 52 additions & 52 deletions BinanceApiTests/BinanceApiObjCTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -176,61 +176,61 @@ - (void)testAllBookTickers {
[self waitForExpectations:@[expectation] timeout:self.timeout];
}

- (void)testTestNewOrder {
NSString *symbol = @"ETHBTC";
NSDecimalNumber *quantity = [NSDecimalNumber decimalNumberWithString:@"1.0"];

XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"all book tickers"];

BinanceApi *api = [[BinanceApi alloc] initWithApiKey:self.apiKey secretKey:self.secretKey];
[api testNewOrderWithSymbol:symbol side:BinanceOrderSide.Buy type:BinanceOrderType.Market timeInForce:nil quantity:quantity price:nil newClientOrderId:nil stopPrice:nil icebergQuantity:nil responseHandler:^(NSError * _Nullable error) {
XCTAssertNil(error);

[expectation fulfill];
}];

[self waitForExpectations:@[expectation] timeout:self.timeout];
}

- (void)testQueryOrder {
XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"query order"];

BinanceApi *api = [[BinanceApi alloc] initWithApiKey:self.apiKey secretKey:self.secretKey];
[api queryOrderWithSymbol:self.querySymbol orderId:self.queryOrderId originalClientOrderId:nil responseHandler:^(NSDictionary<NSString *,id> * _Nullable result, NSError * _Nullable error) {
XCTAssertNil(error);
XCTAssert(result);

XCTAssert([(NSString *)[result valueForKey:@"symbol"] isEqualToString:self.querySymbol]);
XCTAssertEqual([(NSNumber *)[result valueForKey:@"orderId"] unsignedLongLongValue], self.queryOrderId);

NSLog(@"%@: %@", [result valueForKey:@"symbol"], [result valueForKey:@"status"]);

[expectation fulfill];
}];

[self waitForExpectations:@[expectation] timeout:self.timeout];
}


- (void)testCancelOrder {
NSString *symbol = @"BNBETH";
UInt64 orderId = 10000;

XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"cancel order"];

BinanceApi *api = [[BinanceApi alloc] initWithApiKey:self.apiKey secretKey:self.secretKey];
[api cancelOrderWithSymbol:symbol orderId:orderId originalClientOrderId:nil newClientOrderId:nil responseHandler:^(NSDictionary<NSString *,id> * _Nullable result, NSError * _Nullable error) {
XCTAssertNil(error);
XCTAssert(result);
//- (void)testTestNewOrder {
// NSString *symbol = @"ETHBTC";
// NSDecimalNumber *quantity = [NSDecimalNumber decimalNumberWithString:@"1.0"];
//
// XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"all book tickers"];
//
// BinanceApi *api = [[BinanceApi alloc] initWithApiKey:self.apiKey secretKey:self.secretKey];
// [api testNewOrderWithSymbol:symbol side:BinanceOrderSide.Buy type:BinanceOrderType.Market timeInForce:nil quantity:quantity price:nil newClientOrderId:nil stopPrice:nil icebergQuantity:nil responseHandler:^(NSError * _Nullable error) {
// XCTAssertNil(error);
//
// [expectation fulfill];
// }];
//
// [self waitForExpectations:@[expectation] timeout:self.timeout];
//}

UInt64 orderId = [[result valueForKey:@"orderId"] unsignedLongLongValue];
NSLog(@"Cancelled order %llu", orderId);
//- (void)testQueryOrder {
// XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"query order"];
//
// BinanceApi *api = [[BinanceApi alloc] initWithApiKey:self.apiKey secretKey:self.secretKey];
// [api queryOrderWithSymbol:self.querySymbol orderId:self.queryOrderId originalClientOrderId:nil responseHandler:^(NSDictionary<NSString *,id> * _Nullable result, NSError * _Nullable error) {
// XCTAssertNil(error);
// XCTAssert(result);
//
// XCTAssert([(NSString *)[result valueForKey:@"symbol"] isEqualToString:self.querySymbol]);
// XCTAssertEqual([(NSNumber *)[result valueForKey:@"orderId"] unsignedLongLongValue], self.queryOrderId);
//
// NSLog(@"%@: %@", [result valueForKey:@"symbol"], [result valueForKey:@"status"]);
//
// [expectation fulfill];
// }];
//
// [self waitForExpectations:@[expectation] timeout:self.timeout];
//}

[expectation fulfill];
}];

[self waitForExpectations:@[expectation] timeout:self.timeout];
}
//- (void)testCancelOrder {
// NSString *symbol = @"BNBETH";
// UInt64 orderId = 10000;
//
// XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"cancel order"];
//
// BinanceApi *api = [[BinanceApi alloc] initWithApiKey:self.apiKey secretKey:self.secretKey];
// [api cancelOrderWithSymbol:symbol orderId:orderId originalClientOrderId:nil newClientOrderId:nil responseHandler:^(NSDictionary<NSString *,id> * _Nullable result, NSError * _Nullable error) {
// XCTAssertNil(error);
// XCTAssert(result);
//
// UInt64 orderId = [[result valueForKey:@"orderId"] unsignedLongLongValue];
// NSLog(@"Cancelled order %llu", orderId);
//
// [expectation fulfill];
// }];
//
// [self waitForExpectations:@[expectation] timeout:self.timeout];
//}


- (void)testOpenOrders {
Expand Down
145 changes: 72 additions & 73 deletions BinanceApiTests/BinanceApiTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class BinanceApiTests: XCTestCase {
}

func testSignature() {
// let apiKey = "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A"
let secretKey = "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"
let message = "symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559"

Expand Down Expand Up @@ -197,80 +196,80 @@ class BinanceApiTests: XCTestCase {
}
}

/*func testNewOrder() {
let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey)
let symbol = "ETHBTC"
let request = BinanceNewOrderRequest(
symbol: symbol,
side: .sell,
type: .limit,
quantity: Decimal(string: "0.001")!,
price: Decimal(string: "1.1")!, timeInForce: .goodTilCancelled)

asyncTest("new order") { (expectation) in
api.send(request) { response in
XCTAssertTrue(response.result.isSuccess)
XCTAssertNotNil(response.result.value)
let value = response.result.value!
XCTAssertEqual(value.symbol, symbol)
print("Created new order #\(value.orderId)")
expectation.fulfill()
}
}
}*/

func testTestNewOrder() {
let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey)
let symbol = "ETHBTC"
let request = BinanceTestNewOrderRequest(
symbol: symbol,
side: .buy,
type: .market,
quantity: Decimal(string: "1.1")!)

asyncTest("test new order") { (expectation) in
api.send(request) { response in
XCTAssertTrue(response.result.isSuccess)
XCTAssertNotNil(response.result.value)
let _ = response.result.value!
expectation.fulfill()
}
}
}

func testQueryOrder() {
let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey)
let request = BinanceQueryOrderRequest(symbol: self.querySymbol, orderId: self.queryOrderId)

asyncTest("query order") { (expectation) in
api.send(request) { response in
XCTAssertTrue(response.result.isSuccess)
XCTAssertNotNil(response.result.value)
let order = response.result.value!
print(order)
expectation.fulfill()
}
}
}
// func testNewOrder() {
// let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey)
// let symbol = "ETHBTC"
// let request = BinanceNewOrderRequest(
// symbol: symbol,
// side: .sell,
// type: .limit,
// quantity: Decimal(string: "0.001")!,
// price: Decimal(string: "1.1")!, timeInForce: .goodTilCancelled)
//
// asyncTest("new order") { (expectation) in
// api.send(request) { response in
// XCTAssertTrue(response.result.isSuccess)
// XCTAssertNotNil(response.result.value)
// let value = response.result.value!
// XCTAssertEqual(value.symbol, symbol)
// print("Created new order #\(value.orderId)")
// expectation.fulfill()
// }
// }
// }

/*func testCancelOrder() {
let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey)
let symbol = "ETHBTC"
let orderId = UInt64(11691907)
let request = BinanceCancelOrderRequest(symbol: symbol, orderId: orderId)
// func testTestNewOrder() {
// let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey)
// let symbol = "ETHBTC"
// let request = BinanceTestNewOrderRequest(
// symbol: symbol,
// side: .buy,
// type: .market,
// quantity: Decimal(string: "1.1")!)
//
// asyncTest("test new order") { (expectation) in
// api.send(request) { response in
// XCTAssertTrue(response.result.isSuccess)
// XCTAssertNotNil(response.result.value)
// let _ = response.result.value!
// expectation.fulfill()
// }
// }
// }

asyncTest("cancel order") { (expectation) in
api.send(request) { response in
XCTAssertTrue(response.result.isSuccess)
XCTAssertNotNil(response.result.value)
let value = response.result.value!
XCTAssertEqual(value.symbol, symbol)
XCTAssertEqual(value.orderId, orderId)
print("Cancelled order #\(value.orderId)")
expectation.fulfill()
}
}
}*/
// func testQueryOrder() {
// let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey)
// let request = BinanceQueryOrderRequest(symbol: self.querySymbol, orderId: self.queryOrderId)
//
// asyncTest("query order") { (expectation) in
// api.send(request) { response in
// XCTAssertTrue(response.result.isSuccess)
// XCTAssertNotNil(response.result.value)
// let order = response.result.value!
// print(order)
// expectation.fulfill()
// }
// }
// }
//
// func testCancelOrder() {
// let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey)
// let symbol = "ETHBTC"
// let orderId = UInt64(11691907)
// let request = BinanceCancelOrderRequest(symbol: symbol, orderId: orderId)
//
// asyncTest("cancel order") { (expectation) in
// api.send(request) { response in
// XCTAssertTrue(response.result.isSuccess)
// XCTAssertNotNil(response.result.value)
// let value = response.result.value!
// XCTAssertEqual(value.symbol, symbol)
// XCTAssertEqual(value.orderId, orderId)
// print("Cancelled order #\(value.orderId)")
// expectation.fulfill()
// }
// }
// }

func testOpenOrders() {
let api = BinanceApi(apiKey: self.apiKey, secretKey: self.secretKey)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,4 @@ api.send(request) { response in

## Testing & Examples

Both an Objective-C and Swift test suite are included. You can use the test code as an example for integration this library. You will need to insert your own apikey, secretkey, and order to query to test the signed endpoints. The new order (not the test version) and cancel order endpoints in the test suite *will* execute on the market but are disabled by default.
Both an Objective-C and Swift test suite are included. You can use the test code as an example for integration this library. You will need to insert your own `apiKey`, `secretKey`, and `orderId` to query to test the signed endpoints. Mutable tests are commented (disabled) by default. You should disable withdrawal and optionally trading access for the API key before using it. You should also revoke the API key when you are done testing.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
* Remove the need for an `elements` ivar in array responses that are transformed into dicts.
* Add dSYM files for debugging
* Add CI support
* Injectable API credential secrets for testing

0 comments on commit 100da74

Please sign in to comment.