Git Product home page Git Product logo

coinexfutures-python's Introduction

CoinexFutures-Python

This is Coinex(Futures) cryptocurrency exchange library.
Some methods included and listed blow:

  • getMarketPice: get latest dealed(excution) price in market.
  • getBalance: get balance of future account's wallet.
  • adjust: set leverage and position type(isolated or cross margin).
  • getKlines: get last up to 1000 klines in diferrent time frames.
  • calculateAmount: calculate amount before open position.
  • openMarket: open order( also returns position id ) in market price( always latest excution is matter ).
  • openLimit: open order( must get position id with below method ) in given target price.
  • getPositionId: get position id after opening a limit order.
  • closeAll: close order( needs position id taken in open method or getPositionId method) in market price but as a limit close!
  • closeLimit: close order( needs position id taken in open method or getPositionId method) in given target price.
  • getPositionStatus: get position details such as amount of position, unreal profit etc...
  • cancelPending: cancel pending order(s) of an asset.

Note: if you have an open position, you can use another openMarket/openLimit in same direction( if main position was long, open another long ) for add amount to your position or you can use another openMarket/openLimit in opposite direction( if main position was long, open short ) for sell some amount of your position.

How to use/install:

Download library file, put in same dir with your project and import it in your project like this:
from .CoinexFutures import CoinexFutures
Or clone source code in your project.

How to use:


Simple example of openning order:
from .CoinexFutures import CoinexFutures
import sys
coinex = CoinexFutures( "Your AccessID", "Your SecretKey" )
market = "BTCUSDT"
leverage = 10
minimum_amount = 0.0005
adjust_res = coinex.adjust(market, leverage)
if 'error' in adjust_res:
  if adjust_res['error'] != 0:
    print('[!] Failed to adjust position: {}'.format(adjust_res['message']) )
    sys.exit(0)
balanceUsdt = coinex.getBalance()['USDT']['available']
currentPrice = coinex.getMarketPrice(market)
amount = coinex.calculateAmount(balanceUsdt, currentPrice, minimum_amount, leverage)
feedback = coinex.openMarket(market, amount, 'LONG')
if 'error' in feedback:
  if feedback['error'] != 0: # means failed to open position
    print('[!] Failed to open position: {}'.format(feedback['message']) )
    sys.exit(0)
positionId = feedback['positionId']

Simple example of closing position:
.
.
.
status = coinex.getPositionStatus(market, positionId)
if 'error' in status:
  if status['error'] != 0: # means having trouble for getting position status
    print('[!] Failed to get position status: {}'.format(status['message']) )
    sys.exit(0)
if float(status['profit_pnl']) >= 15.0: # means this position is 15% in profit at least.
  print('[+] Closing position with {}% profits.'.format(status['profit_pnl']))
  res = coinex.closeAll(market, positionId)
  print(res['message'])
  

Also check examples in repo files.

As soon as posible i'll share this library to pypi for install easier using pip.

coinexfutures-python's People

Contributors

pouriamdr avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

alimogh

coinexfutures-python's Issues

status = self.coinex.getPositionStatus(market, position_id)

status = self.coinex.getPositionStatus(market, position_id)

I cant seem to get this to work. I just get a response of..

<Response [200]>

Which if I am reading it correctly that means everything is ok... Looking to get information on my existing position.

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.