Comments (28)
@irufus I figured out the first part. Just had to add the package name for the component scan in my spring boot project. Still checking on How do I pass the API key and secret. Please let me know if there's a way.
from gdax-java.
@irufus I am using this jar in my Android application but getting nullpointexception even using the Autowired with accountService and component with Activity class. Could you please let me know what additional I need to do here for running this jar in Android project?
from gdax-java.
Looks like you're trying to develop outside the application, but this is not how the codebase is currently set up to work. The code base relies on Spring Boot. Spring boot is a framework to develop your application within.
The gdax-java application is a (self contained) application. All you have to do is fork the code base, supply your api credentials (do not commit them), then write your application code on top of/within of it.
So for what you're trying to do you need to declare your class Test as a @component so that spring knows it should create an instance available for use from the Spring Context. Then when other classes want a reference to it, they simply annotate their field/constructor with @Autowired.
import com.coinbase.exchange.api.accounts.Account;
import com.coinbase.exchange.api.accounts.AccountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class Test {
private static final Logger log = LoggerFactory.getLogger(Test.class);
@Autowired
private AccountService accountService;
public List<Account> main(String[] args) {
List<Account> accounts = accountService.getAccounts();
System.out.println("TEST: " + accounts);
return accounts;
}
}
If you need anything more try looking at the classes named *Service as they all follow much the same pattern.
from gdax-java.
Awesome -- Thanks @robevansuk and @irufus !
from gdax-java.
Nevermind. I got it working, just had to give the properties in my application.properties file and autowire GdaxImplementationa and Signature classes in my controller.
from gdax-java.
For examples please see - https://github.com/robevansuk/gdax-java/blob/master/CONTRIBUTE.md Where I've done what I can to provide examples.
The GUI package provides working examples.
My repo is not quite ready to merge into this as I'm building a desktop app on this API. You can see a screen shot in the gitter channel. But there's still a lot of hooking up to do and a number more features to build out.
from gdax-java.
I think an examples directory/modules should be added as: examples/
. This may help resolve the issues with lack of Spring knowledge, etc.
from gdax-java.
added one but also added a bunch of tests that show how to make various calls. These should suffice.
from gdax-java.
I'm new to Spring, I've been trying to learn about it through a number of resources however I still can't work out how to get started with this project, can you please provide a simple example such as starting up, pulling down something from the exchange and printing it to the screen without it being a "test".
from gdax-java.
Cd to the directory where you checked out the project
supply your api keys in the application.yml file (from GDAX)
./gradlew bootRun
That should be it. Get back if you need more info - I'll update the read me some time soon
from gdax-java.
There's no application.yml file present in the repository so I am not sure what is the structure of that file. Can you elaborate please?
from gdax-java.
Its right here: https://github.com/irufus/gdax-java/blob/master/src/main/resources/application.yml
from gdax-java.
It is a bit confusing for me due to the lack of examples, but I wanted to ask you that to make a simple order all you need is 1) Update the application.yml to use your keys 2) initialize an OrderService: (new OrderService();) 3) use the createOrder() method 4) execute with Gradle
I have been trying to build a jar file to use as a library in my project, but it is not successful:
https://stackoverflow.com/questions/45787085/implementation-of-gdax-java-as-a-library
Do you think you could guide me to any examples on implementation?
from gdax-java.
That sounds about right.
I've matched almost exactly the API structure from the documentation here: https://docs.gdax.com/#api
Here are some examples which I'll be adding to the README shortly.
AccountService.getAccounts()
- returns an array of all AccountsAccountService.getAccountHistory(String accountId)
- returns the history for a given accountAccountService.getHolds(String accountId)
- returns an array of all held funds for a given account.DepositService.depositViaPaymentMethod(BigDecimal amount, String currency, String paymentMethodId)
- makes a deposit from a stored payment method into your GDAX accountDepositService.coinbaseDeposit(BigDecimal amount, String currency, String coinbaseAccountId)
- makes a deposit from a coinbase account into your GDAX accountMarketDataService.getMarketDataOrderBook(String productId, String level)
- a call to ProductService.getProducts() will return the order book for a given product. You can then use the WebsocketFeed api to keep your orderbook up to date. This is implemented in this codebase.OrderService.getOpenOrders(String accountId)
- returns an array of Orders for any outstanding ordersOrderService.cancelOrder(String orderId)
- cancels a given orderOrderService.createOrder(NewOrderSingle aSingleOrder)
- construct an order and send it to this method to place an order for a given product on the exchange.
from gdax-java.
As I forked from this repo originally I've made efforts to keep the original repo up to date but inevitably my own version of this repo is more up to date at present.. watch this space: https://github.com/robevansuk/gdax-java
from gdax-java.
I read your instructions to compile a jar file to use as a library in my own project. However, when I run the ./gradlew jar I don't get a jar file in the build folder. Am I missing anything besides updating the application.yml?
from gdax-java.
trying to keep this as simple as possible, after having entered the key, secret and passphrase into the application.yml file I've entered these lines into the main method of GdaxApiApplication:
AccountService accountService = new AccountService();
Account[] accounts = accountService.getAccounts();
however I get a java.lang.NullPointerException and I don't understand why, can you please explain,
thanks in advance.
from gdax-java.
What is the full stack trace that came with the exception?
from gdax-java.
Exception in thread "main" java.lang.NullPointerException
at com.coinbase.exchange.api.accounts.AccountService.getAccounts(AccountService.java:24)
at com.coinbase.exchange.api.GdaxApiApplication.main(GdaxApiApplication.java:27)
(GdaxApiApplication.java:27) is when I call Account[] accounts = accountService.getAccounts();
I have made no changes to AccountService.java
Edit:
I was able to determine that the
@Autowired GdaxExchange exchange;
is the null element here.
To keep things very simple, from the main method, using Spring, how do I get to run accountService.getAccounts()
?
from gdax-java.
If the GdaxExchange is null then something is likely to be wrong with the configuration. Have you tried debugging what happens when the AccountService makes a get request and attempts to sign the request?
debug on this line - it seems likely the securityHeaders are not correct.
ResponseEntity responseEntity = restTemplate.exchange(getBaseUrl() + resourcePath,
GET,
securityHeaders(resourcePath,
"GET",
""),
responseType);
from gdax-java.
Can someone provide a simple class with a main function that, for instance, shows the BTC balance? I'm getting a NullPointerException
when I try something as simple as this:
import com.coinbase.exchange.api.accounts.AccountService;
public class Test {
public static void main(String[] args) {
new AccountService().getAccounts();
}
}
from gdax-java.
Just a side note. I am working on a side project that utilizes gdax as a library. Once I figure out how to streamline the process of rigging it I will add this information to usage examples.
from gdax-java.
@irufus I see that the code is supposed to be built on top of this current project. But two quick questions. Can I use the jar built from the project and use it in my existing spring boot project?
I tried it, the autowire to Accountservice is not getting reflected at Spring start time. Also, How would you set the API key/secret if you are using this as a jar? Appreciate any thoughts.
from gdax-java.
Can you provide a stack trace/some more details?
from gdax-java.
@robevansuk, can you please show, how to execute the https://github.com/irufus/gdax-java/issues/2#issuecomment-345699316 code using SpringBoot? I am not familiar with Spring. I tried to run it as main and as Spring application, but I still got the nullpointer on accountService.
from gdax-java.
Let me know if this was any good for you as its still open to improvements and your feedback will no doubt help others.
from gdax-java.
Yes, your link (and you forked repo version) helped me lot and it is best help for those who never encountered with Spring Boot. The problem was that I didn't know how to run SpringBoot main method.
@irufus I think, you should have CONTRIBUTE in this repository or at least put a link to robevansuk's examples to README.
from gdax-java.
Great. There is a ticket for the Contribute.MD @irufus already raised I just haven't merged anything back yet - it'll get merged eventually into this repo - a few weeks/couple of months away with any luck.
./gradle bootRun
will run the application with whatever config is in the application.yml
. Or you can just run the main method within your IDE and the same thing will happen.
The intention is to merge my entire repo back to this one in the coming weeks/month or two as I'm working on a desktop application that should largely mirror the web-interface version. This will then be extended over time to provide some extra stats with any luck to help decision making. Hopefully others will also contribute over time too.
from gdax-java.
Related Issues (20)
- Recommend using Lombok for Data Transfer Objects, and toString methods in each DTO HOT 2
- SEVERE: CancelAllOrders worked even with a VIEW ONLY API key HOT 5
- GDAX credensials generates: forbidden error HOT 10
- Is it possible to get the network transaction and address hash for crypto deposits? HOT 2
- Websocket is not working with the sandbox environment HOT 3
- Getting {"message":"request timestamp expired"} on POST message HOT 2
- Time issue HOT 1
- what's your plan on orderbook? HOT 2
- gdax-java project rename to coinbasepro-java HOT 1
- Cloudflare Blocking access: "User-Agent" needs to be added to the header HOT 2
- Split gdax-java into library and client HOT 14
- OrderService.getAllFills fails due to API change - Requests without either order_id or product_id will be rejected after 8/23/18. HOT 2
- Syntax error on WebsocketFeed HOT 2
- Deprecated API in OrderTests HOT 2
- Any plans to get this project on Maven Central? HOT 1
- ./gradlew build Errors Execution failed for task ':model:compileJava'. > Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)' HOT 2
- Gradlew jar. Could not resolve central.maven.org
- Error while extracting response for type [class [Lcom.coinbase.exchange.model.Product;] ... max_market_funds HOT 1
- Problem with Jar
- Api
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gdax-java.