This link also includes basic Python understandings and guide to run a Python script, you should get yourself familiar with these concepts before moving forward.

3. Install Gatecoin Python library

Install the library by entering pip3 install gatecoin_api in terminal/command prompt, refer to the link in step 2 above if you are not sure what to do.

4. Get your API keys

Login to your Gatecoin account, go to API page by clicking your name at the top right corner →API. Name your key, uncheck “Read only” and tick “Trade” under Key Permission session, and click “Generate” (Do not tick Allow Withdrawal if you don’t want to bear unnecessary risks).

Keep a safe copy of your generated key pairs.

5. Code — Getting data and configuring logics

Now lets set the ball rolling. With your favorite editor, type:

from gatecoin_api import GatecoinAPI

import time api = GatecoinAPI() api.set_credentials('YOUR_PRIVATE_KEY', 'YOUR_PUBLIC_KEY')

With the above we are importing the Gatecoin library, the time library, and setting up your credentials. And yes you would have to replace the Private & Public key fields with your own keys generated in Step 4 above.

Then lets checkout the price on the orderbook:

orderbook = api.get_order_book("BTCUSD")

top_bid = orderbook.bids[0].price

top_ask = orderbook.asks[0].price

print("Top bid and ask:", top_bid,top_ask)

We get the whole BTCUSD orderbook, store it in the variable “orderbook”, extract the top bid and ask and store them into “top_bid” and “top_ask” variables respectively, then print them out.

Run your script, you should see the top bid and ask.

Next we move to balance checking, run your script with the below code and you should see your USD balance:

balance_USD = api.get_balance('USD').balance.available_balance

print("My USD balance:", balance_USD)

Now lets specify some trade logics, lets say I want to buy BTC only when 1.) I have more than 100 USD in my account, and 2.) The top ask price is less than 6000

if (balance_USD > 100 and top_ask < 6000):

print ("The time is now!!")

api.create_order(currency_pair="BTCUSD", order_way="Bid", price=5900, amount=0.001)

else:

print("Patience...")

If the conditions are met, the script will place a buy order of 0.001 BTC at the price of 5900 with the above code.

6. Code — Putting everything together

As you might have noticed, with the code above, the script will stop after going through each line once. To make it run endlessly, put your code inside a while loop, and it’s gonna run again and again:

Here there’s a new line of code time.sleep(5) , what it does is simply putting the script to sleep for 5 seconds, before running everything in the while loop all over again.

Run the script and you should see something like this:

To stop it, press Ctrl + c

Shouldn’t be too overwhelming isn’t it?

I have also included a list of other useful methods above in the form of a comment (All those starting with #), pick the ones useful to you, remove the # and try them out.

For the public methods, you can call them even without setting up an API key, and there is no rate limit

For the private methods, you must first setup your API keys, and there are rate limits

Example, from the link above, Gatecoin allows a maximum of 30 calls per minute for getting “Balance”. That means you can most frequently get your updated account balance every 2 seconds

For security reasons, it is common for crypto exchanges to impose a rate limit for private method calls. Make sure you do not exceed the limit, or else you risk your IP being banned by the exchange.