Перейти к содержимому

интернет-биржа

Фотография

Пример API Python 2.7.17

API

  • Пожалуйста, авторизуйтесь для ответа.
ответов в данной теме 1

#1 Пользователь Dmitrid (WMID 519046945291 )

  • Группа: Пользователи
  • сообщений 6
  • Регистрация: 31-Январь 17
  • Webmoney BL

Отправлено 27 Январь 2020 - 20:02

# -*- coding: utf-8 -*-
import httplib
import json
import base64
import hashlib
import time

Login = ''
Wmid = ''
Culture = ''
Password = ''
ID = ''

class Api():

    def __init__(self):
        pass

    def public_api(self, api_name, api_params={}):

        time.sleep(2)
        header = {"Content-type": "application/json; charset=utf-8"}
        connection = httplib.HTTPSConnection("api.indx.ru")
        connection.request("POST", "/api/v2/trade/" + api_name, str(api_params), header)
        response = connection.getresponse()
        # print response.status, response.reason
        a = json.load(response)
        connection.close()
        return a

    def Balance(self):
        string = Login + ";" + Password + ";" + Culture + ";" + Wmid
        new_string = string.encode('utf-8')
        sig = base64.b64encode(hashlib.sha256(string.encode('utf-8')).digest())  # .decode('utf-8')
        params = {"ApiContext": {"Login": Login, "Wmid": Wmid, "Culture": "ru-RU", "Signature": sig}}
        a = Api()
        b = a.public_api('Balance', params)
        return b

    def Tools(self):
        string = Login + ";" + Password + ";" + Culture
        new_string = string.encode('utf-8')
        sig = base64.b64encode(hashlib.sha256(string.encode('utf-8')).digest())  # .decode('utf-8')
        params = {"ApiContext":{"Login":Login,"Wmid":Wmid,"Culture":"ru-RU","Signature":sig}}
        a = Api()
        b = a.public_api('Tools', params)
        return b

    def HistoryTrading(self):

        #DateStart =
        #DateEnd  =
        string = Login + ';' + Password + ';' + Culture + ';' + Wmid + ';' + ID + ';' + DateStart + ';' + DateEnd
        new_string = string.encode('utf-8')
        sig = base64.b64encode(hashlib.sha256(string.encode('utf-8')).digest())  # .decode('utf-8')
        params = {"ApiContext": {"Login": Login, "Wmid": Wmid, "Culture": "ru-RU", "Signature": sig},"Trading":{"ID":0,"DateStart":DateStart,"DateEnd":DateEnd}}
        a = Api()
        b = a.public_api('HistoryTrading', params)
        return b

    def HistoryTransaction(self):

        #DateStart =
        #DateEnd  =
        string =  Login+ ';' + Password+ ';' + Culture + ';' + Wmid + ';' + ID + ';' + DateStart + ';' + DateEnd
        new_string = string.encode('utf-8')
        sig = base64.b64encode(hashlib.sha256(string.encode('utf-8')).digest())  # .decode('utf-8')
        params = {"ApiContext": {"Login": Login, "Wmid": Wmid, "Culture": "ru-RU", "Signature": sig},"Trading":{"ID":0,"DateStart":DateStart,"DateEnd":DateEnd}}
        a = Api()
        b = a.public_api('HistoryTransaction', params)
        return b

    def OfferMy(self):

        string = Login + ";" + Password + ";" + Culture + ";" + Wmid
        sig = base64.b64encode(hashlib.sha256(string.encode('utf-8')).digest())
        params = {"ApiContext": {"Login": Login, "Wmid": Wmid, "Culture": "ru-RU", "Signature": sig}}
        a = Api()
        b = a.public_api('OfferMy', params)
        return b['value']

    def OfferList(self):

        string = Login + ";" + Password + ";" + Culture + ";" + Wmid + ";" + ID
        sig = base64.b64encode(hashlib.sha256(string.encode('utf-8')).digest())
        params = {"ApiContext": {"Login": Login, "Wmid": Wmid, "Culture": "ru-RU", "Signature": sig},
                  "Trading": {"ID": ID}}
        a = Api()
        b = a.public_api('OfferList', params)
        return b

    def OfferAdd(self, Count, IsBid, Price):

        string = Login + ";" + Password + ";" + Culture + ";" + Wmid + ";" + ID
        sig = base64.b64encode(hashlib.sha256(string.encode('utf-8')).digest())  # .decode('utf-8')
        params = {"ApiContext": {"Login": Login, "Wmid": Wmid, "Culture": "ru-RU", "Signature": sig},
                  "Offer": {"ID": ID, "Count": Count, "IsAnonymous": 'true', "IsBid": IsBid, "Price": Price}}
        a = Api()
        b = a.public_api('OfferAdd', params)
        return b

    def OfferDelete(self, OfferID):

        string = Login + ";" + Password + ";" + Culture + ";" + Wmid + ";" + str(OfferID)
        sig = base64.b64encode(hashlib.sha256(string.encode('utf-8')).digest())  # .decode('utf-8')
        params = {"ApiContext": {"Login": Login, "Wmid": Wmid, "Culture": "ru-RU", "Signature": sig},
                  "OfferId": OfferID}
        a = Api()
        b = a.public_api('OfferDelete', params)
        return b

    • 0
  • Наверх

#2 Пользователь Dmitrid (WMID 519046945291 )

  • Группа: Пользователи
  • сообщений 6
  • Регистрация: 31-Январь 17
  • Webmoney BL

Отправлено 27 Январь 2020 - 20:03

Прошу сильно не пинать!!!


    • 0
  • Наверх





Еще теги с одним или более ключевыми словами: API

0 человек читают эту тему

0 пользователей, 0 гостей, 0 анонимных