Giter Site home page Giter Site logo

GDAX usage examples about gdax-java HOT 28 OPEN

irufus avatar irufus commented on September 4, 2024
GDAX usage examples

from gdax-java.

Comments (28)

venkateshthallam avatar venkateshthallam commented on September 4, 2024 2

@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.

sunnyaditya avatar sunnyaditya commented on September 4, 2024 2

@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.

robevansuk avatar robevansuk commented on September 4, 2024 1

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.

mossaab0 avatar mossaab0 commented on September 4, 2024 1

Awesome -- Thanks @robevansuk and @irufus !

from gdax-java.

venkateshthallam avatar venkateshthallam commented on September 4, 2024 1

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.

robevansuk avatar robevansuk commented on September 4, 2024 1

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.

robevansuk avatar robevansuk commented on September 4, 2024 1

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.

robevansuk avatar robevansuk commented on September 4, 2024

added one but also added a bunch of tests that show how to make various calls. These should suffice.

from gdax-java.

biroshima avatar biroshima commented on September 4, 2024

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.

robevansuk avatar robevansuk commented on September 4, 2024

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.

genesiscz avatar genesiscz commented on September 4, 2024

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.

robevansuk avatar robevansuk commented on September 4, 2024

Its right here: https://github.com/irufus/gdax-java/blob/master/src/main/resources/application.yml

from gdax-java.

pablof300 avatar pablof300 commented on September 4, 2024

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.

robevansuk avatar robevansuk commented on September 4, 2024

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 Accounts
  • AccountService.getAccountHistory(String accountId) - returns the history for a given account
  • AccountService.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 account
  • DepositService.coinbaseDeposit(BigDecimal amount, String currency, String coinbaseAccountId) - makes a deposit from a coinbase account into your GDAX account
  • MarketDataService.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 orders
  • OrderService.cancelOrder(String orderId) - cancels a given order
  • OrderService.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.

robevansuk avatar robevansuk commented on September 4, 2024

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.

pablof300 avatar pablof300 commented on September 4, 2024

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.

biroshima avatar biroshima commented on September 4, 2024

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.

irufus avatar irufus commented on September 4, 2024

What is the full stack trace that came with the exception?

from gdax-java.

biroshima avatar biroshima commented on September 4, 2024
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.

robevansuk avatar robevansuk commented on September 4, 2024

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.

mossaab0 avatar mossaab0 commented on September 4, 2024

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.

irufus avatar irufus commented on September 4, 2024

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.

venkateshthallam avatar venkateshthallam commented on September 4, 2024

@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.

robevansuk avatar robevansuk commented on September 4, 2024

Can you provide a stack trace/some more details?

from gdax-java.

mohwald avatar mohwald commented on September 4, 2024

@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.

robevansuk avatar robevansuk commented on September 4, 2024

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.

mohwald avatar mohwald commented on September 4, 2024

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.

robevansuk avatar robevansuk commented on September 4, 2024

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 Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.