Skip to content
This repository has been archived by the owner on Oct 26, 2021. It is now read-only.

Poloniex Integration #60

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 110 additions & 28 deletions BalanceOpen.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
version = "1.3">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
Expand Down Expand Up @@ -33,11 +33,15 @@
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D8D54441EEB12360060FCCF"
BlueprintIdentifier = "2DF76CDC1F212F6F00EE18BB"
BuildableName = "BalanceOpenTests.xctest"
BlueprintName = "BalanceOpenTests"
ReferencedContainer = "container:BalanceOpen.xcodeproj">
</BuildableReference>
<LocationScenarioReference
identifier = "com.apple.dt.IDEFoundation.CurrentLocationScenarioIdentifier"
referenceType = "1">
</LocationScenarioReference>
</TestableReference>
</Testables>
<MacroExpansion>
Expand Down
13 changes: 2 additions & 11 deletions BalanceOpen/Data Model/API Models/CoinbaseAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@

import Foundation

fileprivate var decimalFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.generatesDecimalNumbers = true
formatter.numberStyle = .decimal
formatter.allowsFloats = true
formatter.locale = Locale(identifier: "en_US")
return formatter
}()

fileprivate var jsonDateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
Expand Down Expand Up @@ -47,13 +38,13 @@ struct CoinbaseAccount {
let balanceDict: [String: AnyObject] = try checkType(account, name: "balance")
self.currency = try checkType(balanceDict, name: "currency")
let balanceAmount: String = try checkType(balanceDict, name: "amount")
let balanceAmountDecimal = decimalFormatter.number(from: balanceAmount)?.decimalValue
let balanceAmountDecimal = NumberUtils.decimalFormatter.number(from: balanceAmount)?.decimalValue
self.balance = try checkType(balanceAmountDecimal, name: "balanceAmountDecimal")

let nativeBalanceDict: [String: AnyObject] = try checkType(account, name: "native_balance")
self.nativeCurrency = try checkType(nativeBalanceDict, name: "currency")
let nativeBalanceAmount: String = try checkType(nativeBalanceDict, name: "amount")
let nativeBalanceAmountDecimal = decimalFormatter.number(from: nativeBalanceAmount)?.decimalValue
let nativeBalanceAmountDecimal = NumberUtils.decimalFormatter.number(from: nativeBalanceAmount)?.decimalValue
self.nativeBalance = try checkType(nativeBalanceAmountDecimal, name: "balanceAmountDecimal")

// TODO: Finish this
Expand Down
4 changes: 2 additions & 2 deletions BalanceOpen/Data Model/API Models/CoinbaseApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ struct CoinbaseApi {
for ca in coinbaseAccounts {
// Calculate the number of decimals
var decimals = 2
if let currency = Currency(rawValue: ca.currency) {
if let currency = Currency.rawValue(currency: ca.currency) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the chance in syntax here? Swift 4 thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created my own method for raw value.
Since we have two enums, one is nested and the other is an attributed type.
Just tried to be similar than what we had before :)

decimals = currency.decimals
}

var altDecimals = 2
if let altCurrency = Currency(rawValue: ca.nativeCurrency) {
if let altCurrency = Currency.rawValue(currency: ca.nativeCurrency) {
altDecimals = altCurrency.decimals
}

Expand Down
35 changes: 35 additions & 0 deletions BalanceOpen/Data Model/API Models/PoloniexAccount.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// PoloniexAccount.swift
// BalanceOpen
//
// Created by Raimon Lapuente on 28/07/2017.
// Copyright © 2017 Balanced Software, Inc. All rights reserved.
//

import Foundation

struct PoloniexAccount {
let type: AccountType

let currency: String
let available: Decimal
let onOrders: Decimal
let btcValue: Decimal

init(dictionary:[String:AnyObject],currency:String, type: AccountType) throws {
self.type = type
self.currency = currency
let availableAmount: String = try checkType(dictionary, name: "available")
let availableDecimal = NumberUtils.decimalFormatter.number(from: availableAmount)?.decimalValue
self.available = try checkType(availableDecimal, name: "availableDecimal")

let onOrdersAmount: String = try checkType(dictionary, name: "onOrders")
let onOrdersdecimal = NumberUtils.decimalFormatter.number(from: onOrdersAmount)?.decimalValue
self.onOrders = try checkType(onOrdersdecimal, name: "onOrdersdecimal")

let btcValueAmount: String = try checkType(dictionary, name: "btcValue")
let btcValueDecimal = NumberUtils.decimalFormatter.number(from: btcValueAmount)?.decimalValue
self.btcValue = try checkType(btcValueDecimal, name: "btcValueDecimal")
}

}
Loading