Exemplo n.º 1
0
    def closeAllPositions(self):
        #Get current open positions
        self.writeToLog("Closing all positions...")
        openPositions = FinexAPI.active_positions()
        self.writeToLog(openPositions)

        for pos in openPositions:
            id = json.loads(makeJSONReadable(str(pos)))['id']
            self.writeToLog(FinexAPI.close_position(id))

        self.writeToLog("All positions closed.")
Exemplo n.º 2
0
    def openPositionMarket(self, type, price):
        amount = (
            self.tradeableAmount / price
        ) * 0.995  #<--- gives a 0.5% buffer in case of price difference

        self.writeToLog(
            FinexAPI.place_order(str(amount),
                                 "500",
                                 type,
                                 "market",
                                 symbol=self.coinCode))
        self.writeToLog("Opened position of " + str(amount) + " at approx " +
                        str(price))
Exemplo n.º 3
0
    def getPosition(self):

        try:
            pos = makeJSONReadable(str(FinexAPI.active_positions()[0]))
            self.writeToLog(pos)
            pos = json.loads(pos)
            print pos['amount']
            if float(pos['amount']) > 0.0000001:
                self.positionType = "Long"
            elif float(pos['amount']) < -0.0000001:
                self.positionType = "Short"
        except:
            None
Exemplo n.º 4
0
    def tick(self):
        #only call API once
        try:
            self.APIlist = FinexAPI.ticker()
        except:
            try:
                time.sleep(10)
                self.APIlist = FinexAPI.ticker()
            except:
                try:
                    time.sleep(10)
                    self.APIlist = FinexAPI.ticker()
                except:
                    pass

        #date
        self.dataDate = datetime.datetime.fromtimestamp(
            int(float(
                self.APIlist["timestamp"]))).strftime('%Y-%m-%d %H:%M:%S')
        #prices
        self.currentPrice = float(self.APIlist["last_price"])
        #insert into SQL db
        self.TradeDatabase.insertStatement01(self.dataDate, self.currentPrice)
        #load datelist, prices from db
        self.datelist, self.prices = self.TradeDatabase.readtolist01()

        #indicators
        self.SMA = self.indicators.movingAverage(self.prices, 200)
        self.CResistance = self.indicators.trendline(self.prices)
        self.RSI = self.indicators.RSI(self.prices)

        #macd indicators & insert into DB
        if len(self.prices) > 26:  #get macd indicators
            emaslow, emafast, self.MACD = self.indicators.MACD(self.prices)
            self.EMA9 = self.indicators.EMA(self.MACD, 9)

        #Insert all to DB (no need for macd and ema9 - they are self generated and contained lists)
        self.TradeDatabase.insertStatement02(self.dataDate, self.CResistance,
                                             self.SMA, self.RSI)

        #graph
        #archaic : self.graphdataPoints.append({'date':self.dataDate, 'price': self.currentPrice, 'trend': self.CResistance, 'SMA': self.SMA, 'RSI':self.RSI, 'short': np.nan, 'long':np.nan,'closedLong':np.nan,'closedShort':np.nan})

        #graph with pdDataFrame obj
        self.graphdataPoints = self.TradeDatabase.frameit()

        #if/else indicators
        self.tradePlaced, self.typeOfTrade, self.cryptoAmount = self.TradeDatabase.readtolist02(
        )
        self.tradePlaced = [i for i in self.tradePlaced
                            if i * 0 == 0]  #only get the numbers
        self.typeOfTrade = [i for i in self.typeOfTrade
                            if i != None]  #only get the strings
        self.cryptoAmount = [i for i in self.cryptoAmount
                             if i * 0 == 0]  #only get the numbers

        #print timestamp and price to cmd line for logging purposes
        self.output.log(self.dataDate + "\tPrice: " + str(self.currentPrice) +
                        "\tMoving Average: " + str(self.SMA))
        #print numofwins, numofloses and cumulated profits to cmd line
        self.cumulatedProfits, self.numofwins, self.numofloses = self.TradeDatabase.cumwinloss(
        )
        self.output.log(
            "No. of Wins: {}, No. of Loses: {}, Cumulated Profits: {}".format(
                self.numofwins, self.numofloses, self.cumulatedProfits))
Exemplo n.º 5
0
#!/usr/bin/env python
import FinexAPI

myvar = FinexAPI.past_trades(0)

for obj in myvar:
    print "price: " + str(obj["price"]) + " type: " + str(obj["type"])
Exemplo n.º 6
0
#!/usr/bin/env python
import FinexAPI

print FinexAPI.active_orders()
Exemplo n.º 7
0
#!/usr/bin/env python
#Places a put and take above and below current market price
import FinexAPI

diff = 2 #The amount above or below market price you want
ticker = FinexAPI.ticker()
available = float(FinexAPI.balances()[2]["available"])
ask = float(ticker["ask"])
amount = 0.01 #Amount of BTC to place orders

marketPrice = ticker["last_price"]
buyPrice = float(marketPrice) - diff
sellPrice = float(marketPrice) + diff

print FinexAPI.place_order(str(amount), str(buyPrice), "buy", "exchange limit")
print FinexAPI.place_order(str(amount), str(sellPrice), "sell", "exchange limit")
Exemplo n.º 8
0
#!/usr/bin/env python
import FinexAPI

myvar = FinexAPI.past_trades(0)

for obj in myvar:
	print "price: " + str(obj["price"]) + " type: " + str(obj["type"])
Exemplo n.º 9
0
#!/usr/bin/env python
import FinexAPI

print (FinexAPI.symbols())
Exemplo n.º 10
0
#!/usr/bin/env python
import FinexAPI

print FinexAPI.balances()
Exemplo n.º 11
0
#!/usr/bin/env python
import FinexAPI

print FinexAPI.delete_all_order()
Exemplo n.º 12
0
#!/usr/bin/env python
#Places a put and take above and below current market price
import FinexAPI

diff = 2  #The amount above or below market price you want
ticker = FinexAPI.ticker()
available = float(FinexAPI.balances()[2]["available"])
ask = float(ticker["ask"])
amount = 0.01  #Amount of BTC to place orders

marketPrice = ticker["last_price"]
buyPrice = float(marketPrice) - diff
sellPrice = float(marketPrice) + diff

print FinexAPI.place_order(str(amount), str(buyPrice), "buy", "exchange limit")
print FinexAPI.place_order(str(amount), str(sellPrice), "sell",
                           "exchange limit")
Exemplo n.º 13
0
#!/usr/bin/env python
import FinexAPI

print FinexAPI.stats()
Exemplo n.º 14
0
#!/usr/bin/env python
import FinexAPI

print FinexAPI.ticker()
Exemplo n.º 15
0
#!/usr/bin/env python
import FinexAPI

print FinexAPI.orderbook()
Exemplo n.º 16
0
#!/usr/bin/env python
import FinexAPI

print FinexAPI.symbols()
Exemplo n.º 17
0
#!/usr/bin/env python
import FinexAPI

print FinexAPI.lendbook()
Exemplo n.º 18
0
#!/usr/bin/env python
import FinexAPI

print FinexAPI.today()
Exemplo n.º 19
0
#!/usr/bin/env python
import FinexAPI

print FinexAPI.place_order("0.01", "500.0", "sell", "exchange limit")
Exemplo n.º 20
0
#!/usr/bin/env python
import FinexAPI

print FinexAPI.active_positions()